#182 WIP PLC front panel

This commit is contained in:
Mikayla Fischler
2023-04-06 22:10:33 -04:00
parent efef4a845f
commit 6ea530635f
9 changed files with 426 additions and 6 deletions

View File

@@ -0,0 +1,85 @@
--
-- Main SCADA Coordinator GUI
--
local util = require("scada-common.util")
local style = require("reactor-plc.panel.style")
local core = require("graphics.core")
local DisplayBox = require("graphics.elements.displaybox")
local Div = require("graphics.elements.div")
local Rectangle = require("graphics.elements.rectangle")
local TextBox = require("graphics.elements.textbox")
local ColorMap = require("graphics.elements.colormap")
local PushButton = require("graphics.elements.controls.push_button")
local SwitchButton = require("graphics.elements.controls.switch_button")
local DataIndicator = require("graphics.elements.indicators.data")
local LED = require("graphics.elements.indicators.led")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN
local cpair = core.graphics.cpair
local border = core.graphics.border
-- create new main view
---@param monitor table main viewscreen
local function init(monitor)
local panel = DisplayBox{window=monitor,fg_bg=style.root}
-- window header message
local header = TextBox{parent=panel,y=1,text="REACTOR PLC",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
local system = Div{parent=panel,width=14,height=18,x=2,y=3}
local init_ok = LED{parent=system,label="STATUS",colors=cpair(colors.green,colors.red)}
local heartbeat = LED{parent=system,label="HEARTBEAT",colors=cpair(colors.green,colors.green_off)}
system.line_break()
local reactor = LED{parent=system,label="REACTOR",colors=cpair(colors.green,colors.red)}
local modem = LED{parent=system,label="MODEM",colors=cpair(colors.green,colors.gray)}
local network = LED{parent=system,label="NETWORK",colors=cpair(colors.green,colors.gray)}
system.line_break()
local _ = LED{parent=system,label="RT MAIN",colors=cpair(colors.green,colors.gray)}
local _ = LED{parent=system,label="RT RPS",colors=cpair(colors.green,colors.gray)}
local _ = LED{parent=system,label="RT COMMS TX",colors=cpair(colors.green,colors.gray)}
local _ = LED{parent=system,label="RT COMMS RX",colors=cpair(colors.green,colors.gray)}
local _ = LED{parent=system,label="RT SPCTL",colors=cpair(colors.green,colors.gray)}
system.line_break()
local active = LED{parent=system,label="RCT ACTIVE",colors=cpair(colors.green,colors.green_off)}
local scram = LED{parent=system,label="RPS TRIP",colors=cpair(colors.red,colors.red_off)}
system.line_break()
local about = Rectangle{parent=panel,width=16,height=4,x=18,y=15,border=border(1,colors.white),thin=true,fg_bg=cpair(colors.black,colors.white)}
local _ = TextBox{parent=about,text="FW: v1.0.0",alignment=TEXT_ALIGN.LEFT,height=1}
local _ = TextBox{parent=about,text="NT: v1.4.0",alignment=TEXT_ALIGN.LEFT,height=1}
-- about.line_break()
-- local _ = TextBox{parent=about,text="SVTT: 10ms",alignment=TEXT_ALIGN.LEFT,height=1}
local rps = Rectangle{parent=panel,width=16,height=16,x=36,y=3,border=border(1,colors.lightGray),thin=true,fg_bg=cpair(colors.black,colors.lightGray)}
local _ = LED{parent=rps,label="MANUAL",colors=cpair(colors.red,colors.red_off)}
local _ = LED{parent=rps,label="AUTOMATIC",colors=cpair(colors.red,colors.red_off)}
local _ = LED{parent=rps,label="TIMEOUT",colors=cpair(colors.red,colors.red_off)}
local _ = LED{parent=rps,label="PLC FAULT",colors=cpair(colors.red,colors.red_off)}
local _ = LED{parent=rps,label="RCT FAULT",colors=cpair(colors.red,colors.red_off)}
rps.line_break()
local _ = LED{parent=rps,label="HI DAMAGE",colors=cpair(colors.red,colors.red_off)}
local _ = LED{parent=rps,label="HI TEMP",colors=cpair(colors.red,colors.red_off)}
rps.line_break()
local _ = LED{parent=rps,label="LO FUEL",colors=cpair(colors.red,colors.red_off)}
local _ = LED{parent=rps,label="HI WASTE",colors=cpair(colors.red,colors.red_off)}
rps.line_break()
local _ = LED{parent=rps,label="LO CCOOLANT",colors=cpair(colors.red,colors.red_off)}
local _ = LED{parent=rps,label="HI HCOOLANT",colors=cpair(colors.red,colors.red_off)}
ColorMap{parent=panel,x=1,y=19}
-- facility.ps.subscribe("sv_ping", ping.update)
-- facility.ps.subscribe("date_time", datetime.set_value)
return panel
end
return init

View File

@@ -0,0 +1,41 @@
--
-- Graphics Style Options
--
local core = require("graphics.core")
local style = {}
local cpair = core.graphics.cpair
-- GLOBAL --
-- remap global colors
colors.ivory = colors.pink
colors.red_off = colors.brown
colors.green_off = colors.lime
style.root = cpair(colors.black, colors.ivory)
style.header = cpair(colors.black, colors.lightGray)
style.label = cpair(colors.gray, colors.lightGray)
style.colors = {
{ c = colors.red, hex = 0xdf4949 }, -- RED ON
{ c = colors.orange, hex = 0xffb659 },
{ c = colors.yellow, hex = 0xe5e552 },
{ c = colors.lime, hex = 0x16665a }, -- GREEN OFF
{ c = colors.green, hex = 0x6be551 }, -- GREEN ON
{ c = colors.cyan, hex = 0x34bac8 },
{ c = colors.lightBlue, hex = 0x6cc0f2 },
{ c = colors.blue, hex = 0x0096ff },
{ c = colors.purple, hex = 0xb156ee },
{ c = colors.pink, hex = 0xdcd9ca }, -- IVORY
{ c = colors.magenta, hex = 0xf9488a },
-- { c = colors.white, hex = 0xdcd9ca },
{ c = colors.lightGray, hex = 0x999f9b },
{ c = colors.gray, hex = 0x575757 },
-- { c = colors.black, hex = 0x191919 },
{ c = colors.brown, hex = 0x672223 } -- RED OFF
}
return style

62
reactor-plc/renderer.lua Normal file
View File

@@ -0,0 +1,62 @@
--
-- Graphics Rendering Control
--
local style = require("reactor-plc.panel.style")
local panel_view = require("reactor-plc.panel.front_panel")
local renderer = {}
local ui = {
view = nil
}
-- start the UI
function renderer.start_ui()
if ui.view == nil then
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1, 1)
-- set overridden colors
for i = 1, #style.colors do
term.setPaletteColor(style.colors[i].c, style.colors[i].hex)
end
-- init front panel view
ui.view = panel_view(term.current())
end
end
-- close out the UI
function renderer.close_ui()
if ui.view ~= nil then
-- hide to stop animation callbacks
ui.view.hide()
end
-- clear root UI elements
ui.view = nil
-- restore colors
for i = 1, #style.colors do
local r, g, b = term.nativePaletteColor(style.colors[i].c)
term.setPaletteColor(style.colors[i].c, r, g, b)
end
term.clear()
end
-- is the UI ready?
---@nodiscard
---@return boolean ready
function renderer.ui_ready() return ui.view ~= nil end
-- handle a touch event
---@param event monitor_touch
function renderer.handle_touch(event)
ui.view.handle_touch(event)
end
return renderer

