fix(peripheral): 完善tm_gpu外设检测逻辑并升级版本号
新增scanForTmGpu函数用于遍历所有外设查找tm_gpu设备,在原有按类型匹配的查找失败时启用该后备逻辑,同时更新两个脚本文件的版本号。
This commit is contained in:
@@ -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
|
||||
|
||||
+19
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user