#634 moved most monitor disconnect handling to the backplane

This commit is contained in:
Mikayla
2025-11-07 17:08:05 +00:00
parent 9ff183b17d
commit 8c8d3faf72
3 changed files with 45 additions and 26 deletions

View File

@@ -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")

View File

@@ -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

View File

@@ -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)