perf(gate): 移除显示器握手等待循环,直接设置参数后继续
- 版本号 v1.5.32 -> v1.5.33 - handshakeMonitor:改为单次设置 scale/颜色/清屏即返回,不再循环重试 - waitForPeripherals:移除 handshakeDone 等待分支与 'Waking monitor...' 提示 - 显示器一旦发现立即调用 handshakeMonitor 完成初始化,不做额外阻塞等待 - MONITOR_HANDSHAKE_RETRIES 置 0 作为占位常量
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user