mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2025-01-03 08:13:49 +01:00
Handle errors in api:info/status. Use Disconnected state when there is no printer driver
This commit is contained in:
parent
0956561064
commit
0667dfe070
@ -112,25 +112,32 @@ function M.access(request, response)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
response:setError(msg)
|
response:setError(msg)
|
||||||
return
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local hasControl = accessManager.hasControl(request.remoteAddress)
|
local hasControl = accessManager.hasControl(request.remoteAddress)
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
response:addData('hasControl', hasControl)
|
response:addData('has_control', hasControl)
|
||||||
|
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.status(request, response)
|
function M.status(request, response)
|
||||||
|
|
||||||
printerAPI.temperature(request, response)
|
local rv
|
||||||
printerAPI.progress(request, response)
|
rv, state = printerAPI.state(request, response)
|
||||||
printerAPI.state(request, response)
|
if(rv == false) then return end
|
||||||
M.access(request, response)
|
|
||||||
|
|
||||||
response:addData('v', 9)
|
if(state ~= "disconnected") then
|
||||||
|
rv = printerAPI.temperature(request, response)
|
||||||
|
if(rv == false) then return end
|
||||||
|
rv = printerAPI.progress(request, response)
|
||||||
|
if(rv == false) then return end
|
||||||
|
rv = M.access(request, response)
|
||||||
|
if(rv == false) then return end
|
||||||
|
end
|
||||||
|
response:addData('v', 10)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,11 +22,10 @@ function M._global(request, response)
|
|||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
end
|
end
|
||||||
|
|
||||||
--requires id(string)
|
|
||||||
function M.temperature(request, response)
|
function M.temperature(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)
|
||||||
if not printer then return end
|
if not printer then return false end
|
||||||
|
|
||||||
local temperatures,msg = printer:getTemperatures()
|
local temperatures,msg = printer:getTemperatures()
|
||||||
|
|
||||||
@ -39,66 +38,57 @@ function M.temperature(request, response)
|
|||||||
response:addData('bed_target', temperatures.bed_target)
|
response:addData('bed_target', temperatures.bed_target)
|
||||||
else
|
else
|
||||||
response:setError(msg)
|
response:setError(msg)
|
||||||
|
return false;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true;
|
||||||
end
|
end
|
||||||
|
|
||||||
--requires id(string)
|
|
||||||
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)
|
||||||
if not printer then return end
|
if not printer then return false end
|
||||||
|
|
||||||
-- NOTE: despite their names, `currentLine` is still the error indicator and `numLines` the message in such case.
|
-- NOTE: despite their names, `currentLine` is still the error indicator and `numLines` the message in such case.
|
||||||
local currentLine,numLines = printer:getProgress()
|
local currentLine,totalLines = printer:getProgress()
|
||||||
|
|
||||||
response:addData('id', argId)
|
response:addData('id', argId)
|
||||||
if currentLine then
|
if currentLine then
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
response:addData('current_line', currentLine)
|
response:addData('current_line', currentLine)
|
||||||
response:addData('num_lines', numLines)
|
response:addData('total_lines', totalLines)
|
||||||
else
|
else
|
||||||
response:setError(numLines)
|
response:setError(totalLines)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true;
|
||||||
end
|
end
|
||||||
|
|
||||||
--TODO: remove busy function (client should use state function)
|
|
||||||
--requires id(string)
|
|
||||||
function M.busy(request, response)
|
|
||||||
local argId = request:get("id")
|
|
||||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
|
||||||
if not printer then return end
|
|
||||||
|
|
||||||
local rv,msg = printer:getState()
|
|
||||||
|
|
||||||
response:addData('id', argId)
|
|
||||||
if rv then
|
|
||||||
response:setSuccess()
|
|
||||||
response:addData('busy', (rv ~= 'idle'))
|
|
||||||
else
|
|
||||||
response:setError(msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--requires id(string)
|
|
||||||
function M.state(request, response)
|
function M.state(request, response)
|
||||||
local argId = request:get("id")
|
local argId = request:get("id")
|
||||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
|
||||||
if not printer then return end
|
|
||||||
|
|
||||||
local rv,msg = printer:getState()
|
|
||||||
|
|
||||||
response:addData('id', argId)
|
response:addData('id', argId)
|
||||||
if rv then
|
|
||||||
|
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||||
|
if not printer then
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
response:addData('state', rv)
|
local printerState = "disconnected"
|
||||||
else
|
response:addData('state', printerState)
|
||||||
response:setError(msg)
|
return true, printerState
|
||||||
|
else
|
||||||
|
local rv,msg = printer:getState()
|
||||||
|
if rv then
|
||||||
|
response:setSuccess()
|
||||||
|
response:addData('state', rv)
|
||||||
|
return true, rv
|
||||||
|
else
|
||||||
|
response:setError(msg)
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return true;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--requires id(string)
|
|
||||||
function M.heatup_POST(request, response)
|
function M.heatup_POST(request, response)
|
||||||
|
|
||||||
if not accessManager.hasControl(request.remoteAddress) then
|
if not accessManager.hasControl(request.remoteAddress) then
|
||||||
@ -108,7 +98,7 @@ function M.heatup_POST(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)
|
||||||
if not printer then return end
|
if not printer then return false end
|
||||||
|
|
||||||
local temperature = settings.get('printer.heatup.temperature')
|
local temperature = settings.get('printer.heatup.temperature')
|
||||||
local rv,msg = printer:heatup(temperature)
|
local rv,msg = printer:heatup(temperature)
|
||||||
@ -119,7 +109,6 @@ function M.heatup_POST(request, response)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--requires id(string)
|
|
||||||
function M.stop_POST(request, response)
|
function M.stop_POST(request, response)
|
||||||
|
|
||||||
if not accessManager.hasControl(request.remoteAddress) then
|
if not accessManager.hasControl(request.remoteAddress) then
|
||||||
@ -140,7 +129,6 @@ function M.stop_POST(request, response)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--requires id(string), gcode(string)
|
|
||||||
--accepts: first(bool) (chunks will be concatenated but output file will be cleared first if this argument is true)
|
--accepts: first(bool) (chunks will be concatenated but output file will be cleared first if this argument is true)
|
||||||
--accepts: last(bool) (chunks will be concatenated and only when this argument is true will printing be started)
|
--accepts: last(bool) (chunks will be concatenated and only when this argument is true will printing be started)
|
||||||
function M.print_POST(request, response)
|
function M.print_POST(request, response)
|
||||||
|
Loading…
Reference in New Issue
Block a user