From 9c7e99633b26b501bdc24c687eb7a399914d0f4d Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Fri, 31 Jul 2026 11:18:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(peripheral):=20=E5=AE=8C=E5=96=84tm=5Fgpu?= =?UTF-8?q?=E5=A4=96=E8=AE=BE=E6=A3=80=E6=B5=8B=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增scanForTmGpu函数用于遍历所有外设查找tm_gpu设备,在原有按类型匹配的查找失败时启用该后备逻辑,同时更新两个脚本文件的版本号。 --- gate.lua | 23 ++++++++++++++++++++++- ticketmachine.lua | 20 +++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/gate.lua b/gate.lua index 1b79ddf..cd01422 100644 --- a/gate.lua +++ b/gate.lua @@ -1,7 +1,7 @@ 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.28" +local VERSION = "v1.5.29" local VERSION_CHECK_INTERVAL = 5 local serverURL = nil @@ -206,6 +206,20 @@ local function isTmGpu(dev) and type(dev.sync) == "function" end +local function scanForTmGpu() + if not peripheral or type(peripheral.getNames) ~= "function" or type(peripheral.wrap) ~= "function" then + return nil, nil + end + local names = peripheral.getNames() or {} + for _, name in ipairs(names) do + local okWrap, dev = pcall(peripheral.wrap, name) + if okWrap and isTmGpu(dev) then + return dev, name + end + end + return nil, nil +end + local function buildTmGpuTerm(dev) local gpuTerm = { kind = "tm_gpu", @@ -364,6 +378,13 @@ local function refreshDisplayTarget() nextGpuSide = nil end end + if not nextGpu then + local dev, name = scanForTmGpu() + if dev then + nextGpu = dev + nextGpuSide = name + end + end if nextMonitorSide and type(peripheral.isPresent) == "function" and peripheral.isPresent(nextMonitorSide) and type(peripheral.wrap) == "function" then local okWrap, wrapped = pcall(peripheral.wrap, nextMonitorSide) if okWrap and wrapped then diff --git a/ticketmachine.lua b/ticketmachine.lua index b30615f..fb758fa 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -1,6 +1,6 @@ local CURRENT_STATION_CODE = 'Ticket-Machine' local API_BASE = 'https://ticket.fse-media.group/api' -local VERSION = 'v1.5.26' +local VERSION = 'v1.5.27' local UPDATE_CHECK_INTERVAL = 5 local pack = table.pack or function(...) @@ -566,6 +566,21 @@ local function findPeripheralByType(typeName) return nil, nil end +local function scanForTmGpu() + if not peripheral or type(peripheral.getNames) ~= 'function' or type(peripheral.wrap) ~= 'function' then + return nil, nil + end + local names = peripheral.getNames() or {} + table.sort(names, comparePeripheralName) + for _, name in ipairs(names) do + local okWrap, dev = pcall(peripheral.wrap, name) + if okWrap and isTmGpu(dev) then + return dev, name + end + end + return nil, nil +end + local termDev = nativeTerm or term local w, h = termDev.getSize() @@ -578,6 +593,9 @@ local function refreshDevices() }, '|') monitor, monitorName = findPeripheralByType('monitor') tmGpu, tmGpuName = findPeripheralByType('tm_gpu') + if not isTmGpu(tmGpu) then + tmGpu, tmGpuName = scanForTmGpu() + end ticketVendingMachine, ticketVendingMachineName = findPeripheralByType('ticket_vending_machine') speaker, speakerName = findPeripheralByType('speaker') if tmGpu and isTmGpu(tmGpu) then