#219 properly close out GUI on error on pocket and coordinator

This commit is contained in:
Mikayla 2023-04-21 18:53:28 +00:00
parent 706fb5ea74
commit e1da8b59d3
12 changed files with 89 additions and 112 deletions

View File

@ -12,19 +12,19 @@ local unit_view = require("coordinator.ui.layout.unit_view")
local flasher = require("graphics.flasher") local flasher = require("graphics.flasher")
local DisplayBox = require("graphics.elements.displaybox")
local renderer = {} local renderer = {}
-- render engine -- render engine
local engine = { local engine = {
monitors = nil, monitors = nil, ---@type monitors_struct|nil
dmesg_window = nil, dmesg_window = nil, ---@type table|nil
ui_ready = false ui_ready = false,
} ui = {
main_display = nil, ---@type graphics_element|nil
-- UI layouts unit_displays = {}
local ui = { }
main_layout = nil,
unit_layouts = {}
} }
-- init a display to the "default", but set text scale to 0.5 -- init a display to the "default", but set text scale to 0.5
@ -57,10 +57,8 @@ function renderer.is_monitor_used(periph)
if engine.monitors.primary == periph then if engine.monitors.primary == periph then
return true return true
else else
for i = 1, #engine.monitors.unit_displays do for _, monitor in ipairs(engine.monitors.units) do
if engine.monitors.unit_displays[i] == periph then if monitor == periph then return true end
return true
end
end end
end end
end end
@ -74,7 +72,7 @@ function renderer.init_displays()
_init_display(engine.monitors.primary) _init_display(engine.monitors.primary)
-- init unit displays -- init unit displays
for _, monitor in pairs(engine.monitors.unit_displays) do for _, monitor in ipairs(engine.monitors.units) do
_init_display(monitor) _init_display(monitor)
end end
end end
@ -93,7 +91,7 @@ end
function renderer.validate_unit_display_sizes() function renderer.validate_unit_display_sizes()
local valid = true local valid = true
for id, monitor in pairs(engine.monitors.unit_displays) do for id, monitor in ipairs(engine.monitors.units) do
local w, h = monitor.getSize() local w, h = monitor.getSize()
if w ~= 79 or h ~= 52 then if w ~= 79 or h ~= 52 then
log.warning(util.c("RENDERER: unit ", id, " display resolution not 79 wide by 52 tall: ", w, ", ", h)) log.warning(util.c("RENDERER: unit ", id, " display resolution not 79 wide by 52 tall: ", w, ", ", h))
@ -108,7 +106,6 @@ end
function renderer.init_dmesg() function renderer.init_dmesg()
local disp_x, disp_y = engine.monitors.primary.getSize() local disp_x, disp_y = engine.monitors.primary.getSize()
engine.dmesg_window = window.create(engine.monitors.primary, 1, 1, disp_x, disp_y) engine.dmesg_window = window.create(engine.monitors.primary, 1, 1, disp_x, disp_y)
log.direct_dmesg(engine.dmesg_window) log.direct_dmesg(engine.dmesg_window)
end end
@ -119,11 +116,13 @@ function renderer.start_ui()
engine.dmesg_window.setVisible(false) engine.dmesg_window.setVisible(false)
-- show main view on main monitor -- show main view on main monitor
ui.main_layout = main_view(engine.monitors.primary) engine.ui.main_display = DisplayBox{window=engine.monitors.primary,fg_bg=style.root}
main_view(engine.ui.main_display)
-- show unit views on unit displays -- show unit views on unit displays
for id, monitor in pairs(engine.monitors.unit_displays) do for i = 1, #engine.monitors.units do
table.insert(ui.unit_layouts, unit_view(monitor, id)) engine.ui.unit_displays[i] = DisplayBox{window=engine.monitors.units[i],fg_bg=style.root}
unit_view(engine.ui.unit_displays[i], i)
end end
-- start flasher callback task -- start flasher callback task
@ -136,29 +135,22 @@ end
-- close out the UI -- close out the UI
function renderer.close_ui() function renderer.close_ui()
-- report ui as not ready
engine.ui_ready = false
-- stop blinking indicators -- stop blinking indicators
flasher.clear() flasher.clear()
if engine.ui_ready then
-- hide to stop animation callbacks -- hide to stop animation callbacks
ui.main_layout.hide() if engine.ui.main_display ~= nil then engine.ui.main_display.hide() end
for i = 1, #ui.unit_layouts do for _, display in ipairs(engine.ui.unit_displays) do display.hide() end
ui.unit_layouts[i].hide()
engine.monitors.unit_displays[i].clear() -- report ui as not ready
end engine.ui_ready = false
else
-- clear unit displays
for i = 1, #ui.unit_layouts do
engine.monitors.unit_displays[i].clear()
end
end
-- clear root UI elements -- clear root UI elements
ui.main_layout = nil engine.ui.main_display = nil
ui.unit_layouts = {} engine.ui.unit_displays = {}
-- clear unit monitors
for _, monitor in ipairs(engine.monitors.units) do monitor.clear() end
-- re-draw dmesg -- re-draw dmesg
engine.dmesg_window.setVisible(true) engine.dmesg_window.setVisible(true)
@ -173,16 +165,18 @@ function renderer.ui_ready() return engine.ui_ready end
-- handle a touch event -- handle a touch event
---@param event mouse_interaction ---@param event mouse_interaction
function renderer.handle_mouse(event) function renderer.handle_mouse(event)
if engine.ui_ready then
if event.monitor == engine.monitors.primary_name then if event.monitor == engine.monitors.primary_name then
ui.main_layout.handle_mouse(event) engine.ui.main_display.handle_mouse(event)
else else
for id, monitor in pairs(engine.monitors.unit_name_map) do for id, monitor in ipairs(engine.monitors.unit_name_map) do
if event.monitor == monitor then if event.monitor == monitor then
local layout = ui.unit_layouts[id] ---@type graphics_element local layout = engine.ui.unit_displays[id] ---@type graphics_element
layout.handle_mouse(event) layout.handle_mouse(event)
end end
end end
end end
end
end end
return renderer return renderer

