diff --git a/station_broadcast.lua b/station_broadcast.lua index af9a283..eae687e 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -1,6 +1,6 @@ -- 1. Configuration & Constants -local APP_VERSION_TEXT = "v1.0.50" +local APP_VERSION_TEXT = "v1.0.51" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -2704,38 +2704,38 @@ function Main.loop() end if etaSeconds >= 0 and etaSeconds <= 45 then - seenApproachKeys[announceKey] = true - local pending = State.pendingApproaching[announceKey] - if not pending then - State.pendingApproaching[announceKey] = { since = now, lastEta = etaSeconds } - else - if etaSeconds > (tonumber(pending.lastEta) or etaSeconds) + 15 then - pending.since = now + if not seenApproachKeys[announceKey] then + seenApproachKeys[announceKey] = true + local pending = State.pendingApproaching[announceKey] + if not pending then + State.pendingApproaching[announceKey] = { since = now, lastEta = etaSeconds } + else + if etaSeconds > (tonumber(pending.lastEta) or etaSeconds) + 15 then + pending.since = now + end + pending.lastEta = etaSeconds end - pending.lastEta = etaSeconds - end - local stableMs = tonumber(CONFIG.APPROACHING_STABLE_MS) or 15000 - local currentPending = State.pendingApproaching[announceKey] - if currentPending and (now - (currentPending.since or now)) >= stableMs and not State.announcedApproaching[announceKey] then - State.announcedApproaching[announceKey] = now - Utils.log("INFO", string.format("Train Approaching: %s (ETA: %.1fs, Delay: %dm)", trainName, etaSeconds, delayMinutes)) - Network.send({ - type = "train_approaching", - stationName = State.stationName, - stationCode = State.stationCode, - stationPlatform = platform, - trainId = trainName, - destination = destination, - eta = string.format("%.1fs", etaSeconds), - etaSeconds = etaSeconds, - delay = displayDelayMinutes, - cancelled = cancelled, - reason = reason - }) + local stableMs = tonumber(CONFIG.APPROACHING_STABLE_MS) or 15000 + local currentPending = State.pendingApproaching[announceKey] + if currentPending and (now - (currentPending.since or now)) >= stableMs and not State.announcedApproaching[announceKey] then + State.announcedApproaching[announceKey] = now + Utils.log("INFO", string.format("Train Approaching: %s (ETA: %.1fs, Delay: %dm)", trainName, etaSeconds, delayMinutes)) + Network.send({ + type = "train_approaching", + stationName = State.stationName, + stationCode = State.stationCode, + stationPlatform = platform, + trainId = trainName, + destination = destination, + eta = string.format("%.1fs", etaSeconds), + etaSeconds = etaSeconds, + delay = displayDelayMinutes, + cancelled = cancelled, + reason = reason + }) + end end - else - State.pendingApproaching[announceKey] = nil end end end @@ -2838,36 +2838,36 @@ function Main.loop() end if etaSeconds >= 0 and etaSeconds <= 45 then - seenApproachKeys[announceKey] = true - local pending = State.pendingApproaching[announceKey] - if not pending then - State.pendingApproaching[announceKey] = { since = now, lastEta = etaSeconds } - else - if etaSeconds > (tonumber(pending.lastEta) or etaSeconds) + 3 then - pending.since = now + if not seenApproachKeys[announceKey] then + seenApproachKeys[announceKey] = true + local pending = State.pendingApproaching[announceKey] + if not pending then + State.pendingApproaching[announceKey] = { since = now, lastEta = etaSeconds } + else + if etaSeconds > (tonumber(pending.lastEta) or etaSeconds) + 15 then + pending.since = now + end + pending.lastEta = etaSeconds end - pending.lastEta = etaSeconds - end - local stableMs = tonumber(CONFIG.APPROACHING_STABLE_MS) or 15000 - local currentPending = State.pendingApproaching[announceKey] - if currentPending and (now - (currentPending.since or now)) >= stableMs and not State.announcedApproaching[announceKey] then - State.announcedApproaching[announceKey] = now - Utils.log("INFO", string.format("Train Approaching: %s (ETA: %ds, Delay: %dm)", tName, etaSeconds, delay)) - Network.send({ - type = "train_approaching", - stationName = State.stationName, - stationCode = State.stationCode, - stationPlatform = platform or State.stationPlatform or "1", - trainId = tName, - destination = dest, - eta = etaStr, - etaSeconds = etaSeconds, - delay = delay - }) + local stableMs = tonumber(CONFIG.APPROACHING_STABLE_MS) or 15000 + local currentPending = State.pendingApproaching[announceKey] + if currentPending and (now - (currentPending.since or now)) >= stableMs and not State.announcedApproaching[announceKey] then + State.announcedApproaching[announceKey] = now + Utils.log("INFO", string.format("Train Approaching: %s (ETA: %ds, Delay: %dm)", tName, etaSeconds, delay)) + Network.send({ + type = "train_approaching", + stationName = State.stationName, + stationCode = State.stationCode, + stationPlatform = platform or State.stationPlatform or "1", + trainId = tName, + destination = dest, + eta = etaStr, + etaSeconds = etaSeconds, + delay = delay + }) + end end - else - State.pendingApproaching[announceKey] = nil end end end