#344 coordinator renderer assert handling

This commit is contained in:
Mikayla Fischler 2023-09-30 12:19:04 -04:00
parent 625feb3fd1
commit 560d48084a
4 changed files with 40 additions and 29 deletions

View File

@ -15,10 +15,12 @@ local panel_view = require("coordinator.ui.layout.front_panel")
local main_view = require("coordinator.ui.layout.main_view")
local unit_view = require("coordinator.ui.layout.unit_view")
local core = require("graphics.core")
local flasher = require("graphics.flasher")
local DisplayBox = require("graphics.elements.displaybox")
---@class coord_renderer
local renderer = {}
-- render engine
@ -177,35 +179,46 @@ function renderer.close_fp()
end
-- start the coordinator GUI
function renderer.start_ui()
---@return boolean success, any error_msg
function renderer.try_start_ui()
local status, msg = true, nil
if not engine.ui_ready then
-- hide dmesg
engine.dmesg_window.setVisible(false)
-- show main view on main monitor
if engine.monitors.primary ~= nil then
engine.ui.main_display = DisplayBox{window=engine.monitors.primary,fg_bg=style.root}
main_view(engine.ui.main_display)
status, msg = pcall(function ()
-- show main view on main monitor
if engine.monitors.primary ~= nil then
engine.ui.main_display = DisplayBox{window=engine.monitors.primary,fg_bg=style.root}
main_view(engine.ui.main_display)
end
-- show flow view on flow monitor
if engine.monitors.flow ~= nil then
engine.ui.flow_display = DisplayBox{window=engine.monitors.flow,fg_bg=style.root}
flow_view(engine.ui.flow_display)
end
-- show unit views on unit displays
for idx, display in pairs(engine.monitors.unit_displays) do
engine.ui.unit_displays[idx] = DisplayBox{window=display,fg_bg=style.root}
unit_view(engine.ui.unit_displays[idx], idx)
end
end)
if status then
-- start flasher callback task and report ready
flasher.run()
engine.ui_ready = true
else
-- report fail and close ui
msg = core.extract_assert_msg(msg)
renderer.close_ui()
end
-- show flow view on flow monitor
if engine.monitors.flow ~= nil then
engine.ui.flow_display = DisplayBox{window=engine.monitors.flow,fg_bg=style.root}
flow_view(engine.ui.flow_display)
end
-- show unit views on unit displays
for idx, display in pairs(engine.monitors.unit_displays) do
engine.ui.unit_displays[idx] = DisplayBox{window=display,fg_bg=style.root}
unit_view(engine.ui.unit_displays[idx], idx)
end
-- start flasher callback task
flasher.run()
-- report ui as ready
engine.ui_ready = true
end
return status, msg
end
-- close out the UI

View File

@ -22,7 +22,7 @@ local sounder = require("coordinator.sounder")
local apisessions = require("coordinator.session.apisessions")
local COORDINATOR_VERSION = "v1.0.14"
local COORDINATOR_VERSION = "v1.0.15"
local println = util.println
local println_ts = util.println_ts
@ -198,9 +198,8 @@ local function main()
local draw_start = util.time_ms()
local ui_ok, ui_message = pcall(renderer.start_ui)
local ui_ok, ui_message = renderer.try_start_ui()
if not ui_ok then
renderer.close_ui()
log_graphics(util.c("main UI error: ", ui_message))
log.fatal(util.c("main GUI render failed with error ", ui_message))
else

View File

@ -115,7 +115,7 @@ end
-- extract the custom element assert message, dropping the path to the element file
function core.extract_assert_msg(msg)
local start = string.find(msg, "@") or 1
local start = (string.find(msg, "@") + 1) or 1
return string.sub(msg, start)
end

View File

@ -10,7 +10,7 @@ local element = require("graphics.element")
---@field format string data format (lua string format)
---@field commas? boolean whether to use commas if a number is given (default to false)
---@field lu_colors? cpair label foreground color (a), unit foreground color (b)
---@field value number default value
---@field value? radiation_reading default value
---@field parent graphics_element
---@field id? string element id
---@field x? integer 1 if omitted
@ -24,7 +24,6 @@ local element = require("graphics.element")
---@param args rad_indicator_args
---@return graphics_element element, element_id id
local function rad(args)
element.assert(type(args.value) ~= "number", "value is a required number field")
element.assert(type(args.label) == "string", "label is a required field")
element.assert(type(args.format) == "string", "format is a required field")
element.assert(util.is_int(args.width), "width is a required field")