diff options
Diffstat (limited to 'fw.lua')
-rw-r--r-- | fw.lua | 123 |
1 files changed, 84 insertions, 39 deletions
@@ -4,18 +4,17 @@ --See http://unlicense.org/ for more information --Lookup tables for human-readable strings and such -lttypes = {"Permissive","Protected","Yellow Arrow Prot/Perm","Circular Green Prot/Perm"} -pedtypes = {"Unsignalized","Signalized"} -signaltypes = {"Streets 1","Roads","Streets 2"} -pedbuttontypes = {"Normal","TrafficNeXt Compatibility"} -shortphases = {"O","G","R","Y","FR","FY","FG","RY"} -- Green/red switched for, uh, reasons -phases = {O = "Off",R = "Red",Y = "Yellow",G = "Green",RY = "RedYellow",FR = "FlashRed",FY = "FlashYellow",FG = "FlashGreen"} -monitortypes = {"Straight","Left Turn","Pedestrian"} -modes = {"Sensor","Timer","Phase Lock"} -panellock = {"Unlocked","Locked"} -logmodes = {"Quiet","Normal","Verbose"} -pedrecallmodes = {"Never","Timer Only","Always"} -ltrecallmodes = {"No","Yes"} +local lttypes = {"Permissive","Protected","Yellow Arrow Prot/Perm","Circular Green Prot/Perm"} +local pedtypes = {"Unsignalized","Signalized"} +local signaltypes = {"Streets 1","Roads","Streets 2"} +local pedbuttontypes = {"Normal","TrafficNeXt Compatibility"} +local shortphases = {"O","G","R","Y","FR","FY","FG","RY"} -- Green/red switched for, uh, reasons +local phases = {O = "Off",R = "Red",Y = "Yellow",G = "Green",RY = "RedYellow",FR = "FlashRed",FY = "FlashYellow",FG = "FlashGreen"} +local modes = {"Sensor","Timer","Phase Lock"} +local panellock = {"Unlocked","Locked"} +local logmodes = {"Quiet","Normal","Verbose"} +local pedrecallmodes = {"Never","Timer Only","Always"} +local ltrecallmodes = {"No","Yes"} --Only accept digilines signals on the necessary channels local event_ok = false @@ -28,7 +27,7 @@ if not event_ok then end --Used for reverse lookups -function pivot(table) +local function pivot(table) local out = {} for k,v in pairs(table) do out[v] = k @@ -37,19 +36,19 @@ function pivot(table) end --Phase setter thing -function setlight(light,phase) +local function setlight(light,phase) mem.currentphase[light] = phase end --Log filter/formatter -function log(desc,verboseonly) +local function log(desc,verboseonly) if mem.logmode ~= 1 and (mem.logmode == 3 or not verboseonly) then print("[LTC-4000E @ "..mem.name.."] "..desc) end end --Fault logger -function logfault(desc,fatal) +local function logfault(desc,fatal) if fatal then mem.phaselocked = true end log(string.format("%s FAULT: ",(fatal and "FATAL" or "Non-fatal"))..desc,false) local date = os.datetable() @@ -58,7 +57,7 @@ function logfault(desc,fatal) end --Checks if the schedule is currently active -function isscheduled() +local function isscheduled() local hour = os.datetable().hour if mem.schedstart < mem.schedend then --Active during the day @@ -127,8 +126,8 @@ if not mem.logmode then mem.logmode = 2 end if not mem.lock then mem.lock = 2 end --Handle special modes -was_phaselocked = mem.phaselocked -was_timed = mem.timed +local was_phaselocked = mem.phaselocked +local was_timed = mem.timed mem.phaselocked = (isscheduled() and mem.schedmode == 3) or (not isscheduled() and mem.normalmode == 3) mem.timed = (isscheduled() and mem.schedmode == 2) or (not isscheduled() and mem.normalmode == 2) if was_phaselocked and not mem.phaselocked then @@ -253,7 +252,13 @@ if event.type == "digiline" and string.sub(event.channel,1,8) == "preempt_" and end --Phase logic for already-running cycles -if mem.busy and mem.cycle and event.type == "interrupt" and (event.iid == "tick" or event.iid == "manualtick") and not mem.phaselocked and (event.iid == "manualtick" or not mem.stoptime) then +if mem.busy + and mem.cycle + and event.type == "interrupt" + and (event.iid == "tick" or event.iid == "manualtick") + and not mem.phaselocked + and (event.iid == "manualtick" or not mem.stoptime) +then log("Continuing existing cycle at phase "..mem.cycle,true) if mem.cycle == "preempt_yellow" then for k,v in pairs(mem.currentphase) do @@ -289,7 +294,9 @@ if mem.busy and mem.cycle and event.type == "interrupt" and (event.iid == "tick" setlight("at","R") setlight("ct","R") --Branch over to B/D leading left turn if necessary - if (mem.det.bt and mem.det.dt and mem.ltbtype ~= 1 and mem.ltdtype ~= 1) or (((mem.det.bt and mem.ltbtype ~= 1) or (mem.det.dt and mem.ltdtype ~= 1)) and ((mem.det.ap and mem.pedatype ~= 1) or (mem.det.cp and mem.pedctype ~= 1))) then + if (mem.det.bt and mem.det.dt and mem.ltbtype ~= 1 and mem.ltdtype ~= 1) + or (((mem.det.bt and mem.ltbtype ~= 1) or (mem.det.dt and mem.ltdtype ~= 1)) and ((mem.det.ap and mem.pedatype ~= 1) + or (mem.det.cp and mem.pedctype ~= 1))) then mem.cycle = "bdlead1" elseif mem.det.bt and mem.ltbtype ~= 1 then mem.cycle = "blead1" @@ -542,7 +549,9 @@ if mem.busy and mem.cycle and event.type == "interrupt" and (event.iid == "tick" if mem.peddtype ~= 1 then setlight("dp","G") end interrupt(mem.sideped,"tick") elseif mem.cycle == "sideped3" then - if not (mem.det.b or mem.det.d or mem.det.at or mem.det.bt or mem.det.ct or mem.det.dt or mem.det.ap or mem.det.cp) and (mem.pedrecallmode == 3 or mem.det.bp or mem.det.dp) then + if not (mem.det.b or mem.det.d or mem.det.at or mem.det.bt or mem.det.ct or mem.det.dt or mem.det.ap or mem.det.cp) + and (mem.pedrecallmode == 3 or mem.det.bp or mem.det.dp) + then mem.det.bp = nil mem.det.dp = nil interrupt(mem.sideped,"tick") @@ -580,7 +589,7 @@ if mem.busy and mem.cycle and event.type == "interrupt" and (event.iid == "tick" end --Phase logic for starting new cycles -detactive = false +local detactive = false for _,_ in pairs(mem.det) do detactive = true end if (not mem.busy) and detactive and (not mem.stoptime) then if mem.phaselocked then @@ -590,17 +599,31 @@ if (not mem.busy) and detactive and (not mem.stoptime) then else log("Starting new cycle",true) mem.stats.cycles = mem.stats.cycles + 1 - if mem.det.at and mem.ltatype ~= 1 and (mem.ltctype == 2 or mem.ltctype == 3) and not (mem.det.b or mem.det.d or mem.det.bt or mem.det.ct or mem.det.dt) then + if mem.det.at + and mem.ltatype ~= 1 + and (mem.ltctype == 2 or mem.ltctype == 3) + and not (mem.det.b or mem.det.d or mem.det.bt or mem.det.ct or mem.det.dt) + then mem.cycle = "yta1" mem.busy = true setlight("c","Y") interrupt(mem.yellowa,"tick") - elseif mem.det.ct and mem.ltctype ~=1 and (mem.ltatype == 2 or mem.ltatype == 3) and not (mem.det.b or mem.det.d or mem.det.at or mem.det.bt or mem.det.dt) then + elseif mem.det.ct + and mem.ltctype ~=1 + and (mem.ltatype == 2 or mem.ltatype == 3) + and not (mem.det.b or mem.det.d or mem.det.at or mem.det.bt or mem.det.dt) + then mem.cycle = "ytc1" mem.busy = true setlight("a","Y") interrupt(mem.yellowa,"tick") - elseif mem.det.b or mem.det.d or mem.det.bt or mem.det.dt or (mem.det.at and mem.ltatype ~= 1) or (mem.det.ct and mem.ltctype ~= 1) then + elseif mem.det.b + or mem.det.d + or mem.det.bt + or mem.det.dt + or (mem.det.at and mem.ltatype ~= 1) + or (mem.det.ct and mem.ltctype ~= 1) + then mem.cycle = "straight1" mem.busy = true setlight("a","Y") @@ -802,9 +825,7 @@ if event.type == "digiline" and event.channel == "touchscreen" then interrupt(nil,"gapout") interrupt(nil,"maxgreen") end - elseif mem.menu == "reboot" then - --No fields/buttons on this screen, so do nothing - else + elseif mem.menu ~= "reboot" then --Reboot screen exists has no controls logfault("Unrecognized menu "..mem.menu,false) mem.menu = "run" end @@ -921,14 +942,38 @@ elseif mem.menu == "mancyc" then table.insert(disp,{command="addlabel",X=0,Y=0,label="Manual Call Entry"}) table.insert(disp,{command="addimage_button",X=1,Y=2,W=2,H=1,name="b",label="Straight B",image="digistuff_ts_bg.png"..(mem.det.b and "^[brighten" or "")}) table.insert(disp,{command="addimage_button",X=1,Y=4,W=2,H=1,name="d",label="Straight D",image="digistuff_ts_bg.png"..(mem.det.d and "^[brighten" or "")}) - if mem.ltatype ~= 1 then table.insert(disp,{command="addimage_button",X=4,Y=1,W=2,H=1,name="at",label="Left Turn A",image="digistuff_ts_bg.png"..(mem.det.at and "^[brighten" or "")}) end - if mem.ltbtype ~= 1 then table.insert(disp,{command="addimage_button",X=4,Y=2,W=2,H=1,name="bt",label="Left Turn B",image="digistuff_ts_bg.png"..(mem.det.bt and "^[brighten" or "")}) end - if mem.ltctype ~= 1 then table.insert(disp,{command="addimage_button",X=4,Y=3,W=2,H=1,name="ct",label="Left Turn C",image="digistuff_ts_bg.png"..(mem.det.ct and "^[brighten" or "")}) end - if mem.ltdtype ~= 1 then table.insert(disp,{command="addimage_button",X=4,Y=4,W=2,H=1,name="dt",label="Left Turn D",image="digistuff_ts_bg.png"..(mem.det.dt and "^[brighten" or "")}) end - if mem.pedatype ~= 1 then table.insert(disp,{command="addimage_button",X=7,Y=1,W=2,H=1,name="ap",label="Pedestrian A",image="digistuff_ts_bg.png"..(mem.det.ap and "^[brighten" or "")}) end - if mem.pedbtype ~= 1 then table.insert(disp,{command="addimage_button",X=7,Y=2,W=2,H=1,name="bp",label="Pedestrian B",image="digistuff_ts_bg.png"..(mem.det.bp and "^[brighten" or "")}) end - if mem.pedctype ~= 1 then table.insert(disp,{command="addimage_button",X=7,Y=3,W=2,H=1,name="cp",label="Pedestrian C",image="digistuff_ts_bg.png"..(mem.det.cp and "^[brighten" or "")}) end - if mem.peddtype ~= 1 then table.insert(disp,{command="addimage_button",X=7,Y=4,W=2,H=1,name="dp",label="Pedestrian D",image="digistuff_ts_bg.png"..(mem.det.dp and "^[brighten" or "")}) end + if mem.ltatype ~= 1 then + local attex = "digistuff_ts_bg.png"..(mem.det.at and "^[brighten" or "") + table.insert(disp,{command="addimage_button",X=4,Y=1,W=2,H=1,name="at",label="Left Turn A",image=attex}) + end + if mem.ltbtype ~= 1 then + local bttex = "digistuff_ts_bg.png"..(mem.det.bt and "^[brighten" or "") + table.insert(disp,{command="addimage_button",X=4,Y=2,W=2,H=1,name="bt",label="Left Turn B",image=bttex}) + end + if mem.ltctype ~= 1 then + local cttex = "digistuff_ts_bg.png"..(mem.det.ct and "^[brighten" or "") + table.insert(disp,{command="addimage_button",X=4,Y=3,W=2,H=1,name="ct",label="Left Turn C",image=cttex}) + end + if mem.ltdtype ~= 1 then + local dttex = "digistuff_ts_bg.png"..(mem.det.dt and "^[brighten" or "") + table.insert(disp,{command="addimage_button",X=4,Y=4,W=2,H=1,name="dt",label="Left Turn D",image=dttex}) + end + if mem.pedatype ~= 1 then + local aptex = "digistuff_ts_bg.png"..(mem.det.ap and "^[brighten" or "") + table.insert(disp,{command="addimage_button",X=7,Y=1,W=2,H=1,name="ap",label="Pedestrian A",image=aptex}) + end + if mem.pedbtype ~= 1 then + local bptex = "digistuff_ts_bg.png"..(mem.det.bp and "^[brighten" or "") + table.insert(disp,{command="addimage_button",X=7,Y=2,W=2,H=1,name="bp",label="Pedestrian B",image=bptex}) + end + if mem.pedctype ~= 1 then + local cptex = "digistuff_ts_bg.png"..(mem.det.cp and "^[brighten" or "") + table.insert(disp,{command="addimage_button",X=7,Y=3,W=2,H=1,name="cp",label="Pedestrian C",image=cptex}) + end + if mem.peddtype ~= 1 then + local dptex = "digistuff_ts_bg.png"..(mem.det.dp and "^[brighten" or "") + table.insert(disp,{command="addimage_button",X=7,Y=4,W=2,H=1,name="dp",label="Pedestrian D",image=dptex}) + end table.insert(disp,{command="addbutton",X=4,Y=6,W=2,H=1,name="cancel",label="Back"}) elseif mem.menu == "log" then table.insert(disp,{command="addlabel",X=0,Y=0,label="Fault Log"}) @@ -1049,7 +1094,7 @@ elseif mem.menu == "monitoring" then table.insert(disp,{command="addimage",X=5.25, Y=1.75, W=1,H=1,texture_name=sideline}) table.insert(disp,{command="addimage",X=6, Y=1.75, W=1,H=1,texture_name=centerline}) table.insert(disp,{command="addimage",X=6.75, Y=1.75, W=1,H=1,texture_name=sideline.."^[transformR180"}) - + --Approach C (right) table.insert(disp,{command="addimage",X=7.5, Y=3.25, W=1,H=1,texture_name=sideline.."^[transformR270"}) table.insert(disp,{command="addimage",X=7.5, Y=4, W=1,H=1,texture_name=centerline.."^[transformR90"}) @@ -1149,7 +1194,7 @@ elseif mem.menu == "stats" then table.insert(disp,{command="addlabel",X=4,Y=3.5,label="DP: "..mem.stats.dp}) table.insert(disp,{command="addlabel",X=0,Y=4.5,label="Total cycles: "..mem.stats.cycles}) local timesinceclear = os.time() - mem.stats.lastreset - local lastclear = "ERROR" + local lastclear if timesinceclear < 120 then --Two minutes lastclear = math.floor(timesinceclear).." seconds" elseif timesinceclear < 7200 then --Two hours |