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

Fixed issue that control access wasn't properly reset after print

This commit is contained in:
peteruithoven 2014-03-12 16:36:16 +01:00
parent 6297984d68
commit 09f653e3da
3 changed files with 29 additions and 21 deletions

View File

@ -149,26 +149,10 @@ function M.access(request, response)
--log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|");
--log:info(" controller: |"..utils.dump(accessManager.getController()).."|");
-- when there is a controller we check if the printer is idle,
-- if so, it should be done printing and we can clear the controller
if accessManager.getController() ~= "" then
local argId = request:get("id")
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
local rv,msg = printer:getState()
if rv then
response:setSuccess()
if(state == "idle") then -- TODO: define in constants somewhere
accessManager.setController("") -- clear controller
end
else
response:setError(msg)
return false
end
end
local hasControl = accessManager.hasControl(request.remoteAddress)
-- if hasControl then log:info(" hasControl: true")
-- else log:info(" hasControl: false") end
response:setSuccess()
response:addData('has_control', hasControl)
return true

View File

@ -8,12 +8,34 @@
local log = require('util.logger')
local utils = require('util.utils')
local printerUtils = require('util.printer')
local M = {}
function M.hasControl(ip)
local controllerIP = M.getController()
return (controllerIP == "" or (controllerIP ~= "" and controllerIP == ip))
-- no controller stored? we have control
if controllerIP == "" then return true end;
-- controller stored is same as our (requesting) ip? we have control
if(controllerIP == ip) then return true end;
-- no printer connected? we have control
local printer,msg = printerUtils.createPrinterOrFail()
if not printer or not printer:hasSocket() then
M.setController("") -- clear the controller
return true
end
-- printer is idle (done printing)? we have control
local state = printer:getState()
if state == "idle" then -- TODO: define in constants somewhere
M.setController("") -- clear controller
return true
end
return false
end
function M.getController()

View File

@ -78,8 +78,10 @@ function M.createPrinterOrFail(deviceId, response)
end
if not printer then
response:setError("could not open printer driver (" .. msg .. ")")
response:addData('id', deviceId)
if response ~= nil then
response:setError("could not open printer driver (" .. msg .. ")")
response:addData('id', deviceId)
end
return nil
end