feat(station): allow slave nodes to run without monitors

Make monitors optional so slave nodes can boot and play audio in terminal-only mode, while still using the monitor UI automatically when one is present.
This commit is contained in:
2026-08-01 07:59:06 +08:00
parent 918e0c68e5
commit 578cff6dc2
+17 -6
View File
@@ -2,7 +2,7 @@
-- ============================================================================ -- ============================================================================
-- 1. Configuration & Constants -- 1. Configuration & Constants
-- ============================================================================ -- ============================================================================
local APP_VERSION_TEXT = "v1.0.8" local APP_VERSION_TEXT = "v1.0.9"
local CONFIG = { local CONFIG = {
CLOUD_URL = "ws://stabadmin.fse-media.group", CLOUD_URL = "ws://stabadmin.fse-media.group",
@@ -38,6 +38,7 @@ local State = {
stationPlatform = "1", stationPlatform = "1",
stationIdentityMode = "auto", stationIdentityMode = "auto",
hasStationPeripheral = false, hasStationPeripheral = false,
hasPrimaryMonitor = false,
registered = false, registered = false,
stationList = {}, stationList = {},
currentTrain = nil, currentTrain = nil,
@@ -67,10 +68,14 @@ function Peripherals.init()
end end
-- Monitors -- Monitors
local monitors = { peripheral.find("monitor") } local monitors = { peripheral.find("monitor") }
if #monitors == 0 then error("At least one monitor is required") end if #monitors > 0 then
-- Assign monitors Peripherals.primaryMonitor = monitors[1]
Peripherals.primaryMonitor = monitors[1] Peripherals.primaryMonitor.setTextScale(0.5)
Peripherals.primaryMonitor.setTextScale(0.5) State.hasPrimaryMonitor = true
else
Peripherals.primaryMonitor = nil
State.hasPrimaryMonitor = false
end
-- Speakers -- Speakers
Peripherals.speakers = { peripheral.find("speaker") } Peripherals.speakers = { peripheral.find("speaker") }
end end
@@ -1691,6 +1696,7 @@ local Display = {}
function Display.render() function Display.render()
local mon = Peripherals.primaryMonitor local mon = Peripherals.primaryMonitor
if not mon then return end
local w, h = mon.getSize() local w, h = mon.getSize()
mon.clear() mon.clear()
mon.setCursorPos(1,1) mon.setCursorPos(1,1)
@@ -1831,7 +1837,7 @@ local Input = {}
function Input.listener() function Input.listener()
Utils.log("DEBUG", "Input listener started") Utils.log("DEBUG", "Input listener started")
local monitorName = peripheral.getName(Peripherals.primaryMonitor) local monitorName = Peripherals.primaryMonitor and peripheral.getName(Peripherals.primaryMonitor) or nil
while true do while true do
local event, param1, param2, param3 = os.pullEvent() local event, param1, param2, param3 = os.pullEvent()
@@ -1952,6 +1958,11 @@ else
Utils.log("WARN", "No train station peripheral on back; using manual slave mode") Utils.log("WARN", "No train station peripheral on back; using manual slave mode")
Utils.log("INFO", "Edit " .. CONFIG.STATION_IDENTITY_FILE .. " to set station_code/station_platform") Utils.log("INFO", "Edit " .. CONFIG.STATION_IDENTITY_FILE .. " to set station_code/station_platform")
end end
if Peripherals.primaryMonitor then
Utils.log("INFO", "Primary monitor detected")
else
Utils.log("WARN", "No monitor detected; running in terminal-only mode")
end
parallel.waitForAny( parallel.waitForAny(
function() function()