From 8c8d3faf7226f6bac78da6f5d57c085a0adc5223 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Fri, 7 Nov 2025 17:08:05 +0000 Subject: [PATCH] #634 moved most monitor disconnect handling to the backplane --- coordinator/backplane.lua | 35 ++++++++++++++++++++++++++++++++++- coordinator/renderer.lua | 30 ++++++++++-------------------- coordinator/threads.lua | 6 +----- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/coordinator/backplane.lua b/coordinator/backplane.lua index e0deec8..4134b14 100644 --- a/coordinator/backplane.lua +++ b/coordinator/backplane.lua @@ -390,7 +390,40 @@ function backplane.detach(type, device, iface) end elseif type == "monitor" then ---@cast device Monitor - _bp.smem.q.mq_render.push_data(MQ__RENDER_DATA.MON_DISCONNECT, device) + + local is_used = false + + log.info("BKPLN: MONITOR LINK_DOWN " .. iface) + + if _bp.displays.main == device then + is_used = true + + log.info("BKPLN: lost the main display") + iocontrol.fp_monitor_state("main", false) + elseif _bp.displays.flow == device then + is_used = true + + log.info("BKPLN: lost the flow display") + iocontrol.fp_monitor_state("flow", false) + else + for idx, monitor in pairs(_bp.displays.unit_displays) do + if monitor == device then + is_used = true + + log.info("BKPLN: lost the unit " .. idx .. " display") + iocontrol.fp_monitor_state(idx, false) + break + end + end + end + + -- notify renderer if it was using it + if is_used then + log_sys("lost a configured monitor") + _bp.smem.q.mq_render.push_data(MQ__RENDER_DATA.MON_DISCONNECT, iface) + else + log_sys("lost an unused monitor") + end elseif type == "speaker" then ---@cast device Speaker log_sys("lost alarm sounder speaker") diff --git a/coordinator/renderer.lua b/coordinator/renderer.lua index c6bb3f1..f9dd9bd 100644 --- a/coordinator/renderer.lua +++ b/coordinator/renderer.lua @@ -267,53 +267,43 @@ function renderer.fp_ready() return engine.fp_ready end function renderer.ui_ready() return engine.ui_ready end -- handle a monitor peripheral being disconnected ----@param device Monitor monitor ----@return boolean is_used if the monitor is one of the configured monitors -function renderer.handle_disconnect(device) - local is_used = false - +---@param iface string monitor interface +function renderer.handle_disconnect(iface) if not engine.monitors then return false end - if engine.monitors.main == device then + if engine.monitors.main_iface == iface then if engine.ui.main_display ~= nil then -- delete element tree and clear root UI elements engine.ui.main_display.delete() + log_render("closed main view due to monitor disconnect") end - is_used = true engine.monitors.main = nil engine.ui.main_display = nil - - iocontrol.fp_monitor_state("main", false) - elseif engine.monitors.flow == device then + elseif engine.monitors.flow_iface == iface then if engine.ui.flow_display ~= nil then -- delete element tree and clear root UI elements engine.ui.flow_display.delete() + log_render("closed flow view due to monitor disconnect") end - is_used = true engine.monitors.flow = nil engine.ui.flow_display = nil - - iocontrol.fp_monitor_state("flow", false) else - for idx, monitor in pairs(engine.monitors.unit_displays) do - if monitor == device then + for idx, u_iface in pairs(engine.monitors.unit_ifaces) do + if u_iface == iface then if engine.ui.unit_displays[idx] ~= nil then + -- delete element tree and clear root UI elements engine.ui.unit_displays[idx].delete() + log_render("closed unit" .. idx .. "view due to monitor disconnect") end - is_used = true engine.monitors.unit_displays[idx] = nil engine.ui.unit_displays[idx] = nil - - iocontrol.fp_monitor_state(idx, false) break end end end - - return is_used end -- handle a monitor peripheral being reconnected diff --git a/coordinator/threads.lua b/coordinator/threads.lua index f80f28f..6e27b46 100644 --- a/coordinator/threads.lua +++ b/coordinator/threads.lua @@ -264,11 +264,7 @@ function threads.thread__render(smem) end elseif cmd.key == MQ__RENDER_DATA.MON_DISCONNECT then -- monitor disconnected - if renderer.handle_disconnect(cmd.val) then - log_sys("lost a configured monitor") - else - log_sys("lost an unused monitor") - end + renderer.handle_disconnect(cmd.val) elseif cmd.key == MQ__RENDER_DATA.MON_RESIZE then -- monitor resized local is_used, is_ok = renderer.handle_resize(cmd.val)