From 777e6f3371691ccbb5491ffdfb3e284ac2ceaddd Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 1 Aug 2026 09:45:13 +0800 Subject: [PATCH] fix(station): detect train station peripherals on any side Avoid prompting manual slave setup on main hosts when the train station block is attached somewhere other than the back side, and log the detected side for easier diagnosis. --- station_broadcast.lua | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index 123579d..cba197c 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -2,7 +2,7 @@ -- ============================================================================ -- 1. Configuration & Constants -- ============================================================================ -local APP_VERSION_TEXT = "v1.0.10" +local APP_VERSION_TEXT = "v1.0.11" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -38,6 +38,7 @@ local State = { stationPlatform = "1", stationIdentityMode = "auto", hasStationPeripheral = false, + stationPeripheralSide = nil, hasPrimaryMonitor = false, registered = false, stationList = {}, @@ -57,15 +58,20 @@ local State = { local Peripherals = {} function Peripherals.init() - -- Station Peripheral - local back = peripheral.wrap("back") - if back and peripheral.getType("back") == "train_station" then - Peripherals.station = back - State.hasStationPeripheral = true - else - Peripherals.station = nil - State.hasStationPeripheral = false + -- Station Peripheral: prefer the back side, then fall back to any side. + local station = nil + local stationSide = nil + local preferredSides = { "back", "top", "bottom", "left", "right", "front" } + for _, side in ipairs(preferredSides) do + if peripheral.getType(side) == "train_station" then + station = peripheral.wrap(side) + stationSide = side + break + end end + Peripherals.station = station + State.hasStationPeripheral = station ~= nil + State.stationPeripheralSide = stationSide -- Monitors local monitors = { peripheral.find("monitor") } if #monitors > 0 then @@ -1951,9 +1957,9 @@ Audio.loadStationList() Utils.refreshStationIdentity() Utils.log("INFO", "StationBroadcast version " .. APP_VERSION_TEXT) if Peripherals.station then - Utils.log("INFO", "Train station peripheral detected on back") + Utils.log("INFO", "Train station peripheral detected on " .. tostring(State.stationPeripheralSide or "unknown")) else - Utils.log("WARN", "No train station peripheral on back; using manual slave mode") + Utils.log("WARN", "No train station peripheral detected; using manual slave mode") Utils.log("INFO", "Edit " .. CONFIG.STATION_IDENTITY_FILE .. " to set station_code/station_platform") end if Peripherals.primaryMonitor then