From 578cff6dc29fefb89f5936a70af4d4c69a053834 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 1 Aug 2026 07:59:06 +0800 Subject: [PATCH] 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. --- station_broadcast.lua | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index ad11199..a463e95 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -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()