View File

@@ -8,13 +8,15 @@ local crash = require("scada-common.crash")
local log = require("scada-common.log")
local mqueue = require("scada-common.mqueue")
local ppm = require("scada-common.ppm")
local psil = require("scada-common.psil")
local util = require("scada-common.util")
local config = require("reactor-plc.config")
local plc = require("reactor-plc.plc")
local renderer = require("reactor-plc.renderer")
local threads = require("reactor-plc.threads")
local R_PLC_VERSION = "v1.0.0"
local R_PLC_VERSION = "v1.1.0"
local print = util.print
local println = util.println
@@ -106,7 +108,10 @@ local function main()
mq_rps = mqueue.new(),
mq_comms_tx = mqueue.new(),
mq_comms_rx = mqueue.new()
}
},
-- publisher/subscriber interface for front panel
fp_ps = psil.create()
}
local smem_dev = __shared_memory.plc_dev
@@ -148,6 +153,9 @@ local function main()
-- PLC init<br>
--- EVENT_CONSUMER: this function consumes events
local function init()
-- front panel time!
renderer.start_ui()
if plc_state.init_ok then
-- just booting up, no fission allowed (neutrons stay put thanks)
if plc_state.reactor_formed and smem_dev.reactor.getStatus() then
@@ -177,7 +185,7 @@ local function main()
println("init> completed")
log.info("init> startup completed")
else
println("init> system in degraded state, awaiting devices...")
-- println("init> system in degraded state, awaiting devices...")
log.warning("init> started in a degraded state, awaiting peripheral connections...")
end
end
@@ -217,6 +225,8 @@ local function main()
parallel.waitForAll(main_thread.p_exec, rps_thread.p_exec)
end
renderer.close_ui()
println_ts("exited")
log.info("exited")
end