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.
This commit is contained in:
2026-08-01 09:45:13 +08:00
parent f7de7717dc
commit 777e6f3371
+17 -11
View File
@@ -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