diff --git a/gate.lua b/gate.lua index 2a5ed3c..4b072a2 100644 --- a/gate.lua +++ b/gate.lua @@ -1,13 +1,13 @@ local DEFAULT_SERVER_BASE = "https://ticket.fse-media.group" local DEFAULT_SERVER_PATH = "/api/tickets/check" local GATE_OPEN_SECONDS = 2 -local VERSION = "v1.5.31" -local VERSION_CHECK_INTERVAL = 5 -local PERIPHERAL_WAIT_INTERVAL = 0.5 -local PERIPHERAL_WAIT_MAX_RETRIES = 40 -local MONITOR_HANDSHAKE_RETRIES = 20 -local STARTUP_REDRAW_DURATION = 20 -local STARTUP_REDRAW_INTERVAL = 0.5 +local VERSION = "v1.5.32" +local VERSION_CHECK_INTERVAL = 15 +local PERIPHERAL_WAIT_INTERVAL = 0.2 +local PERIPHERAL_WAIT_MAX_RETRIES = 20 +local MONITOR_HANDSHAKE_RETRIES = 8 +local STARTUP_REDRAW_DURATION = 3 +local STARTUP_REDRAW_INTERVAL = 1 local serverURL = nil @@ -291,19 +291,21 @@ local function handshakeMonitor(target) local scaleOk = false local getSizeOk = false local w, h = nil, nil - for _ = 1, MONITOR_HANDSHAKE_RETRIES do + for i = 1, MONITOR_HANDSHAKE_RETRIES do if safeCallMonitor(target, "setTextScale", 0.5) then scaleOk = true end w, h = safeCallTerm("getSize") if type(w) == "number" and type(h) == "number" and w >= 2 and h >= 2 then getSizeOk = true end if scaleOk and getSizeOk then - local cOk = safeCallMonitor(target, "setBackgroundColor", colors.black) - local c2Ok = safeCallMonitor(target, "setTextColor", colors.white) - local clearOk = safeCallMonitor(target, "clear") - if clearOk then return true end + safeCallMonitor(target, "setBackgroundColor", colors.black) + safeCallMonitor(target, "setTextColor", colors.white) + safeCallMonitor(target, "clear") + return true + end + if i < MONITOR_HANDSHAKE_RETRIES then + sleep(PERIPHERAL_WAIT_INTERVAL) end - sleep(PERIPHERAL_WAIT_INTERVAL) local rewrapOk, rewrapped = pcall(function() if monitorSide and peripheral and type(peripheral.isPresent) == "function" and peripheral.isPresent(monitorSide) and type(peripheral.wrap) == "function" then local okW, wd = pcall(peripheral.wrap, monitorSide) @@ -997,14 +999,6 @@ if type(cfg.side_station_codes) == "table" then if next(tmp) ~= nil then sideStationCodeBySide = tmp end end -pcall(function() - refreshStationNameMap(guessBaseFromStatusURL(serverURL)) -end) - -pcall(function() - refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) -end) - pcall(function() if modeBySide == nil then waitForPeripherals(true) @@ -1758,7 +1752,7 @@ local function shouldProcessScan(scan, side, eventName) local now = os.epoch("utc") local prev = recentScans[key] recentScans[key] = now - if prev and (now - prev) < 500 then + if prev and (now - prev) < 200 then return false end return true @@ -1811,7 +1805,7 @@ local function mainLoop() local ev = pack(os.pullEvent()) if ev[1] == "ticket_scanned" or ev[1] == "ic_card_scanned" then processInspectionEvent(ev[1], ev) - os.sleep(0.35) + os.sleep(0.1) drawReadyScreen() elseif ev[1] == "peripheral" or ev[1] == "peripheral_detach" or ev[1] == "monitor_resize" or ev[1] == "config_updated" then pcall(drawReadyScreen) @@ -1822,17 +1816,14 @@ local function mainLoop() end local function startupRedrawTask() - local startTs = (os.epoch and os.epoch("utc")) or (os.time() * 3600000) - local endTs = startTs + STARTUP_REDRAW_DURATION * 1000 - local nextRedraw = startTs + local count = 0 + while count < 3 do + sleep(0.5) + pcall(drawReadyScreen) + count = count + 1 + end while true do - local now = (os.epoch and os.epoch("utc")) or (os.time() * 3600000) - if now <= endTs then - pcall(drawReadyScreen) - sleep(STARTUP_REDRAW_INTERVAL) - else - sleep(60) - end + sleep(600) end end @@ -1896,6 +1887,7 @@ end local function backgroundSyncTask() pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end) + pcall(function() refreshStationNameMap(guessBaseFromStatusURL(serverURL)) end) while true do sleep(VERSION_CHECK_INTERVAL) pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end)