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:
+17
-11
@@ -2,7 +2,7 @@
|
|||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
-- 1. Configuration & Constants
|
-- 1. Configuration & Constants
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
local APP_VERSION_TEXT = "v1.0.10"
|
local APP_VERSION_TEXT = "v1.0.11"
|
||||||
|
|
||||||
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,
|
||||||
|
stationPeripheralSide = nil,
|
||||||
hasPrimaryMonitor = false,
|
hasPrimaryMonitor = false,
|
||||||
registered = false,
|
registered = false,
|
||||||
stationList = {},
|
stationList = {},
|
||||||
@@ -57,15 +58,20 @@ local State = {
|
|||||||
local Peripherals = {}
|
local Peripherals = {}
|
||||||
|
|
||||||
function Peripherals.init()
|
function Peripherals.init()
|
||||||
-- Station Peripheral
|
-- Station Peripheral: prefer the back side, then fall back to any side.
|
||||||
local back = peripheral.wrap("back")
|
local station = nil
|
||||||
if back and peripheral.getType("back") == "train_station" then
|
local stationSide = nil
|
||||||
Peripherals.station = back
|
local preferredSides = { "back", "top", "bottom", "left", "right", "front" }
|
||||||
State.hasStationPeripheral = true
|
for _, side in ipairs(preferredSides) do
|
||||||
else
|
if peripheral.getType(side) == "train_station" then
|
||||||
Peripherals.station = nil
|
station = peripheral.wrap(side)
|
||||||
State.hasStationPeripheral = false
|
stationSide = side
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Peripherals.station = station
|
||||||
|
State.hasStationPeripheral = station ~= nil
|
||||||
|
State.stationPeripheralSide = stationSide
|
||||||
-- Monitors
|
-- Monitors
|
||||||
local monitors = { peripheral.find("monitor") }
|
local monitors = { peripheral.find("monitor") }
|
||||||
if #monitors > 0 then
|
if #monitors > 0 then
|
||||||
@@ -1951,9 +1957,9 @@ Audio.loadStationList()
|
|||||||
Utils.refreshStationIdentity()
|
Utils.refreshStationIdentity()
|
||||||
Utils.log("INFO", "StationBroadcast version " .. APP_VERSION_TEXT)
|
Utils.log("INFO", "StationBroadcast version " .. APP_VERSION_TEXT)
|
||||||
if Peripherals.station then
|
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
|
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")
|
Utils.log("INFO", "Edit " .. CONFIG.STATION_IDENTITY_FILE .. " to set station_code/station_platform")
|
||||||
end
|
end
|
||||||
if Peripherals.primaryMonitor then
|
if Peripherals.primaryMonitor then
|
||||||
|
|||||||
Reference in New Issue
Block a user