mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Fixed issue that control access wasn't properly reset after print
This commit is contained in:
parent
6297984d68
commit
09f653e3da
@ -149,26 +149,10 @@ function M.access(request, response)
|
|||||||
--log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|");
|
--log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|");
|
||||||
--log:info(" controller: |"..utils.dump(accessManager.getController()).."|");
|
--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)
|
local hasControl = accessManager.hasControl(request.remoteAddress)
|
||||||
|
-- if hasControl then log:info(" hasControl: true")
|
||||||
|
-- else log:info(" hasControl: false") end
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
|
|
||||||
response:addData('has_control', hasControl)
|
response:addData('has_control', hasControl)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -8,12 +8,34 @@
|
|||||||
|
|
||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
|
local printerUtils = require('util.printer')
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.hasControl(ip)
|
function M.hasControl(ip)
|
||||||
local controllerIP = M.getController()
|
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
|
end
|
||||||
|
|
||||||
function M.getController()
|
function M.getController()
|
||||||
|
@ -78,8 +78,10 @@ function M.createPrinterOrFail(deviceId, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not printer then
|
if not printer then
|
||||||
|
if response ~= nil then
|
||||||
response:setError("could not open printer driver (" .. msg .. ")")
|
response:setError("could not open printer driver (" .. msg .. ")")
|
||||||
response:addData('id', deviceId)
|
response:addData('id', deviceId)
|
||||||
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user