From 826114e5bf0efc650d3b2e84d8dbbc552fd6f7a7 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Mon, 1 Aug 2022 13:05:39 -0300 Subject: [PATCH] #73 core map and bugfixes --- coordinator/startup.lua | 2 +- coordinator/ui/components/boiler.lua | 1 + coordinator/ui/components/reactor.lua | 1 + coordinator/ui/components/turbine.lua | 1 + coordinator/ui/layout/unit_view.lua | 50 ++++++++--- graphics/elements/colormap.lua | 33 +++++++ graphics/elements/indicators/coremap.lua | 106 +++++++++++++++++++++++ 7 files changed, 182 insertions(+), 12 deletions(-) create mode 100644 graphics/elements/colormap.lua create mode 100644 graphics/elements/indicators/coremap.lua diff --git a/coordinator/startup.lua b/coordinator/startup.lua index b817063..77b1514 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -16,7 +16,7 @@ local config = require("coordinator.config") local coordinator = require("coordinator.coordinator") local renderer = require("coordinator.renderer") -local COORDINATOR_VERSION = "alpha-v0.3.8" +local COORDINATOR_VERSION = "alpha-v0.3.9" local print = util.print local println = util.println diff --git a/coordinator/ui/components/boiler.lua b/coordinator/ui/components/boiler.lua index 8deace3..761366a 100644 --- a/coordinator/ui/components/boiler.lua +++ b/coordinator/ui/components/boiler.lua @@ -47,6 +47,7 @@ local function new_view(root, x, y, ps) ps.subscribe("steam", steam.update) ps.subscribe("ccool", ccool.update) + ---@fixme test code hcool.update(0.22) water.update(1) steam.update(0.05) diff --git a/coordinator/ui/components/reactor.lua b/coordinator/ui/components/reactor.lua index d7d35f5..e7cda02 100644 --- a/coordinator/ui/components/reactor.lua +++ b/coordinator/ui/components/reactor.lua @@ -50,6 +50,7 @@ local function new_view(root, x, y, ps) ps.subscribe("hcool", hcool.update) ps.subscribe("waste", waste.update) + ---@fixme test code fuel.update(1) ccool.update(0.85) hcool.update(0.08) diff --git a/coordinator/ui/components/turbine.lua b/coordinator/ui/components/turbine.lua index f1ffea0..7609e3c 100644 --- a/coordinator/ui/components/turbine.lua +++ b/coordinator/ui/components/turbine.lua @@ -36,6 +36,7 @@ local function new_view(root, x, y, ps) ps.subscribe("steam", steam.update) + ---@fixme test code steam.update(0.12) end diff --git a/coordinator/ui/layout/unit_view.lua b/coordinator/ui/layout/unit_view.lua index 839ef12..067a68a 100644 --- a/coordinator/ui/layout/unit_view.lua +++ b/coordinator/ui/layout/unit_view.lua @@ -10,8 +10,9 @@ local style = require("coordinator.ui.style") local DisplayBox = require("graphics.elements.displaybox") local Div = require("graphics.elements.div") local TextBox = require("graphics.elements.textbox") -local Tiling = require("graphics.elements.tiling") +local ColorMap = require("graphics.elements.colormap") +local CoreMap = require("graphics.elements.indicators.coremap") local DataIndicator = require("graphics.elements.indicators.data") local HorizontalBar = require("graphics.elements.indicators.hbar") local IndicatorLight = require("graphics.elements.indicators.light") @@ -31,18 +32,28 @@ local function init(monitor, id) TextBox{parent=main,text="Reactor Unit #" .. id,alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} - local reactor_width = 18 - local core_width = ((reactor_width - 2) * 2) + 4 - local core_height = reactor_width - local scram_fg_bg = core.graphics.cpair(colors.white, colors.gray) - local reactor_top_view = Tiling{parent=main,x=2,y=3,width=core_width,height=core_height,fill_c=cpair(colors.lightGray,colors.lightBlue),even=true,border_c=colors.gray} + ---@fixme test code + local t = 300 + if id == 1 then + t = 340 + elseif id == 2 then + t = 340 + elseif id == 3 then + t = 300 + elseif id == 4 then + t = 300 + end + + local core_view = CoreMap{parent=main,x=2,y=3} + core_view.update(t) + local core_shift = core_view.height() local f = function () print("scram!") end - local scram = SCRAMButton{parent=main,x=2,y=core_height+4,callback=f,fg_bg=scram_fg_bg} + local scram = SCRAMButton{parent=main,x=2,y=core_shift+4,callback=f,fg_bg=scram_fg_bg} - local burn_control = Div{parent=main,x=13,y=core_height+4,width=19,height=3,fg_bg=cpair(colors.gray,colors.white)} + local burn_control = Div{parent=main,x=13,y=core_shift+4,width=19,height=3,fg_bg=cpair(colors.gray,colors.white)} local burn_rate = SpinboxNumeric{parent=burn_control,x=2,y=1,whole_num_precision=4,fractional_precision=1,arrow_fg_bg=cpair(colors.gray,colors.white),fg_bg=cpair(colors.black,colors.white)} local set_burn = function () print("set burn to " .. burn_rate.get_value()) end @@ -50,7 +61,11 @@ local function init(monitor, id) TextBox{parent=burn_control,x=9,y=2,text="mB/t"} PushButton{parent=burn_control,x=14,y=2,text="SET",min_width=5,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=cpair(colors.white,colors.gray),callback=set_burn} - local annunciator = Div{parent=main,x=34,y=core_height+4} + ---@fixme test code + main.line_break() + ColorMap{parent=main} + + local annunciator = Div{parent=main,x=34,y=3} -- annunciator colors per IAEA-TECDOC-812 recommendations @@ -63,8 +78,8 @@ local function init(monitor, id) annunciator.line_break() -- annunciator fields - local r_trip = IndicatorLight{parent=annunciator,label="Reactor Trip",colors=cpair(colors.red,colors.gray)} - local r_mtrp = IndicatorLight{parent=annunciator,label="Manual Reactor Trip",colors=cpair(colors.red,colors.gray)} + local r_trip = IndicatorLight{parent=annunciator,label="Reactor SCRAM",colors=cpair(colors.red,colors.gray)} + local r_mtrp = IndicatorLight{parent=annunciator,label="Manual Reactor SCRAM",colors=cpair(colors.red,colors.gray)} local r_rtrp = IndicatorLight{parent=annunciator,label="RCP Trip",colors=cpair(colors.red,colors.gray)} local r_cflo = IndicatorLight{parent=annunciator,label="RCS Flow Low",colors=cpair(colors.yellow,colors.gray)} local r_temp = IndicatorLight{parent=annunciator,label="Reactor Temp. High",colors=cpair(colors.red,colors.gray)} @@ -86,6 +101,16 @@ local function init(monitor, id) local rps_flt = IndicatorLight{parent=annunciator,label="PPM Fault",colors=cpair(colors.yellow,colors.gray)} local rps_tmo = IndicatorLight{parent=annunciator,label="Timeout",colors=cpair(colors.yellow,colors.gray)} + annunciator.line_break() + + -- cooling + local c_brm = IndicatorLight{parent=annunciator,label="Boil Rate Mismatch",colors=cpair(colors.yellow,colors.gray)} + local c_cfm = IndicatorLight{parent=annunciator,label="Coolant Feed Mismatch",colors=cpair(colors.yellow,colors.gray)} + local c_sfm = IndicatorLight{parent=annunciator,label="Steam Feed Mismatch",colors=cpair(colors.yellow,colors.gray)} + local c_mwrf = IndicatorLight{parent=annunciator,label="Max Water Return Feed",colors=cpair(colors.yellow,colors.gray)} + local c_tbnt = IndicatorLight{parent=annunciator,label="Turbine Trip",colors=cpair(colors.red,colors.gray)} + + ---@fixme test code plc_hbeat.update(true) r_auto.update(true) r_trip.update(true) @@ -93,6 +118,7 @@ local function init(monitor, id) rps_trp.update(true) rps_nof.update(true) + ---@fixme test code local heartbeat = true local function _test_toggle() plc_hbeat.update(heartbeat) @@ -100,6 +126,7 @@ local function init(monitor, id) tcallbackdsp.dispatch(1, _test_toggle) end + ---@fixme test code local rps = true local function _test_toggle1() rps_nof.update(rps) @@ -107,6 +134,7 @@ local function init(monitor, id) tcallbackdsp.dispatch(0.25, _test_toggle1) end + ---@fixme test code tcallbackdsp.dispatch(1, _test_toggle) tcallbackdsp.dispatch(0.25, _test_toggle1) diff --git a/graphics/elements/colormap.lua b/graphics/elements/colormap.lua new file mode 100644 index 0000000..4c7ba94 --- /dev/null +++ b/graphics/elements/colormap.lua @@ -0,0 +1,33 @@ +-- Color Map Graphics Element + +local util = require("scada-common.util") + +local element = require("graphics.element") + +---@class colormap_args +---@field parent graphics_element +---@field id? string element id +---@field x? integer 1 if omitted +---@field y? integer 1 if omitted + +-- new color map +---@param args colormap_args +---@return graphics_element element, element_id id +local function colormap(args) + local bkg = "008877FFCCEE114455DD9933BBAA2266" + local spaces = util.spaces(32) + + args.width = 32 + args.height = 1 + + -- create new graphics element base object + local e = element.new(args) + + -- draw color map + e.window.setCursorPos(1, 1) + e.window.blit(spaces, bkg, bkg) + + return e.get() +end + +return colormap diff --git a/graphics/elements/indicators/coremap.lua b/graphics/elements/indicators/coremap.lua new file mode 100644 index 0000000..0f7d7f1 --- /dev/null +++ b/graphics/elements/indicators/coremap.lua @@ -0,0 +1,106 @@ +-- Reactor Core View Graphics Element + +local util = require("scada-common.util") + +local core = require("graphics.core") +local element = require("graphics.element") + +---@class core_map_args +---@field parent graphics_element +---@field id? string element id +---@field x? integer 1 if omitted +---@field y? integer 1 if omitted +---@field fg_bg? cpair foreground/background colors + +-- new core map box +---@param args core_map_args +---@return graphics_element element, element_id id +local function core_map(args) + args.width = 30 + args.height = 18 + + -- arbitrary foreground color, gray reactor frame background + args.fg_bg = core.graphics.cpair(colors.white, colors.gray) + + -- create new graphics element base object + local e = element.new(args) + + -- draw core map box + + local start_x = 2 + local start_y = 2 + + local inner_width = math.floor((e.frame.w - 2) / 2) + local inner_height = e.frame.h - 2 + local alternator = true + + -- check dimensions + assert(inner_width > 0, "graphics.elements.indicators.coremap: inner_width <= 0") + assert(inner_height > 0, "graphics.elements.indicators.coremap: inner_height <= 0") + assert(start_x <= inner_width, "graphics.elements.indicators.coremap: start_x > inner_width") + assert(start_y <= inner_height, "graphics.elements.indicators.coremap: start_y > inner_height") + + -- draw the core + local function draw(t) + local i = 1 + local back_c = "FF" + local text_c = "FF" + + -- determine fuel assembly coloring + if t <= 300 then + -- gray + back_c = "88" + elseif t <= 350 then + -- blue + back_c = "33" + elseif t < 600 then + -- green + back_c = "DD" + elseif t < 1000 then + -- yellow + back_c = "44" + elseif t < 1200 then + -- orange + back_c = "11" + elseif t < 1300 then + -- red + back_c = "EE" + text_c = "00" + else + -- pink + back_c = "22" + text_c = "00" + end + + -- draw pattern + for y = start_y, inner_height + (start_y - 1) do + e.window.setCursorPos(start_x, y) + for x = 1, inner_width do + local str = util.sprintf("%02X", i) + + if alternator then + i = i + 1 + e.window.blit(str, text_c, back_c) + else + e.window.blit(" ", "00", "00") + end + + alternator = not alternator + end + + if inner_width % 2 == 0 then alternator = not alternator end + end + end + + draw(300) + + -- on state change + ---@param temperature integer temperature in Kelvin + function e.on_update(temperature) + draw(temperature) + end + + return e.get() +end + +return core_map