mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
This commit is contained in:
parent
971657c3d2
commit
7f007e032d
@ -3,8 +3,8 @@ local util = require("scada-common.util")
|
||||
|
||||
local core = require("graphics.core")
|
||||
|
||||
local main_layout = require("coordinator.ui.main_layout")
|
||||
local unit_layout = require("coordinator.ui.unit_layout")
|
||||
local main_view = require("coordinator.ui.layout.main_view")
|
||||
local unit_view = require("coordinator.ui.layout.unit_view")
|
||||
|
||||
local renderer = {}
|
||||
|
||||
@ -56,10 +56,15 @@ end
|
||||
|
||||
-- start the coordinator GUI
|
||||
function renderer.start_ui()
|
||||
ui.main_layout = main_layout(engine.monitors.primary)
|
||||
-- hide dmesg
|
||||
engine.dmesg_window.setVisible(false)
|
||||
|
||||
-- show main view on main monitor
|
||||
ui.main_layout = main_view(engine.monitors.primary)
|
||||
|
||||
-- show unit views on unit displays
|
||||
for id, monitor in pairs(engine.monitors.unit_displays) do
|
||||
table.insert(ui.unit_layouts, unit_layout(monitor, id))
|
||||
table.insert(ui.unit_layouts, unit_view(monitor, id))
|
||||
end
|
||||
end
|
||||
|
||||
@ -73,6 +78,7 @@ function renderer.close_ui()
|
||||
renderer.reset()
|
||||
|
||||
-- re-draw dmesg
|
||||
engine.dmesg_window.setVisible(true)
|
||||
engine.dmesg_window.redraw()
|
||||
end
|
||||
|
||||
|
@ -12,7 +12,7 @@ local config = require("coordinator.config")
|
||||
local coordinator = require("coordinator.coordinator")
|
||||
local renderer = require("coordinator.renderer")
|
||||
|
||||
local COORDINATOR_VERSION = "alpha-v0.1.6"
|
||||
local COORDINATOR_VERSION = "alpha-v0.2.0"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
@ -85,8 +85,8 @@ log.dmesg("wireless modem connected", "COMMS", colors.purple)
|
||||
log.dmesg("starting UI...", "GRAPHICS", colors.green)
|
||||
util.psleep(3)
|
||||
|
||||
local ui_ok = pcall(renderer.start_ui)
|
||||
local ui_ok, message = pcall(renderer.start_ui)
|
||||
if not ui_ok then
|
||||
renderer.close_ui()
|
||||
log.dmesg("UI draw failed", "GRAPHICS", colors.green)
|
||||
log.dmesg("UI draw failed: " .. message, "GRAPHICS", colors.green)
|
||||
end
|
||||
|
43
coordinator/ui/components/unit_overview.lua
Normal file
43
coordinator/ui/components/unit_overview.lua
Normal file
@ -0,0 +1,43 @@
|
||||
local core = require("graphics.core")
|
||||
|
||||
local style = require("coordinator.ui.style")
|
||||
|
||||
local Div = require("graphics.elements.div")
|
||||
local HorizontalBar = require("graphics.elements.indicators.hbar")
|
||||
local DataIndicator = require("graphics.elements.indicators.data")
|
||||
local StateIndicator = require("graphics.elements.indicators.state")
|
||||
local Rectangle = require("graphics.elements.rectangle")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
|
||||
local TEXT_ALIGN = core.graphics.TEXT_ALIGN
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
local border = core.graphics.border
|
||||
|
||||
---@param parent graphics_element
|
||||
local function make(parent, x, y, unit_id)
|
||||
-- bounding box div
|
||||
local root = Div{parent=parent,x=x,y=y,width=75,height=50}
|
||||
|
||||
-- unit header message
|
||||
TextBox{parent=root,text="Unit #" .. unit_id,alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
|
||||
|
||||
-- reactor
|
||||
local reactor = Rectangle{parent=root,border=border(1, colors.gray, false),width=30,height=10,x=1,y=3}
|
||||
|
||||
local text_fg_bg = cpair(colors.black, colors.lightGray)
|
||||
local lu_col = cpair(colors.gray, colors.gray)
|
||||
|
||||
local status = StateIndicator{parent=reactor,x=9,y=2,states=style.reactor.states,value=1,min_width=14}
|
||||
local core_temp = DataIndicator{parent=reactor,x=3,y=4,lu_colors=lu_col,label="Core: ",unit="K",format="%7.0f",value=295,width=26,fg_bg=text_fg_bg}
|
||||
local heating_r = DataIndicator{parent=reactor,x=3,y=5,lu_colors=lu_col,label="Heating:",unit="mB/t",format="%7.0f",value=359999,width=26,fg_bg=text_fg_bg}
|
||||
local burn_r = DataIndicator{parent=reactor,x=3,y=6,lu_colors=lu_col,label="Burn: ",unit="mB/t",format="%7.1f",value=40.1,width=26,fg_bg=text_fg_bg}
|
||||
|
||||
local fuel = HorizontalBar{parent=root,x=34,y=4,show_percent=true,bar_fg_bg=cpair(colors.brown,colors.white),height=1,width=14}
|
||||
local coolant = HorizontalBar{parent=root,x=34,y=5,show_percent=true,bar_fg_bg=cpair(colors.lightBlue,colors.white),height=1,width=14}
|
||||
|
||||
fuel.update(0.85)
|
||||
coolant.update(0.75)
|
||||
end
|
||||
|
||||
return make
|
29
coordinator/ui/layout/main_view.lua
Normal file
29
coordinator/ui/layout/main_view.lua
Normal file
@ -0,0 +1,29 @@
|
||||
--
|
||||
-- Main SCADA Coordinator GUI
|
||||
--
|
||||
|
||||
local core = require("graphics.core")
|
||||
local log = require("scada-common.log")
|
||||
|
||||
local style = require("coordinator.ui.style")
|
||||
|
||||
local DisplayBox = require("graphics.elements.displaybox")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
|
||||
local unit_overview = require("coordinator.ui.components.unit_overview")
|
||||
|
||||
local TEXT_ALIGN = core.graphics.TEXT_ALIGN
|
||||
|
||||
local function init(monitor)
|
||||
local main = DisplayBox{window=monitor,fg_bg=style.root}
|
||||
|
||||
-- window header message
|
||||
TextBox{parent=main,text="Nuclear Generation Facility SCADA Coordinator",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
|
||||
|
||||
-- unit overviews
|
||||
unit_overview(main, 5, 5, 1)
|
||||
|
||||
return main
|
||||
end
|
||||
|
||||
return init
|
22
coordinator/ui/layout/unit_view.lua
Normal file
22
coordinator/ui/layout/unit_view.lua
Normal file
@ -0,0 +1,22 @@
|
||||
--
|
||||
-- Reactor Unit SCADA Coordinator GUI
|
||||
--
|
||||
|
||||
local core = require("graphics.core")
|
||||
|
||||
local style = require("coordinator.ui.style")
|
||||
|
||||
local DisplayBox = require("graphics.elements.displaybox")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
|
||||
local TEXT_ALIGN = core.graphics.TEXT_ALIGN
|
||||
|
||||
local function init(monitor, id)
|
||||
local main = DisplayBox{window=monitor,fg_bg=style.root}
|
||||
|
||||
TextBox{parent=main,text="Reactor Unit #" .. id,alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
|
||||
|
||||
return main
|
||||
end
|
||||
|
||||
return init
|
@ -1,21 +0,0 @@
|
||||
--
|
||||
-- Main SCADA Coordinator GUI
|
||||
--
|
||||
|
||||
local core = require("graphics.core")
|
||||
local layout = require("graphics.layout")
|
||||
|
||||
local style = require("coordinator.ui.style")
|
||||
|
||||
local displaybox = require("graphics.elements.displaybox")
|
||||
local textbox = require("graphics.elements.textbox")
|
||||
|
||||
local function init(monitor)
|
||||
local main = layout.create(monitor, displaybox{window=monitor,fg_bg=style.root})
|
||||
|
||||
textbox{parent=main,text="Nuclear Generation Facility SCADA Coordinator",alignment=core.graphics.TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
|
||||
|
||||
return main
|
||||
end
|
||||
|
||||
return init
|
@ -3,9 +3,33 @@ local core = require("graphics.core")
|
||||
|
||||
local style = {}
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
|
||||
-- MAIN LAYOUT --
|
||||
|
||||
style.root = core.graphics.cpair(colors.black, colors.lightGray)
|
||||
style.header = core.graphics.cpair(colors.white,colors.gray)
|
||||
style.root = cpair(colors.black, colors.lightGray)
|
||||
style.header = cpair(colors.white, colors.gray)
|
||||
|
||||
style.reactor = {
|
||||
-- reactor states
|
||||
states = {
|
||||
{
|
||||
color = cpair(colors.black, colors.yellow),
|
||||
text = "DISCONNECTED"
|
||||
},
|
||||
{
|
||||
color = cpair(colors.white, colors.gray),
|
||||
text = "DISABLED"
|
||||
},
|
||||
{
|
||||
color = cpair(colors.black, colors.green),
|
||||
text = "ACTIVE"
|
||||
},
|
||||
{
|
||||
color = cpair(colors.black, colors.red),
|
||||
text = "SCRAM!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return style
|
||||
|
@ -1,21 +0,0 @@
|
||||
--
|
||||
-- Reactor Unit SCADA Coordinator GUI
|
||||
--
|
||||
|
||||
local core = require("graphics.core")
|
||||
local layout = require("graphics.layout")
|
||||
|
||||
local style = require("coordinator.ui.style")
|
||||
|
||||
local displaybox = require("graphics.elements.displaybox")
|
||||
local textbox = require("graphics.elements.textbox")
|
||||
|
||||
local function init(monitor, id)
|
||||
local main = layout.create(monitor, displaybox{window=monitor,fg_bg=style.root})
|
||||
|
||||
textbox{parent=main,text="Reactor Unit #" .. id,alignment=core.graphics.TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
|
||||
|
||||
return main
|
||||
end
|
||||
|
||||
return init
|
@ -1,75 +0,0 @@
|
||||
--
|
||||
-- Graphics View Layout
|
||||
--
|
||||
|
||||
local core = require("graphics.core")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local displaybox = require("graphics.elements.displaybox")
|
||||
|
||||
local layout = {}
|
||||
|
||||
---@class stem
|
||||
---@field element graphics_element
|
||||
---@field children table
|
||||
|
||||
function layout.create(window, default_fg_bg)
|
||||
local self = {
|
||||
root = displaybox{window=window,fg_bg=default_fg_bg},
|
||||
tree = {}
|
||||
}
|
||||
|
||||
-- recursive function to search layout tree for an element
|
||||
---@param id string element ID to look for
|
||||
---@param tree table tree to search in
|
||||
---@return stem|nil
|
||||
local function lookup(id, tree)
|
||||
for key, stem in pairs(tree) do
|
||||
if key == id then
|
||||
return stem
|
||||
else
|
||||
stem = lookup(id, stem.children)
|
||||
if stem ~= nil then return stem end
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
---@class layout
|
||||
local public = {}
|
||||
|
||||
-- insert a new element
|
||||
---@param parent_id string|nil parent or nil for root
|
||||
---@param id string element ID
|
||||
---@param element graphics_element
|
||||
function public.insert_at(parent_id, id, element)
|
||||
if parent_id == nil then
|
||||
self.tree[id] = { element = element, children = {} }
|
||||
else
|
||||
local parent = lookup(parent_id, self.tree)
|
||||
if parent ~= nil then
|
||||
parent.children[id] = { element = element, children = {} }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- get an element by ID
|
||||
---@param id string element ID
|
||||
---@return graphics_element|nil
|
||||
function public.get_element_by_id(id)
|
||||
local elem = lookup(id, self.tree)
|
||||
---@diagnostic disable-next-line: need-check-nil
|
||||
return util.trinary(elem == nil, nil, elem.element)
|
||||
end
|
||||
|
||||
-- get the root element
|
||||
---@return graphics_element
|
||||
function public.get_root()
|
||||
return self.root
|
||||
end
|
||||
|
||||
return public
|
||||
end
|
||||
|
||||
return layout
|
Loading…
Reference in New Issue
Block a user