diff options
Diffstat (limited to 'controllerfw.lua')
-rw-r--r-- | controllerfw.lua | 150 |
1 files changed, 98 insertions, 52 deletions
diff --git a/controllerfw.lua b/controllerfw.lua index eeb8814..1850a1e 100644 --- a/controllerfw.lua +++ b/controllerfw.lua @@ -48,13 +48,14 @@ local modenames = { stop = "Emergency Stop", mrinspect = "Machine Room Inspection", carinspect = "Car Top Inspection", - inspconflict = "Inspection Conflict", + inspconflict = "Inspection Conflict", --No longer used but some controllers may be in it at update time fs1 = "Fire Service - Phase 1", fs2 = "Fire Service - Phase 2", fs2hold = "Fire Service - Phase 2 Hold", indep = "Independent Service", capture = "Captured", test = "Test Mode", + swing = "Swing Operation", } local doorstates = { @@ -74,6 +75,9 @@ local faultnames = { drivebadorigin = "Drive Origin Invalid", drivedoorinterlock = "Attempted to Move Doors With Car in Motion", driveoutofbounds = "Target Position Out of Bounds", + drivenomachine = "Hoist Machine Missing", + drivemachinemismatch = "Drive<->Machine ID Mismatch", + drivecontrollermismatch = "Controller<->Drive ID Mismatch", } local function drivecmd(command) @@ -93,7 +97,7 @@ local function getpos(pioffset) ret = ret+v if ret > searchpos then return k end end - return mem.params.floorheights[#mem.params.floorheights] + return #mem.params.floorheights end local function gettarget(floor) @@ -195,7 +199,7 @@ local function open() interrupt(10,"opentimeout") interrupt(nil,"closetimeout") if mem.nudging then - if mem.carstate == "normal" then + if (mem.carstate == "normal" or mem.carstate == "swing") then interrupt(0,"nudge") else mem.nudging = false @@ -228,8 +232,27 @@ if mem.params and not mem.recallto then mem.recallto = mem.params.mainlanding or if mem.params and not mem.params.inspectionspeed then mem.params.inspectionspeed = 0.2 end if mem.params and not mem.params.indepunlock then mem.params.indepunlock = {} end if mem.params and not mem.params.secoverrideusers then mem.params.secoverrideusers = {} end +if mem.params and mem.params.swingcallwhennotswing == nil then mem.params.swingcallwhennotswing = true end if not mem.editinguser then mem.editinguser = 1 end +if mem.params and #mem.params.floornames < 2 then + mem.params.floornames = {"1","2","3"} + mem.params.floorheights = {5,5,5} + mem.carstate = "bfdemand" + if mem.doorstate == "closed" then + drivecmd({ + command = "setmaxvel", + maxvel = mem.params.contractspeed, + }) + drivecmd({command = "resetpos"}) + interrupt(0.1,"checkdrive") + mem.carmotion = true + juststarted = true + else + close() + end +end + if event.type == "program" then mem.carstate = "uninit" mem.editingfloor = 1 @@ -275,6 +298,7 @@ if event.type == "program" then inspectionspeed = 0.2, indepunlock = {}, secoverrideusers = {}, + swingcallwhennotswing = true, } end elseif event.type == "ui" then @@ -338,7 +362,7 @@ elseif event.type == "ui" then elseif event.fields.add then table.insert(mem.params.floorheights,5) table.insert(mem.params.floornames,tostring(#mem.params.floornames+1)) - elseif event.fields.remove then + elseif event.fields.remove and #mem.params.floornames > 2 then table.remove(mem.params.floorheights,mem.editingfloor) table.remove(mem.params.floornames,mem.editingfloor) mem.editingfloor = math.max(1,mem.editingfloor-1) @@ -428,16 +452,17 @@ elseif event.type == "ui" then and (mem.carstate == "normal" or mem.carstate == "test" or mem.carstate == "capture" - or mem.carstate == "indep") + or mem.carstate == "indep" + or mem.carstate == "swing") then mem.carcalls[i] = true - elseif event.fields[string.format("upcall%d",i)] and mem.carstate == "normal" and not mem.capturesw then + elseif event.fields[string.format("upcall%d",i)] and (mem.carstate == "normal" or mem.carstate == "swing") and not mem.capturesw then if mem.params.groupmode == "group" then mem.swingupcalls[i] = true else mem.upcalls[i] = true end - elseif event.fields[string.format("downcall%d",i)] and mem.carstate == "normal" and not mem.capturesw then + elseif event.fields[string.format("downcall%d",i)] and (mem.carstate == "normal" or mem.carstate == "swing") and not mem.capturesw then if mem.params.groupmode == "group" then mem.swingdncalls[i] = true else @@ -503,6 +528,9 @@ elseif event.type == "ui" then if event.fields.indepunlock then mem.params.indepunlock[mem.editingfloor] = (event.fields.indepunlock == "true") end + if event.fields.swingcallwhennotswing then + mem.params.swingcallwhennotswing = (event.fields.swingcallwhennotswing == "true") + end if event.fields.save then mem.screenstate = "parameters" elseif event.fields.floor then @@ -556,7 +584,7 @@ elseif event.type == "ui" then end elseif event.iid == "opened" and mem.doorstate == "opening" then mem.doorstate = "open" - if mem.carstate == "normal" then + if (mem.carstate == "normal" or mem.carstate == "swing") then interrupt(mem.params.doortimer,"close") end elseif event.iid == "close" and mem.doorstate == "open" then @@ -578,9 +606,9 @@ elseif event.iid == "closed" and (mem.doorstate == "closing" or mem.doorstate == mem.carmotion = true juststarted = true end -elseif event.type == "callbutton" and mem.carstate == "normal" then +elseif event.type == "callbutton" and (mem.carstate == "normal" or mem.carstate == "swing") then if mem.doorstate == "closed" or mem.direction ~= event.dir or getpos() ~= event.landing then - if mem.params.groupmode == "group" then + if mem.params.groupmode == "group" and not (mem.carstate == "normal" and not mem.params.swingcallwhennotswing) then if event.dir == "up" and event.landing >= 1 and event.landing < #mem.params.floornames then mem.swingupcalls[event.landing] = true elseif event.dir == "down" and event.landing > 1 and event.landing <= #mem.params.floornames then @@ -601,10 +629,15 @@ elseif event.type == "callbutton" and mem.carstate == "normal" then elseif event.iid == "checkopen" then if mem.drive.status.doorstate == "open" then interrupt(0,"opened") - if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "fs1" or mem.carstate == "fs2" or mem.carstate == "fs2hold" then + if mem.carstate == "normal" + or mem.carstate == "indep" + or mem.carstate == "fs1" + or mem.carstate == "fs2" + or mem.carstate == "fs2hold" + or mem.carstate == "swing" then interrupt(nil,"opentimeout") end - if mem.carstate == "normal" and not mem.interrupts.nudge and mem.params.nudgetimer > 0 then + if (mem.carstate == "normal" or mem.carstate == "swing") and not mem.interrupts.nudge and mem.params.nudgetimer > 0 then interrupt(mem.params.nudgetimer,"nudge") end else @@ -625,7 +658,7 @@ elseif event.iid == "closetimeout" then fault("closetimeout",true) elseif event.type == "cop" then local fields = event.fields - if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "fs2" then + if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "fs2" or mem.carstate == "swing" then for k,v in pairs(fields) do if string.sub(k,1,7) == "carcall" then local landing = tonumber(string.sub(k,8,-1)) @@ -649,7 +682,7 @@ elseif event.type == "cop" then end if v and landing and landing >= 1 and landing <= #mem.params.floorheights and secok then if getpos() == landing then - if mem.carstate == "normal" or mem.carstate == "indep" then + if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "swing" then if mem.doorstate == "closing" and not mem.nudging then open() elseif mem.doorstate == "open" then @@ -745,6 +778,12 @@ elseif event.type == "cartopbox" then }) end elseif event.type == "dispatchermsg" then + local swingstateok = false + if mem.carstate == "normal" then + swingstateok = mem.params.swingcallwhennotswing + elseif mem.carstate == "swing" then + swingstateok = true + end if event.channel == "pairrequest" and mem.screenstate == "oobe_dispatcherconnect" then mem.params.floornames = event.msg.floornames mem.params.floorheights = event.msg.floorheights @@ -794,11 +833,11 @@ elseif event.type == "dispatchermsg" then mem.groupupcalls[event.msg] = nil elseif event.channel == "groupdncancel" then mem.groupdncalls[event.msg] = nil - elseif event.channel == "swingupcall" and mem.carstate == "normal" then + elseif event.channel == "swingupcall" and swingstateok then mem.swingupcalls[event.msg] = true - elseif event.channel == "swingdncall" and mem.carstate == "normal" then + elseif event.channel == "swingdncall" and swingstateok then mem.swingdncalls[event.msg] = true - elseif event.channel == "carcall" and mem.carstate == "normal" then + elseif event.channel == "carcall" and (mem.carstate == "normal" or mem.carstate == "swing") then mem.carcalls[event.msg] = true send(event.source,"status",mem) elseif event.channel == "fs1switch" then @@ -810,38 +849,51 @@ elseif event.type == "dispatchermsg" then if not event.msg then mem.flashfirehat = false end end elseif event.type == "remotemsg" then + local swingstateok = false + if mem.carstate == "normal" then + swingstateok = mem.params.swingcallwhennotswing + elseif mem.carstate == "swing" then + swingstateok = true + end if event.channel == "groupupcall" and mem.carstate == "normal" then mem.groupupcalls[event.msg] = true elseif event.channel == "groupdncall" and mem.carstate == "normal" then mem.groupdncalls[event.msg] = true - elseif event.channel == "swingupcall" and mem.carstate == "normal" then + elseif event.channel == "swingupcall" and swingstateok then mem.swingupcalls[event.msg] = true - elseif event.channel == "swingdncall" and mem.carstate == "normal" then + elseif event.channel == "swingdncall" and swingstateok then mem.swingdncalls[event.msg] = true - elseif event.channel == "upcall" and mem.carstate == "normal" then + elseif event.channel == "upcall" and (mem.carstate == "normal" or mem.carstate == "swing") then mem.upcalls[event.msg] = true - elseif event.channel == "dncall" and mem.carstate == "normal" then + elseif event.channel == "dncall" and (mem.carstate == "normal" or mem.carstate == "swing") then mem.dncalls[event.msg] = true elseif event.channel == "groupupcancel" then mem.groupupcalls[event.msg] = nil elseif event.channel == "groupdncancel" then mem.groupdncalls[event.msg] = nil - elseif event.channel == "carcall" and mem.carstate == "normal" then + elseif event.channel == "carcall" and (mem.carstate == "normal" or mem.carstate == "swing") then mem.carcalls[event.msg] = true elseif event.channel == "security" and type(event.msg.floor) == "number" then if mem.params.floornames[event.msg.floor] and event.msg.floor ~= (mem.params.mainlanding or 1) then mem.params.carcallsecurity[event.msg.floor] = event.msg.mode end + elseif event.channel == "swing" then + mem.swing = event.msg + if mem.carstate == "normal" and event.msg then + mem.carstate = "swing" + elseif mem.carstate == "swing" and not event.msg then + mem.carstate = "normal" + end end elseif event.type == "lightcurtain" and not mem.nudging then - if mem.carstate == "normal" or mem.carstate == "indep" then + if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "swing" then if mem.doorstate == "closing" then open() - elseif mem.doorstate == "open" and mem.carstate == "normal" then + elseif mem.doorstate == "open" and (mem.carstate == "normal" or mem.carstate == "swing") then interrupt(mem.params.doortimer,"close") end end -elseif event.iid == "nudge" and mem.carstate == "normal" then +elseif event.iid == "nudge" and (mem.carstate == "normal" or mem.carstate == "swing") then mem.nudging = true if mem.doorstate == "open" then close(true) @@ -901,19 +953,6 @@ elseif mem.controllerstopsw or mem.screenstate == "floortable" or mem.screenstat mem.direction = nil interrupt(nil,"opentimeout") interrupt(nil,"closetimeout") -elseif mem.controllerinspectsw and mem.cartopinspectsw then - mem.carstate = "inspconflict" - mem.carcalls = {} - mem.upcalls = {} - mem.dncalls = {} - mem.swingupcalls = {} - mem.swingdncalls = {} - mem.groupupcalls = {} - mem.groupdncalls = {} - mem.direction = nil - drivecmd({command="estop"}) - interrupt(nil,"opentimeout") - interrupt(nil,"closetimeout") elseif mem.controllerinspectsw and not mem.cartopinspectsw then mem.carstate = "mrinspect" mem.carcalls = {} @@ -927,7 +966,7 @@ elseif mem.controllerinspectsw and not mem.cartopinspectsw then interrupt(nil,"opentimeout") interrupt(nil,"closetimeout") if oldstate ~= "mrinspect" then drivecmd({command="estop"}) end -elseif mem.cartopinspectsw and not mem.controllerinspectsw then +elseif mem.cartopinspectsw then mem.carstate = "carinspect" mem.carcalls = {} mem.upcalls = {} @@ -1022,9 +1061,9 @@ elseif mem.indsw then if oldstate == "stop" or oldstate == "mrinspect" or oldstate == "fault" then mem.carstate = "resync" gotofloor(getpos()) - elseif oldstate == "normal" and (mem.doorstate == "closed" or mem.doorstate == "closing") and not (mem.carmotion or juststarted) then + elseif (oldstate == "normal" or oldstate == "swing") and (mem.doorstate == "closed" or mem.doorstate == "closing") and not (mem.carmotion or juststarted) then open() - elseif oldstate == "normal" and mem.doorstate == "open" then + elseif (oldstate == "normal" or oldstate == "swing") and mem.doorstate == "open" then interrupt(nil,"close") end elseif mem.testsw then @@ -1060,14 +1099,18 @@ else if (oldstate == "fs1" or oldstate == "fs2" or oldstate == "fs2hold") and mem.doorstate == "open" then interrupt(mem.params.doortimer,"close") end - mem.carstate = "normal" + mem.carstate = (mem.swing and "swing" or "normal") elseif oldstate == "indep" then - mem.carstate = "normal" + mem.carstate = (mem.swing and "swing" or "normal") if mem.doorstate == "open" then interrupt(mem.params.doortimer,"close") end end end -if mem.carstate == "normal" and oldstate ~= "normal" and mem.doorstate ~= "closed" and mem.params.nudgetimer > 0 and not mem.interrupts.nudge then +if (mem.carstate == "normal" or mem.carstate == "swing") + and oldstate ~= "normal" and oldstate ~= "swing" + and mem.doorstate ~= "closed" + and mem.params.nudgetimer > 0 + and not mem.interrupts.nudge then interrupt(mem.params.nudgetimer,"nudge") elseif mem.carstate ~= "normal" and oldstate == "normal" then interrupt(nil,"nudge") @@ -1079,7 +1122,7 @@ if mem.carmotion then interrupt(0.1,"checkdrive") else local hallcall = mem.upcalls[getpos()] or mem.dncalls[getpos()] - if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "fs1" or mem.carstate == "fs2" then + if mem.carstate == "normal" or mem.carstate == "indep" or mem.carstate == "fs1" or mem.carstate == "fs2" or mem.carstate == "swing" then mem.carcalls[getpos()] = nil if mem.direction == "up" then mem.upcalls[getpos()] = nil @@ -1141,7 +1184,7 @@ if mem.carmotion then elseif mem.capturesw then mem.carstate = "capture" else - mem.carstate = "normal" + mem.carstate = (mem.swing and "swing" or "normal") end end end @@ -1164,6 +1207,7 @@ local canprocesscalls = { test = true, indep = true, fs2 = true, + swing = true, } if canprocesscalls[mem.carstate] and mem.doorstate == "closed" then @@ -1212,14 +1256,14 @@ if canprocesscalls[mem.carstate] and mem.doorstate == "closed" then gotofloor(gethighestdowncall()) end end - if mem.carstate == "normal" and mem.capturesw and not mem.direction then + if (mem.carstate == "normal" or mem.carstate == "swing") and mem.capturesw and not mem.direction then mem.upcalls = {} mem.dncalls = {} mem.carstate = "capture" elseif mem.carstate == "capture" and mem.direction then - mem.carstate = "normal" + mem.carstate = (mem.swing and "swing" or "normal") end - elseif (mem.carstate == "normal" or mem.carstate == "capture" or mem.carstate == "test") and mem.carmotion then + elseif (mem.carstate == "normal" or mem.carstate == "capture" or mem.carstate == "test" or mem.carstate == "swing") and mem.carmotion then if mem.drive.status.vel > 0 then local nextup = getnextcallabove("up") if nextup then @@ -1471,6 +1515,7 @@ elseif mem.screenstate == "carcallsecurity" then fs(minetest.formspec_escape(string.format("%s - %s",mem.params.floornames[i],secmode))..(i==1 and "" or ",")) end fs(";"..tostring(#mem.params.floornames-mem.editingfloor+1)..";false]") + fs("checkbox[1,9.5;swingcallwhennotswing;Allow Swing Calls When Not In Swing Operation;"..tostring(mem.params.swingcallwhennotswing).."]") if mem.editingfloor ~= (mem.params.mainlanding or 1) then fs("dropdown[8,2;4,1;secmode;Security Disabled,Authorized Users Only,Locked;") if mem.params.carcallsecurity[mem.editingfloor] == "auth" then @@ -1533,7 +1578,7 @@ local hidepi = { } if hidepi[mem.carstate] then mem.pifloor = "--" end -if mem.pifloor ~= oldpifloor and mem.carstate == "normal" then +if mem.pifloor ~= oldpifloor and (mem.carstate == "normal" or mem.carstate == "swing") then drivecmd({command="pibeep"}) end @@ -1544,6 +1589,7 @@ local arrowenabled = { indep = true, capture = true, test = true, + swing = true, } mem.piuparrow = mem.drive.status.vel > 0 and arrowenabled[mem.carstate] mem.pidownarrow = mem.drive.status.vel < 0 and arrowenabled[mem.carstate] @@ -1553,9 +1599,9 @@ mem.flash_is = mem.carstate == "indep" mem.flash_blank = mem.nudging mem.lanterns = {} -if mem.carstate == "normal" and (mem.doorstate == "open" or mem.doorstate == "opening") then +if (mem.carstate == "normal" or mem.carstate == "swing") and (mem.doorstate == "open" or mem.doorstate == "opening") then mem.lanterns[getpos()] = mem.direction -elseif mem.carstate == "normal" and mem.doorstate == "closed" and mem.drive.status then +elseif (mem.carstate == "normal" or mem.carstate == "swing") and mem.doorstate == "closed" and mem.drive.status then local ring = false if mem.drive.status.vel > 0 and mem.drive.status.neareststop > mem.drive.status.dpos then ring = true |