mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#219 properly close out GUI on error on pocket and coordinator
This commit is contained in:
parent
706fb5ea74
commit
e1da8b59d3
@ -2,29 +2,29 @@
|
||||
-- Graphics Rendering Control
|
||||
--
|
||||
|
||||
local log = require("scada-common.log")
|
||||
local util = require("scada-common.util")
|
||||
local log = require("scada-common.log")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local style = require("coordinator.ui.style")
|
||||
local style = require("coordinator.ui.style")
|
||||
|
||||
local main_view = require("coordinator.ui.layout.main_view")
|
||||
local unit_view = require("coordinator.ui.layout.unit_view")
|
||||
local main_view = require("coordinator.ui.layout.main_view")
|
||||
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 = {}
|
||||
|
||||
-- render engine
|
||||
local engine = {
|
||||
monitors = nil,
|
||||
dmesg_window = nil,
|
||||
ui_ready = false
|
||||
}
|
||||
|
||||
-- UI layouts
|
||||
local ui = {
|
||||
main_layout = nil,
|
||||
unit_layouts = {}
|
||||
monitors = nil, ---@type monitors_struct|nil
|
||||
dmesg_window = nil, ---@type table|nil
|
||||
ui_ready = false,
|
||||
ui = {
|
||||
main_display = nil, ---@type graphics_element|nil
|
||||
unit_displays = {}
|
||||
}
|
||||
}
|
||||
|
||||
-- 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
|
||||
return true
|
||||
else
|
||||
for i = 1, #engine.monitors.unit_displays do
|
||||
if engine.monitors.unit_displays[i] == periph then
|
||||
return true
|
||||
end
|
||||
for _, monitor in ipairs(engine.monitors.units) do
|
||||
if monitor == periph then return true end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -74,7 +72,7 @@ function renderer.init_displays()
|
||||
_init_display(engine.monitors.primary)
|
||||
|
||||
-- init unit displays
|
||||
for _, monitor in pairs(engine.monitors.unit_displays) do
|
||||
for _, monitor in ipairs(engine.monitors.units) do
|
||||
_init_display(monitor)
|
||||
end
|
||||
end
|
||||
@ -93,7 +91,7 @@ end
|
||||
function renderer.validate_unit_display_sizes()
|
||||
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()
|
||||
if w ~= 79 or h ~= 52 then
|
||||
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()
|
||||
local disp_x, disp_y = engine.monitors.primary.getSize()
|
||||
engine.dmesg_window = window.create(engine.monitors.primary, 1, 1, disp_x, disp_y)
|
||||
|
||||
log.direct_dmesg(engine.dmesg_window)
|
||||
end
|
||||
|
||||
@ -119,11 +116,13 @@ function renderer.start_ui()
|
||||
engine.dmesg_window.setVisible(false)
|
||||
|
||||
-- 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
|
||||
for id, monitor in pairs(engine.monitors.unit_displays) do
|
||||
table.insert(ui.unit_layouts, unit_view(monitor, id))
|
||||
for i = 1, #engine.monitors.units do
|
||||
engine.ui.unit_displays[i] = DisplayBox{window=engine.monitors.units[i],fg_bg=style.root}
|
||||
unit_view(engine.ui.unit_displays[i], i)
|
||||
end
|
||||
|
||||
-- start flasher callback task
|
||||
@ -136,29 +135,22 @@ end
|
||||
|
||||
-- close out the UI
|
||||
function renderer.close_ui()
|
||||
-- report ui as not ready
|
||||
engine.ui_ready = false
|
||||
|
||||
-- stop blinking indicators
|
||||
flasher.clear()
|
||||
|
||||
if engine.ui_ready then
|
||||
-- hide to stop animation callbacks
|
||||
ui.main_layout.hide()
|
||||
for i = 1, #ui.unit_layouts do
|
||||
ui.unit_layouts[i].hide()
|
||||
engine.monitors.unit_displays[i].clear()
|
||||
end
|
||||
else
|
||||
-- clear unit displays
|
||||
for i = 1, #ui.unit_layouts do
|
||||
engine.monitors.unit_displays[i].clear()
|
||||
end
|
||||
end
|
||||
-- hide to stop animation callbacks
|
||||
if engine.ui.main_display ~= nil then engine.ui.main_display.hide() end
|
||||
for _, display in ipairs(engine.ui.unit_displays) do display.hide() end
|
||||
|
||||
-- report ui as not ready
|
||||
engine.ui_ready = false
|
||||
|
||||
-- clear root UI elements
|
||||
ui.main_layout = nil
|
||||
ui.unit_layouts = {}
|
||||
engine.ui.main_display = nil
|
||||
engine.ui.unit_displays = {}
|
||||
|
||||
-- clear unit monitors
|
||||
for _, monitor in ipairs(engine.monitors.units) do monitor.clear() end
|
||||
|
||||
-- re-draw dmesg
|
||||
engine.dmesg_window.setVisible(true)
|
||||
@ -173,13 +165,15 @@ function renderer.ui_ready() return engine.ui_ready end
|
||||
-- handle a touch event
|
||||
---@param event mouse_interaction
|
||||
function renderer.handle_mouse(event)
|
||||
if event.monitor == engine.monitors.primary_name then
|
||||
ui.main_layout.handle_mouse(event)
|
||||
else
|
||||
for id, monitor in pairs(engine.monitors.unit_name_map) do
|
||||
if event.monitor == monitor then
|
||||
local layout = ui.unit_layouts[id] ---@type graphics_element
|
||||
layout.handle_mouse(event)
|
||||
if engine.ui_ready then
|
||||
if event.monitor == engine.monitors.primary_name then
|
||||
engine.ui.main_display.handle_mouse(event)
|
||||
else
|
||||
for id, monitor in ipairs(engine.monitors.unit_name_map) do
|
||||
if event.monitor == monitor then
|
||||
local layout = engine.ui.unit_displays[id] ---@type graphics_element
|
||||
layout.handle_mouse(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -20,7 +20,7 @@ local sounder = require("coordinator.sounder")
|
||||
|
||||
local apisessions = require("coordinator.session.apisessions")
|
||||
|
||||
local COORDINATOR_VERSION = "v0.13.5"
|
||||
local COORDINATOR_VERSION = "v0.13.6"
|
||||
|
||||
local println = util.println
|
||||
local println_ts = util.println_ts
|
||||
|
@ -14,7 +14,6 @@ local unit_overview = require("coordinator.ui.components.unit_overview")
|
||||
|
||||
local core = require("graphics.core")
|
||||
|
||||
local DisplayBox = require("graphics.elements.displaybox")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
|
||||
local DataIndicator = require("graphics.elements.indicators.data")
|
||||
@ -24,13 +23,11 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN
|
||||
local cpair = core.graphics.cpair
|
||||
|
||||
-- create new main view
|
||||
---@param monitor table main viewscreen
|
||||
local function init(monitor)
|
||||
---@param main graphics_element main displaybox
|
||||
local function init(main)
|
||||
local facility = iocontrol.get_db().facility
|
||||
local units = iocontrol.get_db().units
|
||||
|
||||
local main = DisplayBox{window=monitor,fg_bg=style.root}
|
||||
|
||||
-- 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 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)
|
||||
|
||||
imatrix(main, 131, cnc_bottom_align_start, facility.induction_data_tbl[1], facility.induction_ps_tbl[1])
|
||||
|
||||
return main
|
||||
end
|
||||
|
||||
return init
|
||||
|
@ -2,21 +2,13 @@
|
||||
-- Reactor Unit SCADA Coordinator GUI
|
||||
--
|
||||
|
||||
local style = require("coordinator.ui.style")
|
||||
|
||||
local unit_detail = require("coordinator.ui.components.unit_detail")
|
||||
|
||||
local DisplayBox = require("graphics.elements.displaybox")
|
||||
|
||||
-- create a unit view
|
||||
---@param monitor table
|
||||
---@param main graphics_element main displaybox
|
||||
---@param id integer
|
||||
local function init(monitor, id)
|
||||
local main = DisplayBox{window=monitor,fg_bg=style.root}
|
||||
|
||||
local function init(main, id)
|
||||
unit_detail(main, id)
|
||||
|
||||
return main
|
||||
end
|
||||
|
||||
return init
|
||||
|
@ -2,20 +2,22 @@
|
||||
-- Graphics Rendering Control
|
||||
--
|
||||
|
||||
local main_view = require("pocket.ui.main")
|
||||
local style = require("pocket.ui.style")
|
||||
local main_view = require("pocket.ui.main")
|
||||
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 ui = {
|
||||
view = nil
|
||||
display = nil
|
||||
}
|
||||
|
||||
-- start the pocket GUI
|
||||
function renderer.start_ui()
|
||||
if ui.view == nil then
|
||||
if ui.display == nil then
|
||||
-- reset screen
|
||||
term.setTextColor(colors.white)
|
||||
term.setBackgroundColor(colors.black)
|
||||
@ -27,11 +29,12 @@ function renderer.start_ui()
|
||||
term.setPaletteColor(style.colors[i].c, style.colors[i].hex)
|
||||
end
|
||||
|
||||
-- init front panel view
|
||||
ui.display = DisplayBox{window=term.current(),fg_bg=style.root}
|
||||
main_view(ui.display)
|
||||
|
||||
-- start flasher callback task
|
||||
flasher.run()
|
||||
|
||||
-- init front panel view
|
||||
ui.view = main_view(term.current())
|
||||
end
|
||||
end
|
||||
|
||||
@ -40,13 +43,13 @@ function renderer.close_ui()
|
||||
-- stop blinking indicators
|
||||
flasher.clear()
|
||||
|
||||
if ui.view ~= nil then
|
||||
if ui.display ~= nil then
|
||||
-- hide to stop animation callbacks
|
||||
ui.view.hide()
|
||||
ui.display.hide()
|
||||
end
|
||||
|
||||
-- clear root UI elements
|
||||
ui.view = nil
|
||||
ui.display = nil
|
||||
|
||||
-- restore colors
|
||||
for i = 1, #style.colors do
|
||||
@ -64,12 +67,14 @@ end
|
||||
-- is the UI ready?
|
||||
---@nodiscard
|
||||
---@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
|
||||
---@param event mouse_interaction
|
||||
function renderer.handle_mouse(event)
|
||||
ui.view.handle_mouse(event)
|
||||
if ui.display ~= nil then
|
||||
ui.display.handle_mouse(event)
|
||||
end
|
||||
end
|
||||
|
||||
return renderer
|
||||
|
@ -17,7 +17,7 @@ local coreio = require("pocket.coreio")
|
||||
local pocket = require("pocket.pocket")
|
||||
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_ts = util.println_ts
|
||||
|
@ -4,34 +4,31 @@
|
||||
|
||||
local coreio = require("pocket.coreio")
|
||||
|
||||
local style = require("pocket.ui.style")
|
||||
local style = require("pocket.ui.style")
|
||||
|
||||
local conn_waiting = require("pocket.ui.components.conn_waiting")
|
||||
local conn_waiting = require("pocket.ui.components.conn_waiting")
|
||||
|
||||
local home_page = require("pocket.ui.components.home_page")
|
||||
local unit_page = require("pocket.ui.components.unit_page")
|
||||
local reactor_page = require("pocket.ui.components.reactor_page")
|
||||
local boiler_page = require("pocket.ui.components.boiler_page")
|
||||
local turbine_page = require("pocket.ui.components.turbine_page")
|
||||
local home_page = require("pocket.ui.components.home_page")
|
||||
local unit_page = require("pocket.ui.components.unit_page")
|
||||
local reactor_page = require("pocket.ui.components.reactor_page")
|
||||
local boiler_page = require("pocket.ui.components.boiler_page")
|
||||
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 MultiPane = require("graphics.elements.multipane")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
local Div = require("graphics.elements.div")
|
||||
local MultiPane = require("graphics.elements.multipane")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
|
||||
local Sidebar = require("graphics.elements.controls.sidebar")
|
||||
local Sidebar = require("graphics.elements.controls.sidebar")
|
||||
|
||||
local TEXT_ALIGN = core.graphics.TEXT_ALIGN
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
|
||||
-- create new main view
|
||||
---@param monitor table main viewscreen
|
||||
local function init(monitor)
|
||||
local main = DisplayBox{window=monitor,fg_bg=style.root}
|
||||
|
||||
---@param main graphics_element main displaybox
|
||||
local function init(main)
|
||||
-- window header message
|
||||
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}
|
||||
|
||||
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
|
||||
|
||||
return init
|
||||
|
@ -28,7 +28,7 @@ local cpair = core.graphics.cpair
|
||||
local border = core.graphics.border
|
||||
|
||||
-- create new main view
|
||||
---@param panel table main displaybox
|
||||
---@param panel graphics_element main displaybox
|
||||
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}
|
||||
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_low_ccool", rps_ccl.update)
|
||||
databus.rx_field("rps_high_hcool", rps_hcl.update)
|
||||
|
||||
return panel
|
||||
end
|
||||
|
||||
return init
|
||||
|
@ -29,12 +29,12 @@ function renderer.start_ui()
|
||||
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)
|
||||
|
||||
-- start flasher callback task
|
||||
flasher.run()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc")
|
||||
local renderer = require("reactor-plc.renderer")
|
||||
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_ts = util.println_ts
|
||||
|
@ -33,7 +33,7 @@ local UNIT_TYPE_LABELS = {
|
||||
|
||||
|
||||
-- create new main view
|
||||
---@param panel table main displaybox
|
||||
---@param panel graphics_element main displaybox
|
||||
---@param units table unit list
|
||||
local function init(panel, units)
|
||||
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)
|
||||
TextBox{parent=unit_hw_statuses,y=i,x=19,text=for_unit,height=1,fg_bg=cpair(colors.lightGray,colors.ivory)}
|
||||
end
|
||||
|
||||
return panel
|
||||
end
|
||||
|
||||
return init
|
||||
|
@ -28,7 +28,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.0.2"
|
||||
local RTU_VERSION = "v1.0.3"
|
||||
|
||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE
|
||||
|
Loading…
Reference in New Issue
Block a user