View File

@ -20,7 +20,7 @@ local sounder = require("coordinator.sounder")
local apisessions = require("coordinator.session.apisessions") local apisessions = require("coordinator.session.apisessions")
local COORDINATOR_VERSION = "v0.13.5" local COORDINATOR_VERSION = "v0.13.6"
local println = util.println local println = util.println
local println_ts = util.println_ts local println_ts = util.println_ts

View File

@ -14,7 +14,6 @@ local unit_overview = require("coordinator.ui.components.unit_overview")
local core = require("graphics.core") local core = require("graphics.core")
local DisplayBox = require("graphics.elements.displaybox")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
local DataIndicator = require("graphics.elements.indicators.data") local DataIndicator = require("graphics.elements.indicators.data")
@ -24,13 +23,11 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.graphics.cpair
-- create new main view -- create new main view
---@param monitor table main viewscreen ---@param main graphics_element main displaybox
local function init(monitor) local function init(main)
local facility = iocontrol.get_db().facility local facility = iocontrol.get_db().facility
local units = iocontrol.get_db().units local units = iocontrol.get_db().units
local main = DisplayBox{window=monitor,fg_bg=style.root}
-- window header message -- window header message
local header = TextBox{parent=main,y=1,text="Nuclear Generation Facility SCADA Coordinator",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} local header = TextBox{parent=main,y=1,text="Nuclear Generation Facility SCADA Coordinator",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
local ping = DataIndicator{parent=main,x=1,y=1,label="SVTT",format="%d",value=0,unit="ms",lu_colors=cpair(colors.lightGray, colors.white),width=12,fg_bg=style.header} local ping = DataIndicator{parent=main,x=1,y=1,label="SVTT",format="%d",value=0,unit="ms",lu_colors=cpair(colors.lightGray, colors.white),width=12,fg_bg=style.header}
@ -87,8 +84,6 @@ local function init(monitor)
process_ctl(main, 2, cnc_bottom_align_start) process_ctl(main, 2, cnc_bottom_align_start)
imatrix(main, 131, cnc_bottom_align_start, facility.induction_data_tbl[1], facility.induction_ps_tbl[1]) imatrix(main, 131, cnc_bottom_align_start, facility.induction_data_tbl[1], facility.induction_ps_tbl[1])
return main
end end
return init return init

View File

@ -2,21 +2,13 @@
-- Reactor Unit SCADA Coordinator GUI -- Reactor Unit SCADA Coordinator GUI
-- --
local style = require("coordinator.ui.style")
local unit_detail = require("coordinator.ui.components.unit_detail") local unit_detail = require("coordinator.ui.components.unit_detail")
local DisplayBox = require("graphics.elements.displaybox")
-- create a unit view -- create a unit view
---@param monitor table ---@param main graphics_element main displaybox
---@param id integer ---@param id integer
local function init(monitor, id) local function init(main, id)
local main = DisplayBox{window=monitor,fg_bg=style.root}
unit_detail(main, id) unit_detail(main, id)
return main
end end
return init return init

View File

@ -7,15 +7,17 @@ local style = require("pocket.ui.style")
local flasher = require("graphics.flasher") local flasher = require("graphics.flasher")
local DisplayBox = require("graphics.elements.displaybox")
local renderer = {} local renderer = {}
local ui = { local ui = {
view = nil display = nil
} }
-- start the pocket GUI -- start the pocket GUI
function renderer.start_ui() function renderer.start_ui()
if ui.view == nil then if ui.display == nil then
-- reset screen -- reset screen
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
@ -27,11 +29,12 @@ function renderer.start_ui()
term.setPaletteColor(style.colors[i].c, style.colors[i].hex) term.setPaletteColor(style.colors[i].c, style.colors[i].hex)
end end
-- init front panel view
ui.display = DisplayBox{window=term.current(),fg_bg=style.root}
main_view(ui.display)
-- start flasher callback task -- start flasher callback task
flasher.run() flasher.run()
-- init front panel view
ui.view = main_view(term.current())
end end
end end
@ -40,13 +43,13 @@ function renderer.close_ui()
-- stop blinking indicators -- stop blinking indicators
flasher.clear() flasher.clear()
if ui.view ~= nil then if ui.display ~= nil then
-- hide to stop animation callbacks -- hide to stop animation callbacks
ui.view.hide() ui.display.hide()
end end
-- clear root UI elements -- clear root UI elements
ui.view = nil ui.display = nil
-- restore colors -- restore colors
for i = 1, #style.colors do for i = 1, #style.colors do
@ -64,12 +67,14 @@ end
-- is the UI ready? -- is the UI ready?
---@nodiscard ---@nodiscard
---@return boolean ready ---@return boolean ready
function renderer.ui_ready() return ui.view ~= nil end function renderer.ui_ready() return ui.display ~= nil end
-- handle a mouse event -- handle a mouse event
---@param event mouse_interaction ---@param event mouse_interaction
function renderer.handle_mouse(event) function renderer.handle_mouse(event)
ui.view.handle_mouse(event) if ui.display ~= nil then
ui.display.handle_mouse(event)
end
end end
return renderer return renderer

View File

@ -17,7 +17,7 @@ local coreio = require("pocket.coreio")
local pocket = require("pocket.pocket") local pocket = require("pocket.pocket")
local renderer = require("pocket.renderer") local renderer = require("pocket.renderer")
local POCKET_VERSION = "alpha-v0.2.4" local POCKET_VERSION = "alpha-v0.2.5"
local println = util.println local println = util.println
local println_ts = util.println_ts local println_ts = util.println_ts

View File

@ -16,7 +16,6 @@ local turbine_page = require("pocket.ui.components.turbine_page")
local core = require("graphics.core") local core = require("graphics.core")
local DisplayBox = require("graphics.elements.displaybox")
local Div = require("graphics.elements.div") local Div = require("graphics.elements.div")
local MultiPane = require("graphics.elements.multipane") local MultiPane = require("graphics.elements.multipane")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
@ -28,10 +27,8 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.graphics.cpair
-- create new main view -- create new main view
---@param monitor table main viewscreen ---@param main graphics_element main displaybox
local function init(monitor) local function init(main)
local main = DisplayBox{window=monitor,fg_bg=style.root}
-- window header message -- window header message
TextBox{parent=main,y=1,text="",alignment=TEXT_ALIGN.LEFT,height=1,fg_bg=style.header} TextBox{parent=main,y=1,text="",alignment=TEXT_ALIGN.LEFT,height=1,fg_bg=style.header}
@ -97,8 +94,6 @@ local function init(monitor)
local page_pane = MultiPane{parent=page_div,x=1,y=1,panes=panes} local page_pane = MultiPane{parent=page_div,x=1,y=1,panes=panes}
Sidebar{parent=main_pane,x=1,y=1,tabs=sidebar_tabs,fg_bg=cpair(colors.white,colors.gray),callback=page_pane.set_value} Sidebar{parent=main_pane,x=1,y=1,tabs=sidebar_tabs,fg_bg=cpair(colors.white,colors.gray),callback=page_pane.set_value}
return main
end end
return init return init

View File

@ -28,7 +28,7 @@ local cpair = core.graphics.cpair
local border = core.graphics.border local border = core.graphics.border
-- create new main view -- create new main view
---@param panel table main displaybox ---@param panel graphics_element main displaybox
local function init(panel) local function init(panel)
local header = TextBox{parent=panel,y=1,text="REACTOR PLC - UNIT ?",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} local header = TextBox{parent=panel,y=1,text="REACTOR PLC - UNIT ?",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
databus.rx_field("unit_id", function (id) header.set_value(util.c("REACTOR PLC - UNIT ", id)) end) databus.rx_field("unit_id", function (id) header.set_value(util.c("REACTOR PLC - UNIT ", id)) end)
@ -137,8 +137,6 @@ local function init(panel)
databus.rx_field("rps_high_waste", rps_wst.update) databus.rx_field("rps_high_waste", rps_wst.update)
databus.rx_field("rps_low_ccool", rps_ccl.update) databus.rx_field("rps_low_ccool", rps_ccl.update)
databus.rx_field("rps_high_hcool", rps_hcl.update) databus.rx_field("rps_high_hcool", rps_hcl.update)
return panel
end end
return init return init

View File

@ -29,12 +29,12 @@ function renderer.start_ui()
term.setPaletteColor(style.colors[i].c, style.colors[i].hex) term.setPaletteColor(style.colors[i].c, style.colors[i].hex)
end end
-- start flasher callback task
flasher.run()
-- init front panel view -- init front panel view
ui.display = DisplayBox{window=term.current(),fg_bg=style.root} ui.display = DisplayBox{window=term.current(),fg_bg=style.root}
panel_view(ui.display) panel_view(ui.display)
-- start flasher callback task
flasher.run()
end end
end end

View File

@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc")
local renderer = require("reactor-plc.renderer") local renderer = require("reactor-plc.renderer")
local threads = require("reactor-plc.threads") local threads = require("reactor-plc.threads")
local R_PLC_VERSION = "v1.1.14" local R_PLC_VERSION = "v1.1.15"
local println = util.println local println = util.println
local println_ts = util.println_ts local println_ts = util.println_ts

View File

@ -33,7 +33,7 @@ local UNIT_TYPE_LABELS = {
-- create new main view -- create new main view
---@param panel table main displaybox ---@param panel graphics_element main displaybox
---@param units table unit list ---@param units table unit list
local function init(panel, units) local function init(panel, units)
TextBox{parent=panel,y=1,text="RTU GATEWAY",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} TextBox{parent=panel,y=1,text="RTU GATEWAY",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
@ -116,8 +116,6 @@ local function init(panel, units)
local for_unit = util.trinary(unit.reactor == 0, "\x1a FACIL ", "\x1a UNIT " .. unit.reactor) local for_unit = util.trinary(unit.reactor == 0, "\x1a FACIL ", "\x1a UNIT " .. unit.reactor)
TextBox{parent=unit_hw_statuses,y=i,x=19,text=for_unit,height=1,fg_bg=cpair(colors.lightGray,colors.ivory)} TextBox{parent=unit_hw_statuses,y=i,x=19,text=for_unit,height=1,fg_bg=cpair(colors.lightGray,colors.ivory)}
end end
return panel
end end
return init return init

View File

@ -28,7 +28,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
local sps_rtu = require("rtu.dev.sps_rtu") local sps_rtu = require("rtu.dev.sps_rtu")
local turbinev_rtu = require("rtu.dev.turbinev_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu")
local RTU_VERSION = "v1.0.2" local RTU_VERSION = "v1.0.3"
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE