diff --git a/station_broadcast.lua b/station_broadcast.lua index 016fa9e..cb3c517 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -2101,6 +2101,23 @@ function Display.render() end end + -- Upcoming Trains + if State.upcomingTrains and #State.upcomingTrains > 0 then + local startY = State.currentTrain and 11 or 7 + mon.setCursorPos(1, startY) + mon.setTextColor(COLORS.DEBUG) + mon.write("UPCOMING TRAINS:") + mon.setTextColor(COLORS.INFO) + for i = 1, math.min(3, #State.upcomingTrains) do + local t = State.upcomingTrains[i] + mon.setCursorPos(1, startY + i) + local delayStr = t.delay > 0 and (" [+" .. t.delay .. "m]") or "" + local lineText = string.format("%s->%s ETA:%ds%s", t.trainName, t.dest, t.eta, delayStr) + if #lineText > w then lineText = lineText:sub(1, w) end + mon.write(lineText) + end + end + -- Logs local y = h - 3 for i = 1, 3 do @@ -2242,6 +2259,7 @@ State.pendingApproaching = {} function Main.loop() while true do local now = os.epoch("utc") + local newUpcoming = {} -- Check Block Reader (Advanced Peripherals) first for precise ETA and Delay if Peripherals.blockReader then @@ -2273,12 +2291,21 @@ function Main.loop() local realArrival = st.RealTimeArrival or 0 local etaTicks = realArrival - currentTick local etaSeconds = math.floor(etaTicks / 20) + if etaSeconds < 0 then etaSeconds = 0 end -- Calculate Delay in minutes local delayTicks = realArrival - scheduledArrival local delayMinutes = math.floor(delayTicks / (20 * 60)) if delayMinutes < 0 then delayMinutes = 0 end + table.insert(newUpcoming, { + trainName = trainName, + dest = destination, + platform = platform, + eta = etaSeconds, + delay = delayMinutes + }) + if etaSeconds >= 0 and etaSeconds <= 45 then local announceKey = trainName .. "_" .. destination if not State.announcedApproaching[announceKey] then @@ -2348,6 +2375,14 @@ function Main.loop() end end end + + table.insert(newUpcoming, { + trainName = tName, + dest = dest, + platform = platform or State.stationPlatform or "1", + eta = etaSeconds >= 0 and etaSeconds or 0, + delay = delay + }) -- 触发逻辑:当 ETA 已经明确 <= 45秒(包括30秒、15秒、现在等),且之前没有播报过 if etaSeconds >= 0 and etaSeconds <= 45 then @@ -2374,6 +2409,7 @@ function Main.loop() if not Peripherals.station then State.currentTrain = nil + State.upcomingTrains = newUpcoming Display.render() Display.renderTerminal() os.sleep(0.5) @@ -2436,6 +2472,7 @@ function Main.loop() end end + State.upcomingTrains = newUpcoming Display.render() Display.renderTerminal() os.sleep(0.5)