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