From c52d4dac031fe3dc6b7fa488afa2f0d3abd0c9b3 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 15 Aug 2026 22:55:17 +0800 Subject: [PATCH] =?UTF-8?q?perf(gate):=20=E7=A7=BB=E9=99=A4=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=99=A8=E6=8F=A1=E6=89=8B=E7=AD=89=E5=BE=85=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=EF=BC=8C=E7=9B=B4=E6=8E=A5=E8=AE=BE=E7=BD=AE=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=90=8E=E7=BB=A7=E7=BB=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 版本号 v1.5.32 -> v1.5.33 - handshakeMonitor:改为单次设置 scale/颜色/清屏即返回,不再循环重试 - waitForPeripherals:移除 handshakeDone 等待分支与 'Waking monitor...' 提示 - 显示器一旦发现立即调用 handshakeMonitor 完成初始化,不做额外阻塞等待 - MONITOR_HANDSHAKE_RETRIES 置 0 作为占位常量 --- gate.lua | 63 ++++++++++---------------------------------------------- 1 file changed, 11 insertions(+), 52 deletions(-) diff --git a/gate.lua b/gate.lua index 4b072a2..0a2403f 100644 --- a/gate.lua +++ b/gate.lua @@ -1,11 +1,11 @@ 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.32" +local VERSION = "v1.5.33" local VERSION_CHECK_INTERVAL = 15 local PERIPHERAL_WAIT_INTERVAL = 0.2 local PERIPHERAL_WAIT_MAX_RETRIES = 20 -local MONITOR_HANDSHAKE_RETRIES = 8 +local MONITOR_HANDSHAKE_RETRIES = 0 local STARTUP_REDRAW_DURATION = 3 local STARTUP_REDRAW_INTERVAL = 1 @@ -121,7 +121,6 @@ end local function waitForPeripherals(requireInspection) local attempts = 0 local lastDrawMsg = nil - local handshakeDone = false while attempts < PERIPHERAL_WAIT_MAX_RETRIES do local hadChange = false if not monitor then @@ -129,15 +128,11 @@ local function waitForPeripherals(requireInspection) if m then monitor = m monitorSide = ms + termDev = monitor + pcall(function() handshakeMonitor(monitor) end) hadChange = true end end - if monitor and (hadChange or not handshakeDone) then - termDev = monitor - local ok = false - pcall(function() ok = handshakeMonitor(monitor) end) - if ok then handshakeDone = true end - end if not speaker then local s, _ = safeFindPeripheral("speaker") if s then speaker = s; hadChange = true end @@ -149,17 +144,10 @@ local function waitForPeripherals(requireInspection) local ok = true if not monitor then ok = false end if requireInspection and not inspection then ok = false end - if ok and handshakeDone then return true end - if ok and not handshakeDone then - local ok2 = false - pcall(function() ok2 = handshakeMonitor(monitor) end) - if ok2 then handshakeDone = true; return true end - end + if ok then return true end local msg = nil if not monitor then msg = "Waiting for monitor..." - elseif not handshakeDone then - msg = "Waking monitor..." elseif requireInspection and not inspection then msg = "Waiting for gate peripheral..." end @@ -288,41 +276,12 @@ end local function handshakeMonitor(target) if not target then return false end - local scaleOk = false - local getSizeOk = false - local w, h = nil, nil - 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 - 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 - 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) - if okW and wd then return wd end - end - if peripheral and type(peripheral.find) == "function" then - return peripheral.find("monitor") - end - return nil - end) - if rewrapOk and rewrapped then - target = rewrapped - monitor = rewrapped - termDev = rewrapped - end - end - return scaleOk or getSizeOk + safeCallMonitor(target, "setTextScale", 0.5) + safeCallMonitor(target, "setBackgroundColor", colors.black) + safeCallMonitor(target, "setTextColor", colors.white) + safeCallMonitor(target, "clear") + local w, h = safeCallTerm("getSize") + return (type(w) == "number" and type(h) == "number" and w >= 2 and h >= 2) end local function refreshDisplayTarget()