From d38a2dea7cd9a5cf7816296fd5f49e4df5e24c50 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 30 Sep 2023 13:31:41 -0400 Subject: [PATCH] #344 renderer integration with new assertion handling --- coordinator/renderer.lua | 31 +++++++++++++++++++++---------- coordinator/startup.lua | 5 ++--- pocket/renderer.lua | 27 +++++++++++++++++++++------ pocket/startup.lua | 5 ++--- reactor-plc/renderer.lua | 27 +++++++++++++++++++++------ reactor-plc/startup.lua | 5 ++--- rtu/renderer.lua | 29 ++++++++++++++++++++++------- rtu/startup.lua | 5 ++--- supervisor/renderer.lua | 27 +++++++++++++++++++++------ supervisor/startup.lua | 5 ++--- 10 files changed, 116 insertions(+), 50 deletions(-) diff --git a/coordinator/renderer.lua b/coordinator/renderer.lua index c41f46c..5aadbb2 100644 --- a/coordinator/renderer.lua +++ b/coordinator/renderer.lua @@ -133,19 +133,30 @@ function renderer.init_dmesg() log.direct_dmesg(engine.dmesg_window) end --- start the coordinator front panel -function renderer.start_fp() +-- try to start the front panel +---@return boolean success, any error_msg +function renderer.try_start_fp() + local status, msg = true, nil + if not engine.fp_ready then -- show front panel view on terminal - engine.ui.front_panel = DisplayBox{window=term.native(),fg_bg=style.fp.root} - panel_view(engine.ui.front_panel, #engine.monitors.unit_displays) + status, msg = pcall(function () + engine.ui.front_panel = DisplayBox{window=term.native(),fg_bg=style.fp.root} + panel_view(engine.ui.front_panel, #engine.monitors.unit_displays) + end) - -- start flasher callback task - flasher.run() - - -- report front panel as ready - engine.fp_ready = true + if status then + -- start flasher callback task and report ready + flasher.run() + engine.fp_ready = true + else + -- report fail and close front panel + msg = core.extract_assert_msg(msg) + renderer.close_fp() + end end + + return status, msg end -- close out the front panel @@ -178,7 +189,7 @@ function renderer.close_fp() end end --- start the coordinator GUI +-- try to start the main GUI ---@return boolean success, any error_msg function renderer.try_start_ui() local status, msg = true, nil diff --git a/coordinator/startup.lua b/coordinator/startup.lua index cf902fc..0ce23ba 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -22,7 +22,7 @@ local sounder = require("coordinator.sounder") local apisessions = require("coordinator.session.apisessions") -local COORDINATOR_VERSION = "v1.0.15" +local COORDINATOR_VERSION = "v1.0.16" local println = util.println local println_ts = util.println_ts @@ -182,9 +182,8 @@ local function main() log_graphics("starting front panel UI...") - local fp_ok, fp_message = pcall(renderer.start_fp) + local fp_ok, fp_message = renderer.try_start_fp() if not fp_ok then - renderer.close_fp() log_graphics(util.c("front panel UI error: ", fp_message)) println_ts("front panel UI creation failed") log.fatal(util.c("front panel GUI render failed with error ", fp_message)) diff --git a/pocket/renderer.lua b/pocket/renderer.lua index fa25bcd..892fc92 100644 --- a/pocket/renderer.lua +++ b/pocket/renderer.lua @@ -5,18 +5,23 @@ local main_view = require("pocket.ui.main") local style = require("pocket.ui.style") +local core = require("graphics.core") local flasher = require("graphics.flasher") local DisplayBox = require("graphics.elements.displaybox") +---@class pocket_renderer local renderer = {} local ui = { display = nil } --- start the pocket GUI -function renderer.start_ui() +-- try to start the pocket GUI +---@return boolean success, any error_msg +function renderer.try_start_ui() + local status, msg = true, nil + if ui.display == nil then -- reset screen term.setTextColor(colors.white) @@ -30,12 +35,22 @@ function renderer.start_ui() end -- init front panel view - ui.display = DisplayBox{window=term.current(),fg_bg=style.root} - main_view(ui.display) + status, msg = pcall(function () + ui.display = DisplayBox{window=term.current(),fg_bg=style.root} + main_view(ui.display) + end) - -- start flasher callback task - flasher.run() + if status then + -- start flasher callback task + flasher.run() + else + -- report fail and close ui + msg = core.extract_assert_msg(msg) + renderer.close_ui() + end end + + return status, msg end -- close out the UI diff --git a/pocket/startup.lua b/pocket/startup.lua index 0592d6c..68fb2c1 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -18,7 +18,7 @@ local iocontrol = require("pocket.iocontrol") local pocket = require("pocket.pocket") local renderer = require("pocket.renderer") -local POCKET_VERSION = "v0.6.2-alpha" +local POCKET_VERSION = "v0.6.3-alpha" local println = util.println local println_ts = util.println_ts @@ -111,9 +111,8 @@ local function main() -- start the UI ---------------------------------------- - local ui_ok, message = pcall(renderer.start_ui) + local ui_ok, message = renderer.try_start_ui() if not ui_ok then - renderer.close_ui() println(util.c("UI error: ", message)) log.error(util.c("startup> GUI render failed with error ", message)) else diff --git a/reactor-plc/renderer.lua b/reactor-plc/renderer.lua index 038918b..2613600 100644 --- a/reactor-plc/renderer.lua +++ b/reactor-plc/renderer.lua @@ -5,18 +5,23 @@ local panel_view = require("reactor-plc.panel.front_panel") local style = require("reactor-plc.panel.style") +local core = require("graphics.core") local flasher = require("graphics.flasher") local DisplayBox = require("graphics.elements.displaybox") +---@class reactor_plc_renderer local renderer = {} local ui = { display = nil } --- start the UI -function renderer.start_ui() +-- try to start the UI +---@return boolean success, any error_msg +function renderer.try_start_ui() + local status, msg = true, nil + if ui.display == nil then -- reset terminal term.setTextColor(colors.white) @@ -30,12 +35,22 @@ function renderer.start_ui() end -- init front panel view - ui.display = DisplayBox{window=term.current(),fg_bg=style.root} - panel_view(ui.display) + status, msg = pcall(function () + ui.display = DisplayBox{window=term.current(),fg_bg=style.root} + panel_view(ui.display) + end) - -- start flasher callback task - flasher.run() + if status then + -- start flasher callback task + flasher.run() + else + -- report fail and close ui + msg = core.extract_assert_msg(msg) + renderer.close_ui() + end end + + return status, msg end -- close out the UI diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index e008280..97ac227 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -19,7 +19,7 @@ local plc = require("reactor-plc.plc") local renderer = require("reactor-plc.renderer") local threads = require("reactor-plc.threads") -local R_PLC_VERSION = "v1.5.9" +local R_PLC_VERSION = "v1.5.10" local println = util.println local println_ts = util.println_ts @@ -184,10 +184,9 @@ local function main() -- front panel time! if not renderer.ui_ready() then local message - plc_state.fp_ok, message = pcall(renderer.start_ui) + plc_state.fp_ok, message = renderer.try_start_ui() if not plc_state.fp_ok then - renderer.close_ui() println_ts(util.c("UI error: ", message)) println("init> running without front panel") log.error(util.c("front panel GUI render failed with error ", message)) diff --git a/rtu/renderer.lua b/rtu/renderer.lua index 17949ce..a212c39 100644 --- a/rtu/renderer.lua +++ b/rtu/renderer.lua @@ -5,19 +5,24 @@ local panel_view = require("rtu.panel.front_panel") local style = require("rtu.panel.style") +local core = require("graphics.core") local flasher = require("graphics.flasher") local DisplayBox = require("graphics.elements.displaybox") +---@class rtu_renderer local renderer = {} local ui = { display = nil } --- start the UI +-- try to start the UI ---@param units table RTU units -function renderer.start_ui(units) +---@return boolean success, any error_msg +function renderer.try_start_ui(units) + local status, msg = true, nil + if ui.display == nil then -- reset terminal term.setTextColor(colors.white) @@ -30,13 +35,23 @@ function renderer.start_ui(units) term.setPaletteColor(style.colors[i].c, style.colors[i].hex) end - -- start flasher callback task - flasher.run() - -- init front panel view - ui.display = DisplayBox{window=term.current(),fg_bg=style.root} - panel_view(ui.display, units) + status, msg = pcall(function () + ui.display = DisplayBox{window=term.current(),fg_bg=style.root} + panel_view(ui.display, units) + end) + + if status then + -- start flasher callback task + flasher.run() + else + -- report fail and close ui + msg = core.extract_assert_msg(msg) + renderer.close_ui() + end end + + return status, msg end -- close out the UI diff --git a/rtu/startup.lua b/rtu/startup.lua index 1ed19e3..f40df57 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -31,7 +31,7 @@ local sna_rtu = require("rtu.dev.sna_rtu") local sps_rtu = require("rtu.dev.sps_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local RTU_VERSION = "v1.6.5" +local RTU_VERSION = "v1.6.6" local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE @@ -480,10 +480,9 @@ local function main() if configure() then -- start UI local message - rtu_state.fp_ok, message = pcall(renderer.start_ui, units) + rtu_state.fp_ok, message = renderer.try_start_ui(units) if not rtu_state.fp_ok then - renderer.close_ui() println_ts(util.c("UI error: ", message)) println("startup> running without front panel") log.error(util.c("front panel GUI render failed with error ", message)) diff --git a/supervisor/renderer.lua b/supervisor/renderer.lua index 1bc70a4..73333d0 100644 --- a/supervisor/renderer.lua +++ b/supervisor/renderer.lua @@ -6,18 +6,23 @@ local panel_view = require("supervisor.panel.front_panel") local pgi = require("supervisor.panel.pgi") local style = require("supervisor.panel.style") +local core = require("graphics.core") local flasher = require("graphics.flasher") local DisplayBox = require("graphics.elements.displaybox") +---@class supervisor_renderer local renderer = {} local ui = { display = nil } --- start the UI -function renderer.start_ui() +-- try to start the UI +---@return boolean success, any error_msg +function renderer.try_start_ui() + local status, msg = true, nil + if ui.display == nil then -- reset terminal term.setTextColor(colors.white) @@ -31,12 +36,22 @@ function renderer.start_ui() end -- init front panel view - ui.display = DisplayBox{window=term.current(),fg_bg=style.root} - panel_view(ui.display) + status, msg = pcall(function () + ui.display = DisplayBox{window=term.current(),fg_bg=style.root} + panel_view(ui.display) + end) - -- start flasher callback task - flasher.run() + if status then + -- start flasher callback task + flasher.run() + else + -- report fail and close ui + msg = core.extract_assert_msg(msg) + renderer.close_ui() + end end + + return status, msg end -- close out the UI diff --git a/supervisor/startup.lua b/supervisor/startup.lua index 4cc4195..11f0948 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -21,7 +21,7 @@ local supervisor = require("supervisor.supervisor") local svsessions = require("supervisor.session.svsessions") -local SUPERVISOR_VERSION = "v1.0.5" +local SUPERVISOR_VERSION = "v1.0.6" local println = util.println local println_ts = util.println_ts @@ -117,10 +117,9 @@ local function main() databus.tx_hw_modem(true) -- start UI - local fp_ok, message = pcall(renderer.start_ui) + local fp_ok, message = renderer.try_start_ui() if not fp_ok then - renderer.close_ui() println_ts(util.c("UI error: ", message)) log.error(util.c("front panel GUI render failed with error ", message)) else