diff --git a/coordinator/config.lua b/coordinator/config.lua index 7ea6ea2..66edbc7 100644 --- a/coordinator/config.lua +++ b/coordinator/config.lua @@ -26,6 +26,9 @@ config.SOUNDER_VOLUME = 1.0 -- true for 24 hour time on main view screen config.TIME_24_HOUR = true +-- disable flow view (for legacy layouts) +config.DISABLE_FLOW_VIEW = false + -- log path config.LOG_PATH = "/log.txt" -- log mode @@ -33,6 +36,6 @@ config.LOG_PATH = "/log.txt" -- 1 = NEW (replaces existing file on start) config.LOG_MODE = 0 -- true to log verbose debug messages -config.LOG_DEBUG = false +config.LOG_DEBUG = true return config diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index 36636bc..93f39b1 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -49,8 +49,9 @@ end -- configure monitor layout ---@param num_units integer number of units expected +---@param disable_flow_view boolean disable flow view (legacy) ---@return boolean success, monitors_struct? monitors -function coordinator.configure_monitors(num_units) +function coordinator.configure_monitors(num_units, disable_flow_view) ---@class monitors_struct local monitors = { primary = nil, @@ -72,7 +73,7 @@ function coordinator.configure_monitors(num_units) end -- we need a certain number of monitors (1 per unit + 1 primary display + 1 flow display) - local num_displays_needed = num_units + 2 + local num_displays_needed = num_units + util.trinary(disable_flow_view, 1, 2) if #names < num_displays_needed then local message = "not enough monitors connected (need " .. num_displays_needed .. ")" println(message) @@ -125,27 +126,29 @@ function coordinator.configure_monitors(num_units) -- FLOW MONITOR DISPLAY -- -------------------------- - local iface_flow_display = settings.get("FLOW_DISPLAY") ---@type boolean|string|nil + if not disable_flow_view then + local iface_flow_display = settings.get("FLOW_DISPLAY") ---@type boolean|string|nil - if not util.table_contains(names, iface_flow_display) then - println("flow monitor display is not connected") - local response = dialog.ask_y_n("would you like to change it", true) - if response == false then return false end - iface_flow_display = nil + if not util.table_contains(names, iface_flow_display) then + println("flow monitor display is not connected") + local response = dialog.ask_y_n("would you like to change it", true) + if response == false then return false end + iface_flow_display = nil + end + + while iface_flow_display == nil and #available > 0 do + iface_flow_display = ask_monitor(available) + end + + if type(iface_flow_display) ~= "string" then return false end + + settings.set("FLOW_DISPLAY", iface_flow_display) + util.filter_table(available, function (x) return x ~= iface_flow_display end) + + monitors.flow = ppm.get_periph(iface_flow_display) + monitors.flow_name = iface_flow_display end - while iface_flow_display == nil and #available > 0 do - iface_flow_display = ask_monitor(available) - end - - if type(iface_flow_display) ~= "string" then return false end - - settings.set("FLOW_DISPLAY", iface_flow_display) - util.filter_table(available, function (x) return x ~= iface_flow_display end) - - monitors.flow = ppm.get_periph(iface_flow_display) - monitors.flow_name = iface_flow_display - ------------------- -- UNIT DISPLAYS -- ------------------- diff --git a/coordinator/iocontrol.lua b/coordinator/iocontrol.lua index e4ff9b5..577b8e6 100644 --- a/coordinator/iocontrol.lua +++ b/coordinator/iocontrol.lua @@ -338,11 +338,21 @@ function iocontrol.fp_has_speaker(has_speaker) io.fp.ps.publish("has_speaker", h function iocontrol.fp_link_state(state) io.fp.ps.publish("link_state", state) end -- report monitor connection state ----@param id integer unit ID or 0 for main +---@param id string|integer unit ID for unit monitor, "main" for main monitor, or "flow" for flow monitor function iocontrol.fp_monitor_state(id, connected) - local name = "main_monitor" - if id > 0 then name = "unit_monitor_" .. id end - io.fp.ps.publish(name, connected) + local name = nil + + if id == "main" then + name = "main_monitor" + elseif id == "flow" then + name = "flow_monitor" + elseif type(id) == "number" then + name = "unit_monitor_" .. id + end + + if name ~= nil then + io.fp.ps.publish(name, connected) + end end -- report PKT firmware version and PKT session connection state diff --git a/coordinator/renderer.lua b/coordinator/renderer.lua index b4709b6..0ab0174 100644 --- a/coordinator/renderer.lua +++ b/coordinator/renderer.lua @@ -32,7 +32,8 @@ local engine = { main_display = nil, ---@type graphics_element|nil flow_display = nil, ---@type graphics_element|nil unit_displays = {} - } + }, + disable_flow_view = false } -- init a display to the "default", but set text scale to 0.5 @@ -50,13 +51,20 @@ local function _init_display(monitor) end end +-- disable the flow view +---@param disable boolean +function renderer.legacy_disable_flow_view(disable) + engine.disable_flow_view = disable +end + -- link to the monitor peripherals ---@param monitors monitors_struct function renderer.set_displays(monitors) engine.monitors = monitors -- report to front panel as connected - iocontrol.fp_monitor_state(0, true) + iocontrol.fp_monitor_state("main", engine.monitors.primary ~= nil) + iocontrol.fp_monitor_state("flow", engine.monitors.flow ~= nil) for i = 1, #engine.monitors.unit_displays do iocontrol.fp_monitor_state(i, true) end end @@ -64,7 +72,7 @@ end function renderer.init_displays() -- init primary and flow monitors _init_display(engine.monitors.primary) - _init_display(engine.monitors.flow) + if not engine.disable_flow_view then _init_display(engine.monitors.flow) end -- init unit displays for _, monitor in ipairs(engine.monitors.unit_displays) do @@ -91,6 +99,14 @@ function renderer.validate_main_display_width() return w == 164 end +-- check flow display width +---@nodiscard +---@return boolean width_okay +function renderer.validate_flow_display_width() + local w, _ = engine.monitors.flow.getSize() + return w == 164 +end + -- check display sizes ---@nodiscard ---@return boolean valid all unit display dimensions OK diff --git a/coordinator/startup.lua b/coordinator/startup.lua index f22326b..0633eba 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -84,7 +84,7 @@ local function main() iocontrol.init_fp(COORDINATOR_VERSION, comms.version) -- setup monitors - local configured, monitors = coordinator.configure_monitors(config.NUM_UNITS) + local configured, monitors = coordinator.configure_monitors(config.NUM_UNITS, config.DISABLE_FLOW_VIEW == true) if not configured or monitors == nil then println("startup> monitor setup failed") log.fatal("monitor configuration failed") @@ -92,6 +92,7 @@ local function main() end -- init renderer + renderer.legacy_disable_flow_view(config.DISABLE_FLOW_VIEW == true) renderer.set_displays(monitors) renderer.init_displays() @@ -99,6 +100,10 @@ local function main() println("startup> main display must be 8 blocks wide") log.fatal("main display not wide enough") return + elseif (config.DISABLE_FLOW_VIEW ~= true) and not renderer.validate_flow_display_width() then + println("startup> flow display must be 8 blocks wide") + log.fatal("flow display not wide enough") + return elseif not renderer.validate_unit_display_sizes() then println("startup> one or more unit display dimensions incorrect; they must be 4x4 blocks") log.fatal("unit display dimensions incorrect") diff --git a/coordinator/ui/layout/front_panel.lua b/coordinator/ui/layout/front_panel.lua index 207e213..11fe172 100644 --- a/coordinator/ui/layout/front_panel.lua +++ b/coordinator/ui/layout/front_panel.lua @@ -73,6 +73,9 @@ local function init(panel, num_units) local main_monitor = LED{parent=monitors,label="MAIN MONITOR",colors=cpair(colors.green,colors.green_off)} main_monitor.register(ps, "main_monitor", main_monitor.update) + local flow_monitor = LED{parent=monitors,label="FLOW MONITOR",colors=cpair(colors.green,colors.green_off)} + flow_monitor.register(ps, "flow_monitor", flow_monitor.update) + monitors.line_break() for i = 1, num_units do