0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-22 11:03:48 +01:00

Continued adaptation of printer api.

This commit is contained in:
Wouter R 2013-09-20 11:09:25 +02:00
parent d7dc69a7dd
commit 2e43ae9897

View File

@ -36,31 +36,12 @@ local function createPrinterOrFail(deviceId, response)
end end
local function isBusy(printerPath)
local cmdPath = printerPath .. '/' .. COMMAND_FILE
if not utils.exists(cmdPath) then return false end
local f,msg = io.open(cmdPath, 'r')
if not f then return nil,msg end
local size = utils.fileSize(f)
f:close()
return size > 0
end
function M._global(request, response) function M._global(request, response)
-- TODO: list all printers (based on /dev/ttyACM* and /dev/ttyUSB*) -- TODO: list all printers (based on /dev/ttyACM* and /dev/ttyUSB*)
response:setSuccess() response:setSuccess()
end end
-- TODO: reimplement the following fields --requires id(string)
-- if withRaw then response:addData('raw', tempText) end
-- response:addData('last_mod', printer:getLastTemperatureUpdate())
--requires id(int)
--accepts with_raw(bool) to include raw printer response (currently not implemented)
function M.temperature(request, response) function M.temperature(request, response)
local argId = request:get("id") local argId = request:get("id")
local printer,msg = createPrinterOrFail(argId, response) local printer,msg = createPrinterOrFail(argId, response)
@ -80,8 +61,7 @@ function M.temperature(request, response)
end end
end end
-- TODO: reimplement last_mod field --requires id(string)
--requires id(int)
function M.progress(request, response) function M.progress(request, response)
local argId = request:get("id") local argId = request:get("id")
local printer,msg = createPrinterOrFail(argId, response) local printer,msg = createPrinterOrFail(argId, response)
@ -100,23 +80,42 @@ function M.progress(request, response)
end end
end end
--requires id(int) --TODO: remove busy function (client should use state function)
--requires id(string)
function M.busy(request, response) function M.busy(request, response)
response:setError("not implemented") -- TODO: reimplement local argId = request:get("id")
return local printer,msg = createPrinterOrFail(argId, response)
if not printer then return end
-- local b,msg = isBusy(ultipath) local rv,msg = printer:getState()
--
-- if b == nil then response:addData('id', argId)
-- response:setError("could not determine printer state") if rv then
-- response:addData('msg', msg) response:setSuccess()
-- else response:addData('busy', (rv ~= 'idle'))
-- response:setSuccess() else
-- response:addData('busy', b) response:setError(msg)
-- end end
end end
--requires id(int) --requires id(string)
function M.state(request, response)
local argId = request:get("id")
local printer,msg = 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('state', rv)
else
response:setError(msg)
end
end
--requires id(string)
function M.heatup_POST(request, response) function M.heatup_POST(request, response)
local argId = request:get("id") local argId = request:get("id")
local printer,msg = createPrinterOrFail(argId, response) local printer,msg = createPrinterOrFail(argId, response)
@ -131,7 +130,7 @@ function M.heatup_POST(request, response)
end end
end end
--requires id(int) --requires id(string)
function M.stop_POST(request, response) function M.stop_POST(request, response)
local argId = request:get("id") local argId = request:get("id")
local printer,msg = createPrinterOrFail(argId, response) local printer,msg = createPrinterOrFail(argId, response)
@ -146,7 +145,7 @@ function M.stop_POST(request, response)
end end
end end
--requires id(int), gcode(string) --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)