cleanup and refactors

This commit is contained in:
Mikayla Fischler 2024-03-05 21:24:17 -05:00
parent 0892a57d35
commit 4e789ab92d
4 changed files with 38 additions and 40 deletions

View File

@ -95,9 +95,9 @@ function coordinator.load_config()
---@class monitors_struct ---@class monitors_struct
local monitors = { local monitors = {
primary = nil, ---@type table|nil main = nil, ---@type table|nil
primary_name = "", main_name = "",
flow = nil, ---@type table|nil flow = nil, ---@type table|nil
flow_name = "", flow_name = "",
unit_displays = {}, unit_displays = {},
unit_name_map = {} unit_name_map = {}
@ -121,11 +121,11 @@ function coordinator.load_config()
return 2, "Main monitor is not connected." return 2, "Main monitor is not connected."
end end
monitors.primary = ppm.get_periph(config.MainDisplay) monitors.main = ppm.get_periph(config.MainDisplay)
monitors.primary_name = config.MainDisplay monitors.main_name = config.MainDisplay
monitors.primary.setTextScale(0.5) monitors.main.setTextScale(0.5)
w, _ = ppm.monitor_block_size(monitors.primary.getSize()) w, _ = ppm.monitor_block_size(monitors.main.getSize())
if w ~= 8 then if w ~= 8 then
return 2, util.c("Main monitor width is incorrect (was ", w, ", must be 8).") return 2, util.c("Main monitor width is incorrect (was ", w, ", must be 8).")
end end

View File

@ -52,6 +52,16 @@ local function _init_display(monitor)
end end
end end
-- print out that the monitor is too small
---@param monitor table monitor
local function _print_too_small(monitor)
monitor.setCursorPos(1, 1)
monitor.setBackgroundColor(colors.black)
monitor.setTextColor(colors.red)
monitor.clear()
monitor.write("monitor too small")
end
-- disable the flow view -- disable the flow view
---@param disable boolean ---@param disable boolean
function renderer.legacy_disable_flow_view(disable) function renderer.legacy_disable_flow_view(disable)
@ -64,15 +74,15 @@ function renderer.set_displays(monitors)
engine.monitors = monitors engine.monitors = monitors
-- report to front panel as connected -- report to front panel as connected
iocontrol.fp_monitor_state("main", engine.monitors.primary ~= nil) iocontrol.fp_monitor_state("main", engine.monitors.main ~= nil)
iocontrol.fp_monitor_state("flow", engine.monitors.flow ~= 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 for i = 1, #engine.monitors.unit_displays do iocontrol.fp_monitor_state(i, true) end
end end
-- init all displays in use by the renderer -- init all displays in use by the renderer
function renderer.init_displays() function renderer.init_displays()
-- init primary and flow monitors -- init main and flow monitors
_init_display(engine.monitors.primary) _init_display(engine.monitors.main)
if not engine.disable_flow_view then _init_display(engine.monitors.flow) end if not engine.disable_flow_view then _init_display(engine.monitors.flow) end
-- init unit displays -- init unit displays
@ -94,8 +104,8 @@ end
-- initialize the dmesg output window -- initialize the dmesg output window
function renderer.init_dmesg() function renderer.init_dmesg()
local disp_w, disp_h = engine.monitors.primary.getSize() local disp_w, disp_h = engine.monitors.main.getSize()
engine.dmesg_window = window.create(engine.monitors.primary, 1, 1, disp_w, disp_h) engine.dmesg_window = window.create(engine.monitors.main, 1, 1, disp_w, disp_h)
log.direct_dmesg(engine.dmesg_window) log.direct_dmesg(engine.dmesg_window)
end end
@ -166,8 +176,8 @@ function renderer.try_start_ui()
status, msg = pcall(function () status, msg = pcall(function ()
-- show main view on main monitor -- show main view on main monitor
if engine.monitors.primary ~= nil then if engine.monitors.main ~= nil then
engine.ui.main_display = DisplayBox{window=engine.monitors.primary,fg_bg=style.root} engine.ui.main_display = DisplayBox{window=engine.monitors.main,fg_bg=style.root}
main_view(engine.ui.main_display) main_view(engine.ui.main_display)
end end
@ -244,14 +254,14 @@ function renderer.handle_disconnect(device)
if not engine.monitors then return false end if not engine.monitors then return false end
if engine.monitors.primary == device then if engine.monitors.main == device then
if engine.ui.main_display ~= nil then if engine.ui.main_display ~= nil then
-- delete element tree and clear root UI elements -- delete element tree and clear root UI elements
engine.ui.main_display.delete() engine.ui.main_display.delete()
end end
is_used = true is_used = true
engine.monitors.primary = nil engine.monitors.main = nil
engine.ui.main_display = nil engine.ui.main_display = nil
iocontrol.fp_monitor_state("main", false) iocontrol.fp_monitor_state("main", false)
@ -298,9 +308,9 @@ function renderer.handle_reconnect(name, device)
-- note: handle_resize is a more adaptive way of re-initializing a connected monitor -- note: handle_resize is a more adaptive way of re-initializing a connected monitor
-- since it can handle a monitor being reconnected that isn't the right size -- since it can handle a monitor being reconnected that isn't the right size
if engine.monitors.primary_name == name then if engine.monitors.main_name == name then
is_used = true is_used = true
engine.monitors.primary = device engine.monitors.main = device
renderer.handle_resize(name) renderer.handle_resize(name)
elseif engine.monitors.flow_name == name then elseif engine.monitors.flow_name == name then
@ -334,8 +344,8 @@ function renderer.handle_resize(name)
if not engine.monitors then return false, false end if not engine.monitors then return false, false end
if engine.monitors.primary_name == name and engine.monitors.primary then if engine.monitors.main_name == name and engine.monitors.main then
local device = engine.monitors.primary ---@type table local device = engine.monitors.main ---@type table
-- this is necessary if the bottom left block was broken and on reconnect -- this is necessary if the bottom left block was broken and on reconnect
_init_display(device) _init_display(device)
@ -343,9 +353,9 @@ function renderer.handle_resize(name)
is_used = true is_used = true
-- resize dmesg window if needed, but don't make it thinner -- resize dmesg window if needed, but don't make it thinner
local disp_w, disp_h = engine.monitors.primary.getSize() local disp_w, disp_h = engine.monitors.main.getSize()
local dmsg_w, _ = engine.dmesg_window.getSize() local dmsg_w, _ = engine.dmesg_window.getSize()
engine.dmesg_window.reposition(1, 1, math.max(disp_w, dmsg_w), disp_h, engine.monitors.primary) engine.dmesg_window.reposition(1, 1, math.max(disp_w, dmsg_w), disp_h, engine.monitors.main)
if ui.main_display then if ui.main_display then
ui.main_display.delete() ui.main_display.delete()
@ -368,11 +378,7 @@ function renderer.handle_resize(name)
ui.main_display = nil ui.main_display = nil
end end
device.setCursorPos(1, 1) _print_too_small(device)
device.setBackgroundColor(colors.black)
device.setTextColor(colors.red)
device.clear()
device.write("monitor too small")
iocontrol.fp_monitor_state("main", false) iocontrol.fp_monitor_state("main", false)
is_ok = false is_ok = false
@ -407,11 +413,7 @@ function renderer.handle_resize(name)
ui.flow_display = nil ui.flow_display = nil
end end
device.setCursorPos(1, 1) _print_too_small(device)
device.setBackgroundColor(colors.black)
device.setTextColor(colors.red)
device.clear()
device.write("monitor too small")
iocontrol.fp_monitor_state("flow", false) iocontrol.fp_monitor_state("flow", false)
is_ok = false is_ok = false
@ -448,11 +450,7 @@ function renderer.handle_resize(name)
ui.unit_displays[idx] = nil ui.unit_displays[idx] = nil
end end
device.setCursorPos(1, 1) _print_too_small(device)
device.setBackgroundColor(colors.black)
device.setTextColor(colors.red)
device.clear()
device.write("monitor too small")
iocontrol.fp_monitor_state(idx, false) iocontrol.fp_monitor_state(idx, false)
is_ok = false is_ok = false
@ -474,7 +472,7 @@ function renderer.handle_mouse(event)
if engine.fp_ready and event.monitor == "terminal" then if engine.fp_ready and event.monitor == "terminal" then
engine.ui.front_panel.handle_mouse(event) engine.ui.front_panel.handle_mouse(event)
elseif engine.ui_ready then elseif engine.ui_ready then
if event.monitor == engine.monitors.primary_name then if event.monitor == engine.monitors.main_name then
if engine.ui.main_display then engine.ui.main_display.handle_mouse(event) end if engine.ui.main_display then engine.ui.main_display.handle_mouse(event) end
elseif event.monitor == engine.monitors.flow_name then elseif event.monitor == engine.monitors.flow_name then
if engine.ui.flow_display then engine.ui.flow_display.handle_mouse(event) end if engine.ui.flow_display then engine.ui.flow_display.handle_mouse(event) end

View File

@ -22,7 +22,7 @@ local sounder = require("coordinator.sounder")
local apisessions = require("coordinator.session.apisessions") local apisessions = require("coordinator.session.apisessions")
local COORDINATOR_VERSION = "v1.2.10" local COORDINATOR_VERSION = "v1.2.11"
local CHUNK_LOAD_DELAY_S = 30.0 local CHUNK_LOAD_DELAY_S = 30.0

View File

@ -70,7 +70,7 @@ function databus.tx_link_state(state)
end end
-- transmit reactor enable state across the bus -- transmit reactor enable state across the bus
---@param active boolean|nil reactor active ---@param active any reactor active
function databus.tx_reactor_state(active) function databus.tx_reactor_state(active)
databus.ps.publish("reactor_active", active == true) databus.ps.publish("reactor_active", active == true)
end end