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
-- ============================================================================
local APP_VERSION_TEXT = "v1.0.8"
local APP_VERSION_TEXT = "v1.0.9"
local CONFIG = {
CLOUD_URL = "ws://stabadmin.fse-media.group",
@@ -38,6 +38,7 @@ local State = {
stationPlatform = "1",
stationIdentityMode = "auto",
hasStationPeripheral = false,
hasPrimaryMonitor = false,
registered = false,
stationList = {},
currentTrain = nil,
@@ -67,10 +68,14 @@ function Peripherals.init()
end
-- Monitors
local monitors = { peripheral.find("monitor") }
if #monitors == 0 then error("At least one monitor is required") end
-- Assign monitors
Peripherals.primaryMonitor = monitors[1]
Peripherals.primaryMonitor.setTextScale(0.5)
if #monitors > 0 then
Peripherals.primaryMonitor = monitors[1]
Peripherals.primaryMonitor.setTextScale(0.5)
State.hasPrimaryMonitor = true
else
Peripherals.primaryMonitor = nil
State.hasPrimaryMonitor = false
end
-- Speakers
Peripherals.speakers = { peripheral.find("speaker") }
end
@@ -1691,6 +1696,7 @@ local Display = {}
function Display.render()
local mon = Peripherals.primaryMonitor
if not mon then return end
local w, h = mon.getSize()
mon.clear()
mon.setCursorPos(1,1)
@@ -1831,7 +1837,7 @@ local Input = {}
function Input.listener()
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
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("INFO", "Edit " .. CONFIG.STATION_IDENTITY_FILE .. " to set station_code/station_platform")
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(
function()