Feat: CC client auto-detects and displays available departure beeps from server
This commit is contained in:
+57
-3
@@ -2,7 +2,7 @@
|
|||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
-- 1. Configuration & Constants
|
-- 1. Configuration & Constants
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
local APP_VERSION_TEXT = "v1.0.15"
|
local APP_VERSION_TEXT = "v1.0.16"
|
||||||
|
|
||||||
local CONFIG = {
|
local CONFIG = {
|
||||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||||
@@ -193,8 +193,41 @@ function Utils.hasUsableManualIdentity(data)
|
|||||||
and data.station_platform and data.station_platform ~= ""
|
and data.station_platform and data.station_platform ~= ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Utils.getAvailableDepartureBeeps()
|
||||||
|
local beeps = {"fc1"}
|
||||||
|
local ok, resp = pcall(http.get, CONFIG.API_URL .. "/api/files")
|
||||||
|
if ok and resp then
|
||||||
|
local raw = resp.readAll()
|
||||||
|
resp.close()
|
||||||
|
local found = {}
|
||||||
|
for path in raw:gmatch('"path"%s*:%s*"Audio/beep/([^"]+%.wav)"') do
|
||||||
|
local fc = path:match("^(fc.*)%.wav$")
|
||||||
|
if fc then
|
||||||
|
table.insert(found, fc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #found > 0 then
|
||||||
|
beeps = found
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local unique = {}
|
||||||
|
local result = {}
|
||||||
|
for _, v in ipairs(beeps) do
|
||||||
|
if not unique[v] then
|
||||||
|
unique[v] = true
|
||||||
|
table.insert(result, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.sort(result)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
function Utils.promptSlaveIdentity()
|
function Utils.promptSlaveIdentity()
|
||||||
while true do
|
while true do
|
||||||
|
local availBeeps = Utils.getAvailableDepartureBeeps()
|
||||||
|
local availStr = table.concat(availBeeps, ", ")
|
||||||
|
if #availStr > 40 then availStr = availStr:sub(1, 37) .. "..." end
|
||||||
|
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.clear()
|
term.clear()
|
||||||
@@ -210,7 +243,12 @@ function Utils.promptSlaveIdentity()
|
|||||||
term.write("Station code (e.g. cb-03): ")
|
term.write("Station code (e.g. cb-03): ")
|
||||||
term.setCursorPos(1, 8)
|
term.setCursorPos(1, 8)
|
||||||
term.write("Platform number (e.g. 6): ")
|
term.write("Platform number (e.g. 6): ")
|
||||||
|
|
||||||
term.setCursorPos(1, 10)
|
term.setCursorPos(1, 10)
|
||||||
|
term.setTextColor(colors.gray)
|
||||||
|
term.write("Available beeps: " .. availStr)
|
||||||
|
term.setTextColor(colors.white)
|
||||||
|
term.setCursorPos(1, 11)
|
||||||
term.write("Departure beep (e.g. fc1): ")
|
term.write("Departure beep (e.g. fc1): ")
|
||||||
|
|
||||||
term.setCursorPos(30, 6)
|
term.setCursorPos(30, 6)
|
||||||
@@ -220,7 +258,7 @@ function Utils.promptSlaveIdentity()
|
|||||||
term.setCursorPos(31, 8)
|
term.setCursorPos(31, 8)
|
||||||
local stationPlatform = Utils.trim(read() or "")
|
local stationPlatform = Utils.trim(read() or "")
|
||||||
|
|
||||||
term.setCursorPos(32, 10)
|
term.setCursorPos(32, 11)
|
||||||
local departureBeep = Utils.trim(read() or "")
|
local departureBeep = Utils.trim(read() or "")
|
||||||
if departureBeep == "" then departureBeep = "fc1" end
|
if departureBeep == "" then departureBeep = "fc1" end
|
||||||
|
|
||||||
@@ -265,6 +303,10 @@ function Utils.promptConfig()
|
|||||||
local currentBeep = manual.departure_beep or State.departureBeep or "fc1"
|
local currentBeep = manual.departure_beep or State.departureBeep or "fc1"
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
local availBeeps = Utils.getAvailableDepartureBeeps()
|
||||||
|
local availStr = table.concat(availBeeps, ", ")
|
||||||
|
if #availStr > 40 then availStr = availStr:sub(1, 37) .. "..." end
|
||||||
|
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.clear()
|
term.clear()
|
||||||
@@ -285,7 +327,12 @@ function Utils.promptConfig()
|
|||||||
term.write("Station code [" .. currentCode .. "]: ")
|
term.write("Station code [" .. currentCode .. "]: ")
|
||||||
term.setCursorPos(1, 8)
|
term.setCursorPos(1, 8)
|
||||||
term.write("Platform number [" .. currentPlatform .. "]: ")
|
term.write("Platform number [" .. currentPlatform .. "]: ")
|
||||||
|
|
||||||
term.setCursorPos(1, 10)
|
term.setCursorPos(1, 10)
|
||||||
|
term.setTextColor(colors.gray)
|
||||||
|
term.write("Available beeps: " .. availStr)
|
||||||
|
term.setTextColor(colors.white)
|
||||||
|
term.setCursorPos(1, 11)
|
||||||
term.write("Departure beep [" .. currentBeep .. "]: ")
|
term.write("Departure beep [" .. currentBeep .. "]: ")
|
||||||
|
|
||||||
term.setCursorPos(30, 6)
|
term.setCursorPos(30, 6)
|
||||||
@@ -297,7 +344,7 @@ function Utils.promptConfig()
|
|||||||
local platformInput = Utils.trim(read() or "")
|
local platformInput = Utils.trim(read() or "")
|
||||||
if platformInput == "" then platformInput = currentPlatform end
|
if platformInput == "" then platformInput = currentPlatform end
|
||||||
|
|
||||||
term.setCursorPos(32, 10)
|
term.setCursorPos(32, 11)
|
||||||
local beepInput = Utils.trim(read() or "")
|
local beepInput = Utils.trim(read() or "")
|
||||||
if beepInput == "" then beepInput = currentBeep end
|
if beepInput == "" then beepInput = currentBeep end
|
||||||
|
|
||||||
@@ -2132,6 +2179,13 @@ function Input.listener()
|
|||||||
Display.renderTerminal()
|
Display.renderTerminal()
|
||||||
Display.render()
|
Display.render()
|
||||||
end
|
end
|
||||||
|
elseif event == "mouse_click" then
|
||||||
|
local button, x, y = param1, param2, param3
|
||||||
|
if y == 1 then
|
||||||
|
Utils.promptConfig()
|
||||||
|
Display.renderTerminal()
|
||||||
|
Display.render()
|
||||||
|
end
|
||||||
elseif event == "key" then
|
elseif event == "key" then
|
||||||
if param1 == keys.up then
|
if param1 == keys.up then
|
||||||
State.logScrollOffset = math.min(State.logScrollOffset + 1, math.max(0, #State.logs - maxLogs))
|
State.logScrollOffset = math.min(State.logScrollOffset + 1, math.max(0, #State.logs - maxLogs))
|
||||||
|
|||||||
Reference in New Issue
Block a user