0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-22 02:53:49 +01:00

add currentPrint get/setter. Fix issue #78

This commit is contained in:
Simon Voordouw 2017-07-06 13:55:35 +02:00
parent 8adc74876e
commit 2883a066ef

View File

@ -48,6 +48,30 @@ function M.temperature(request, response)
end end
end end
local function setCurrentPrint(id)
local cpfileName = "/tmp/current-print";
if id == nil then
io.popen('rm ' .. cpfileName)
return true
end
local cpfile = io.open(cpfileName, 'w+')
if cpfile == nil then
return false
end
cpfile:write(id)
cpfile:close()
return true
end
local function getCurrentPrint()
local idfile = io.open('/tmp/current-print')
if idfile ~= nil then
return idfile:read('*a')
end
end
function M.progress(request, response) function M.progress(request, response)
local argId = request:get("id") local argId = request:get("id")
local printer,msg = printerUtils.createPrinterOrFail(argId, response) local printer,msg = printerUtils.createPrinterOrFail(argId, response)
@ -56,11 +80,7 @@ function M.progress(request, response)
-- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case. -- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case.
local currentLine,bufferedLines,totalLines,bufferSize,maxBufferSize,seqNumber,seqTotal = printer:getProgress() local currentLine,bufferedLines,totalLines,bufferSize,maxBufferSize,seqNumber,seqTotal = printer:getProgress()
local idfile = io.open('/tmp/current-print') local printId = getCurrentPrint()
local printId
if idfile ~= nil then
printId = idfile:read('*a')
end
response:addData('id', argId) response:addData('id', argId)
@ -167,7 +187,8 @@ function M.stop_POST(request, response)
if not printer or not printer:hasSocket() then return end if not printer or not printer:hasSocket() then return end
io.popen("killall print-fetch") io.popen("killall print-fetch")
io.popen("rm /tmp/current-print /tmp/startcode /tmp/endcode") io.popen("rm /tmp/startcode /tmp/endcode")
setCurrentPrint(nil)
if(argGcode == nil) then if(argGcode == nil) then
argGcode = "" argGcode = ""
@ -275,13 +296,7 @@ function M.fetch_POST(request, response)
response:setError("no id supplied") response:setError("no id supplied")
return return
end end
local cpfile = io.open("/tmp/current-print", 'w+') setCurrentPrint(id)
if cpfile == nil then
response:setError("could not save id")
return
end
cpfile:write(id)
cpfile:close()
io.popen("print-fetch " .. socket .. " " .. gcodeServer .. " " .. id .. gcodeFiles) io.popen("print-fetch " .. socket .. " " .. gcodeServer .. " " .. id .. gcodeFiles)