#593 structure and graphics elements for the radiation monitor app

This commit is contained in:
Mikayla Fischler 2025-06-15 18:24:36 -04:00
parent 9e59883a84
commit e1ac42f5f8
2 changed files with 54 additions and 58 deletions

View File

@ -836,6 +836,9 @@ function iorx.record_radiation_data(data)
unit.radiation = mon.radiation unit.radiation = mon.radiation
end end
end end
unit.unit_ps.publish("radiation", unit.radiation)
unit.unit_ps.publish("radiation_monitors", textutils.serialize(unit.rad_monitors))
end end
-- facility radiation monitors -- facility radiation monitors
@ -852,6 +855,9 @@ function iorx.record_radiation_data(data)
fac.radiation = mon.radiation fac.radiation = mon.radiation
end end
end end
fac.ps.publish("radiation", fac.radiation)
fac.ps.publish("radiation_monitors", textutils.serialize(fac.rad_monitors))
end end
return function (io_obj) return function (io_obj)

View File

@ -2,30 +2,24 @@
-- Radiation Monitor App -- Radiation Monitor App
-- --
local types = require("scada-common.types")
local util = require("scada-common.util") local util = require("scada-common.util")
local iocontrol = require("pocket.iocontrol") local iocontrol = require("pocket.iocontrol")
local pocket = require("pocket.pocket") local pocket = require("pocket.pocket")
local process = require("pocket.process")
local style = require("pocket.ui.style") local style = require("pocket.ui.style")
local core = require("graphics.core") local core = require("graphics.core")
local Div = require("graphics.elements.Div") local Div = require("graphics.elements.Div")
local ListBox = require("graphics.elements.ListBox")
local MultiPane = require("graphics.elements.MultiPane") local MultiPane = require("graphics.elements.MultiPane")
local Rectangle = require("graphics.elements.Rectangle") local Rectangle = require("graphics.elements.Rectangle")
local TextBox = require("graphics.elements.TextBox") local TextBox = require("graphics.elements.TextBox")
local WaitingAnim = require("graphics.elements.animations.Waiting") local WaitingAnim = require("graphics.elements.animations.Waiting")
local HazardButton = require("graphics.elements.controls.HazardButton") local RadIndicator = require("graphics.elements.indicators.RadIndicator")
local RadioButton = require("graphics.elements.controls.RadioButton")
local NumberField = require("graphics.elements.form.NumberField")
local IconIndicator = require("graphics.elements.indicators.IconIndicator")
local ALIGN = core.ALIGN local ALIGN = core.ALIGN
local cpair = core.cpair local cpair = core.cpair
@ -34,19 +28,9 @@ local border = core.border
local APP_ID = pocket.APP_ID local APP_ID = pocket.APP_ID
local label_fg_bg = style.label local label_fg_bg = style.label
local lu_col = style.label_unit_pair
local text_fg = style.text_fg local text_fg = style.text_fg
local field_fg_bg = style.field
local field_dis_fg_bg = style.field_disable
local red_ind_s = style.icon_states.red_ind_s
local yel_ind_s = style.icon_states.yel_ind_s
local grn_ind_s = style.icon_states.grn_ind_s
local wht_ind_s = style.icon_states.wht_ind_s
local hzd_fg_bg = style.hzd_fg_bg
local dis_colors = cpair(colors.white, colors.lightGray)
-- new radiation monitor page view -- new radiation monitor page view
---@param root Container parent ---@param root Container parent
local function new_view(root) local function new_view(root)
@ -95,7 +79,7 @@ local function new_view(root)
for i = 1, db.facility.num_units do for i = 1, db.facility.num_units do
local u_pane = panes[i] local u_pane = panes[i]
local u_div = Div{parent=u_pane,x=2,width=main.get_width()-2} local u_div = Div{parent=u_pane}
local unit = db.units[i] local unit = db.units[i]
local u_ps = unit.unit_ps local u_ps = unit.unit_ps
@ -104,47 +88,33 @@ local function new_view(root)
TextBox{parent=u_div,y=1,text="Unit #"..i.." Monitors",alignment=ALIGN.CENTER} TextBox{parent=u_div,y=1,text="Unit #"..i.." Monitors",alignment=ALIGN.CENTER}
-- TextBox{parent=u_div,y=3,text="Auto Rate Limit",fg_bg=label_fg_bg} TextBox{parent=u_div,x=2,y=3,text="Max Radiation",fg_bg=style.label}
-- rate_limits[i] = NumberField{parent=u_div,x=1,y=4,width=16,default=0.01,min=0.01,max_frac_digits=2,max_chars=8,allow_decimal=true,align_right=true,fg_bg=field_fg_bg,dis_fg_bg=field_dis_fg_bg} local radiation = RadIndicator{parent=u_div,x=2,label="",format="%17.3f",lu_colors=lu_col,width=21}
-- TextBox{parent=u_div,x=18,y=4,text="mB/t",width=4,fg_bg=label_fg_bg} radiation.register(u_ps, "radiation", radiation.update)
-- rate_limits[i].register(unit.unit_ps, "max_burn", rate_limits[i].set_max) local mon_list = ListBox{parent=u_div,y=6,scroll_height=100,nav_fg_bg=cpair(colors.lightGray,colors.gray),nav_active=cpair(colors.white,colors.gray)}
-- rate_limits[i].register(unit.unit_ps, "burn_limit", rate_limits[i].set_value)
-- local ready = IconIndicator{parent=u_div,y=6,label="Auto Ready",states=grn_ind_s} -- local last_list = {}
-- local a_stb = IconIndicator{parent=u_div,label="Auto Standby",states=wht_ind_s} -- local new_list = {}
-- local degraded = IconIndicator{parent=u_div,label="Unit Degraded",states=red_ind_s}
-- ready.register(u_ps, "U_AutoReady", ready.update) mon_list.register(u_ps, "radiation", function ()
-- degraded.register(u_ps, "U_AutoDegraded", degraded.update) -- for k, _ in pairs(unit.rad_monitors) do
-- if last_list[k] then last_list[k] = nil end
-- end
-- -- update standby indicator -- re-create due to new items
-- a_stb.register(u_ps, "status", function (active) -- if util.table_len(last_list) > 0 then
-- a_stb.update(unit.annunciator.AutoControl and (not active)) mon_list.remove_all()
-- end)
-- a_stb.register(u_ps, "AutoControl", function (auto_active)
-- if auto_active then
-- a_stb.update(unit.reactor_data.mek_status.status == false)
-- else a_stb.update(false) end
-- end)
-- local function _set_group(value) process.set_group(i, value - 1) end for k, v in pairs(unit.rad_monitors) do
local mon_div = Div{parent=mon_list,height=4}
-- local group = RadioButton{parent=u_div,y=10,options=types.AUTO_GROUP_NAMES,callback=_set_group,radio_colors=cpair(colors.lightGray,colors.gray),select_color=colors.purple,dis_fg_bg=style.btn_disable} local mon_rect = Rectangle{parent=mon_div,height=5,x=2,width=20,border=border(1,colors.gray,true),thin=true,fg_bg=cpair(colors.black,colors.lightGray)}
TextBox{parent=mon_rect,text="Env. Detector "..k}
-- -- can't change group if auto is engaged regardless of if this unit is part of auto control local mon_rad = RadIndicator{parent=mon_rect,x=2,label="",format="%13.3f",value=v.radiation,lu_colors=cpair(colors.gray,colors.gray),width=18}
-- group.register(f_ps, "auto_active", function (auto_active) -- radiation.register(u_ps, "radiation", mon_rad.update)
-- if auto_active then group.disable() else group.enable() end end
-- end) -- end
end)
-- group.register(u_ps, "auto_group_id", function (gid) group.set_value(gid + 1) end)
-- TextBox{parent=u_div,y=16,text="Assigned Group",fg_bg=style.label}
-- local auto_grp = TextBox{parent=u_div,text="Manual",width=11,fg_bg=text_fg}
-- auto_grp.register(u_ps, "auto_group", auto_grp.set_value)
util.nop()
end end
--#endregion --#endregion
@ -157,20 +127,40 @@ local function new_view(root)
local stat_page = app.new_page(nil, db.facility.num_units + 1) local stat_page = app.new_page(nil, db.facility.num_units + 1)
stat_page.tasks = { update } stat_page.tasks = { update }
TextBox{parent=s_div,y=1,text="Radiation Monitors",alignment=ALIGN.CENTER} TextBox{parent=s_div,y=1,text=" Radiation Monitoring",alignment=ALIGN.CENTER}
TextBox{parent=s_div,y=3,text="Max Facility Rad.",fg_bg=style.label}
local s_f_rad = RadIndicator{parent=s_div,label="",format="%17.3f",lu_colors=lu_col,width=21}
s_f_rad.register(f_ps, "radiation", s_f_rad.update)
for i = 1, db.facility.num_units do
local unit = db.units[i]
local u_ps = unit.unit_ps
s_div.line_break()
TextBox{parent=s_div,text="Max Unit "..i.." Radiation",fg_bg=style.label}
local s_u_rad = RadIndicator{parent=s_div,label="",format="%17.3f",lu_colors=lu_col,width=21}
s_u_rad.register(u_ps, "radiation", s_u_rad.update)
end
--#endregion --#endregion
--#region overview page --#region overview page
local f_pane = panes[db.facility.num_units + 2] local f_pane = panes[db.facility.num_units + 2]
local f_div = Div{parent=f_pane,x=2,width=main.get_width()-2} local f_div = Div{parent=f_pane,width=main.get_width()}
local fac_page = app.new_page(nil, db.facility.num_units + 2) local fac_page = app.new_page(nil, db.facility.num_units + 2)
fac_page.tasks = { update } fac_page.tasks = { update }
TextBox{parent=f_div,y=1,text="Facility Monitors",alignment=ALIGN.CENTER} TextBox{parent=f_div,y=1,text="Facility Monitors",alignment=ALIGN.CENTER}
TextBox{parent=f_div,x=2,y=3,text="Max Radiation",fg_bg=style.label}
local f_rad = RadIndicator{parent=f_div,x=2,label="",format="%17.3f",lu_colors=lu_col,width=21}
f_rad.register(f_ps, "radiation", f_rad.update)
local f_mon_list = ListBox{parent=f_div,y=6,scroll_height=100,nav_fg_bg=cpair(colors.lightGray,colors.gray),nav_active=cpair(colors.white,colors.gray)}
--#endregion --#endregion
-- setup multipane -- setup multipane