mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#200 RPS view on pocket
This commit is contained in:
parent
6a8ed311f3
commit
7f009f9c86
@ -1,6 +1,7 @@
|
|||||||
-- Icon Indicator Graphics Element
|
-- Icon Indicator Graphics Element
|
||||||
|
|
||||||
local element = require("graphics.element")
|
local element = require("graphics.element")
|
||||||
|
local util = require("scada-common.util")
|
||||||
|
|
||||||
---@class icon_sym_color
|
---@class icon_sym_color
|
||||||
---@field color cpair
|
---@field color cpair
|
||||||
@ -9,7 +10,7 @@ local element = require("graphics.element")
|
|||||||
---@class icon_indicator_args
|
---@class icon_indicator_args
|
||||||
---@field label string indicator label
|
---@field label string indicator label
|
||||||
---@field states table state color and symbol table
|
---@field states table state color and symbol table
|
||||||
---@field value? integer default state, defaults to 1
|
---@field value? integer|boolean default state, defaults to 1 (true = 2, false = 1)
|
||||||
---@field min_label_width? integer label length if omitted
|
---@field min_label_width? integer label length if omitted
|
||||||
---@field parent graphics_element
|
---@field parent graphics_element
|
||||||
---@field id? string element id
|
---@field id? string element id
|
||||||
@ -33,6 +34,7 @@ local function icon(args)
|
|||||||
local e = element.new(args)
|
local e = element.new(args)
|
||||||
|
|
||||||
e.value = args.value or 1
|
e.value = args.value or 1
|
||||||
|
if e.value == true then e.value = 2 end
|
||||||
|
|
||||||
-- state blit strings
|
-- state blit strings
|
||||||
local state_blit_cmds = {}
|
local state_blit_cmds = {}
|
||||||
@ -47,8 +49,11 @@ local function icon(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- on state change
|
-- on state change
|
||||||
---@param new_state integer indicator state
|
---@param new_state integer|boolean indicator state
|
||||||
function e.on_update(new_state)
|
function e.on_update(new_state)
|
||||||
|
new_state = new_state or 1
|
||||||
|
if new_state == true then new_state = 2 end
|
||||||
|
|
||||||
local blit_cmd = state_blit_cmds[new_state]
|
local blit_cmd = state_blit_cmds[new_state]
|
||||||
e.value = new_state
|
e.value = new_state
|
||||||
e.w_set_cur(1, 1)
|
e.w_set_cur(1, 1)
|
||||||
@ -56,7 +61,7 @@ local function icon(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- set indicator state
|
-- set indicator state
|
||||||
---@param val integer indicator state
|
---@param val integer|boolean indicator state
|
||||||
function e.set_value(val) e.on_update(val) end
|
function e.set_value(val) e.on_update(val) end
|
||||||
|
|
||||||
-- element redraw
|
-- element redraw
|
||||||
|
@ -609,7 +609,7 @@ function iocontrol.record_unit_data(data)
|
|||||||
-- update RPS status
|
-- update RPS status
|
||||||
if unit.reactor_data.rps_tripped then
|
if unit.reactor_data.rps_tripped then
|
||||||
control_status = 2
|
control_status = 2
|
||||||
rps_status = util.trinary(unit.reactor_data.rps_trip_cause ~= "manual", 3, 2)
|
rps_status = util.trinary(unit.reactor_data.rps_trip_cause == "manual", 3, 2)
|
||||||
else rps_status = 4 end
|
else rps_status = 4 end
|
||||||
|
|
||||||
-- update reactor/control status
|
-- update reactor/control status
|
||||||
|
@ -38,7 +38,7 @@ local function init(main)
|
|||||||
local db = iocontrol.get_db()
|
local db = iocontrol.get_db()
|
||||||
|
|
||||||
-- window header message
|
-- window header message
|
||||||
TextBox{parent=main,y=1,text="DEV ALPHA APP S C ",alignment=ALIGN.LEFT,height=1,fg_bg=style.header}
|
TextBox{parent=main,y=1,text="WIP ALPHA APP S C ",alignment=ALIGN.LEFT,height=1,fg_bg=style.header}
|
||||||
local svr_conn = SignalBar{parent=main,y=1,x=22,compact=true,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.green,colors.gray)}
|
local svr_conn = SignalBar{parent=main,y=1,x=22,compact=true,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.green,colors.gray)}
|
||||||
local crd_conn = SignalBar{parent=main,y=1,x=26,compact=true,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.green,colors.gray)}
|
local crd_conn = SignalBar{parent=main,y=1,x=26,compact=true,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.green,colors.gray)}
|
||||||
|
|
||||||
|
@ -45,6 +45,16 @@ local mode_states = {
|
|||||||
{ color = cpair(colors.black, colors.purple), symbol = "A" }
|
{ color = cpair(colors.black, colors.purple), symbol = "A" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local red_ind_s = {
|
||||||
|
{ color = cpair(colors.black, colors.lightGray), symbol = "+" },
|
||||||
|
{ color = cpair(colors.black, colors.red), symbol = "-" }
|
||||||
|
}
|
||||||
|
|
||||||
|
local yel_ind_s = {
|
||||||
|
{ color = cpair(colors.black, colors.lightGray), symbol = "+" },
|
||||||
|
{ color = cpair(colors.black, colors.yellow), symbol = "-" }
|
||||||
|
}
|
||||||
|
|
||||||
-- new unit page view
|
-- new unit page view
|
||||||
---@param root graphics_element parent
|
---@param root graphics_element parent
|
||||||
local function new_view(root)
|
local function new_view(root)
|
||||||
@ -60,27 +70,28 @@ local function new_view(root)
|
|||||||
|
|
||||||
local btn_fg_bg = cpair(colors.yellow, colors.black)
|
local btn_fg_bg = cpair(colors.yellow, colors.black)
|
||||||
local btn_active = cpair(colors.white, colors.black)
|
local btn_active = cpair(colors.white, colors.black)
|
||||||
local label = cpair(colors.lightGray, colors.black)
|
|
||||||
|
local nav_links = {}
|
||||||
|
|
||||||
local function set_sidebar(id)
|
local function set_sidebar(id)
|
||||||
local unit = db.units[id] ---@type pioctl_unit
|
-- local unit = db.units[id] ---@type pioctl_unit
|
||||||
|
|
||||||
local list = {
|
local list = {
|
||||||
{ label = " # ", tall = true, color = core.cpair(colors.black, colors.green), callback = function () db.nav.open_app(iocontrol.APP_ID.ROOT) end },
|
{ label = " # ", tall = true, color = core.cpair(colors.black, colors.green), callback = function () db.nav.open_app(iocontrol.APP_ID.ROOT) end },
|
||||||
{ label = "U-" .. id, color = core.cpair(colors.black, colors.yellow) },
|
{ label = "U-" .. id, color = core.cpair(colors.black, colors.yellow), callback = function () app.switcher(id) end },
|
||||||
{ label = " \x13 ", color = core.cpair(colors.black, colors.red), callback = function () end },
|
{ label = " \x13 ", color = core.cpair(colors.black, colors.red), callback = function () end },
|
||||||
{ label = " R ", tall = true, color = core.cpair(colors.black, colors.lightGray), callback = function () end },
|
{ label = "RPS", tall = true, color = core.cpair(colors.black, colors.cyan), callback = nav_links[id].rps },
|
||||||
{ label = "RPS", color = core.cpair(colors.black, colors.cyan), callback = function () end },
|
-- { label = " R ", color = core.cpair(colors.black, colors.lightGray), callback = function () end },
|
||||||
{ label = "RCS", tall = true, color = core.cpair(colors.black, colors.blue), callback = function () end },
|
{ label = "RCS", tall = true, color = core.cpair(colors.black, colors.blue), callback = function () end },
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 1, unit.num_boilers do
|
-- for i = 1, unit.num_boilers do
|
||||||
table.insert(list, { label = "B-" .. i, color = core.cpair(colors.black, colors.lightBlue), callback = function () end })
|
-- table.insert(list, { label = "B-" .. i, color = core.cpair(colors.black, colors.lightBlue), callback = function () end })
|
||||||
end
|
-- end
|
||||||
|
|
||||||
for i = 1, unit.num_turbines do
|
-- for i = 1, unit.num_turbines do
|
||||||
table.insert(list, { label = "T-" .. i, color = core.cpair(colors.black, colors.white), callback = function () end })
|
-- table.insert(list, { label = "T-" .. i, color = core.cpair(colors.black, colors.white), callback = function () end })
|
||||||
end
|
-- end
|
||||||
|
|
||||||
app.set_sidebar(list)
|
app.set_sidebar(list)
|
||||||
end
|
end
|
||||||
@ -88,25 +99,25 @@ local function new_view(root)
|
|||||||
local function load()
|
local function load()
|
||||||
local page_div = Div{parent=main,x=2,y=2,width=main.get_width()-2}
|
local page_div = Div{parent=main,x=2,y=2,width=main.get_width()-2}
|
||||||
|
|
||||||
local u_pages = {}
|
local panes = {}
|
||||||
|
|
||||||
local active_unit = 1
|
local active_unit = 1
|
||||||
set_sidebar(active_unit)
|
|
||||||
|
|
||||||
|
-- create all page divs
|
||||||
for _ = 1, db.facility.num_units do
|
for _ = 1, db.facility.num_units do
|
||||||
local div = Div{parent=page_div}
|
local div = Div{parent=page_div}
|
||||||
table.insert(u_pages, div)
|
table.insert(panes, div)
|
||||||
|
table.insert(nav_links, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
local u_pane = MultiPane{parent=page_div,x=1,y=1,panes=u_pages}
|
-- previous unit
|
||||||
app.set_root_pane(u_pane)
|
|
||||||
|
|
||||||
local function prev(x)
|
local function prev(x)
|
||||||
active_unit = util.trinary(x == 1, db.facility.num_units, x - 1)
|
active_unit = util.trinary(x == 1, db.facility.num_units, x - 1)
|
||||||
app.switcher(active_unit)
|
app.switcher(active_unit)
|
||||||
set_sidebar(active_unit)
|
set_sidebar(active_unit)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- next unit
|
||||||
local function next(x)
|
local function next(x)
|
||||||
active_unit = util.trinary(x == db.facility.num_units, 1, x + 1)
|
active_unit = util.trinary(x == db.facility.num_units, 1, x + 1)
|
||||||
app.switcher(active_unit)
|
app.switcher(active_unit)
|
||||||
@ -114,9 +125,11 @@ local function new_view(root)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, db.facility.num_units do
|
for i = 1, db.facility.num_units do
|
||||||
local u_div = u_pages[i] ---@type graphics_element
|
local u_div = panes[i] ---@type graphics_element
|
||||||
local unit = db.units[i] ---@type pioctl_unit
|
local unit = db.units[i] ---@type pioctl_unit
|
||||||
|
local u_ps = unit.unit_ps
|
||||||
|
|
||||||
|
-- refresh data callback, every 500ms it will re-send the query
|
||||||
local last_update = 0
|
local last_update = 0
|
||||||
local function update()
|
local function update()
|
||||||
if util.time_ms() - last_update >= 500 then
|
if util.time_ms() - last_update >= 500 then
|
||||||
@ -125,7 +138,10 @@ local function new_view(root)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
app.new_page(nil, i).tasks = { update }
|
-- Main Unit Overview
|
||||||
|
|
||||||
|
local u_page = app.new_page(nil, i)
|
||||||
|
u_page.tasks = { update }
|
||||||
|
|
||||||
TextBox{parent=u_div,y=1,text="Reactor Unit #"..i,height=1,alignment=ALIGN.CENTER}
|
TextBox{parent=u_div,y=1,text="Reactor Unit #"..i,height=1,alignment=ALIGN.CENTER}
|
||||||
PushButton{parent=u_div,x=1,y=1,text="<",fg_bg=btn_fg_bg,active_fg_bg=btn_active,callback=function()prev(i)end}
|
PushButton{parent=u_div,x=1,y=1,text="<",fg_bg=btn_fg_bg,active_fg_bg=btn_active,callback=function()prev(i)end}
|
||||||
@ -142,17 +158,17 @@ local function new_view(root)
|
|||||||
|
|
||||||
local ctrl = IconIndicator{parent=u_div,x=1,y=8,label="Control State",states=mode_states}
|
local ctrl = IconIndicator{parent=u_div,x=1,y=8,label="Control State",states=mode_states}
|
||||||
|
|
||||||
rate.register(unit.unit_ps, "act_burn_rate", rate.update)
|
rate.register(u_ps, "act_burn_rate", rate.update)
|
||||||
temp.register(unit.unit_ps, "temp", temp.update)
|
temp.register(u_ps, "temp", temp.update)
|
||||||
ctrl.register(unit.unit_ps, "U_ControlStatus", ctrl.update)
|
ctrl.register(u_ps, "U_ControlStatus", ctrl.update)
|
||||||
|
|
||||||
u_div.line_break()
|
u_div.line_break()
|
||||||
|
|
||||||
local rct = IconIndicator{parent=u_div,x=1,label="Fission Reactor",states=basic_states}
|
local rct = IconIndicator{parent=u_div,x=1,label="Fission Reactor",states=basic_states}
|
||||||
local rps = IconIndicator{parent=u_div,x=1,label="Protection System",states=basic_states}
|
local rps = IconIndicator{parent=u_div,x=1,label="Protection System",states=basic_states}
|
||||||
|
|
||||||
rct.register(unit.unit_ps, "U_ReactorStatus", rct.update)
|
rct.register(u_ps, "U_ReactorStatus", rct.update)
|
||||||
rps.register(unit.unit_ps, "U_RPS", rps.update)
|
rps.register(u_ps, "U_RPS", rps.update)
|
||||||
|
|
||||||
u_div.line_break()
|
u_div.line_break()
|
||||||
|
|
||||||
@ -167,7 +183,55 @@ local function new_view(root)
|
|||||||
local tbn = IconIndicator{parent=u_div,x=1,label="Turbine "..t,states=basic_states}
|
local tbn = IconIndicator{parent=u_div,x=1,label="Turbine "..t,states=basic_states}
|
||||||
tbn.register(unit.turbine_ps_tbl[t], "TurbineStatus", tbn.update)
|
tbn.register(unit.turbine_ps_tbl[t], "TurbineStatus", tbn.update)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- RPS Tab
|
||||||
|
|
||||||
|
local rps_div = Div{parent=page_div}
|
||||||
|
table.insert(panes, rps_div)
|
||||||
|
|
||||||
|
TextBox{parent=rps_div,y=1,text="Protection System",height=1,alignment=ALIGN.CENTER}
|
||||||
|
|
||||||
|
local r_trip = IconIndicator{parent=rps_div,x=1,y=3,label="RPS Trip",states=basic_states}
|
||||||
|
r_trip.register(u_ps, "U_RPS", r_trip.update)
|
||||||
|
|
||||||
|
local r_mscrm = IconIndicator{parent=rps_div,x=1,y=5,label="Manual SCRAM",states=red_ind_s}
|
||||||
|
local r_ascrm = IconIndicator{parent=rps_div,x=1,label="Automatic SCRAM",states=red_ind_s}
|
||||||
|
local rps_tmo = IconIndicator{parent=rps_div,x=1,label="Timeout",states=yel_ind_s}
|
||||||
|
local rps_flt = IconIndicator{parent=rps_div,x=1,label="PLC Fault",states=yel_ind_s}
|
||||||
|
local rps_sfl = IconIndicator{parent=rps_div,x=1,label="RCT Fault",states=red_ind_s}
|
||||||
|
|
||||||
|
r_mscrm.register(u_ps, "manual", r_mscrm.update)
|
||||||
|
r_ascrm.register(u_ps, "automatic", r_ascrm.update)
|
||||||
|
rps_tmo.register(u_ps, "timeout", rps_tmo.update)
|
||||||
|
rps_flt.register(u_ps, "fault", rps_flt.update)
|
||||||
|
rps_sfl.register(u_ps, "sys_fail", rps_sfl.update)
|
||||||
|
|
||||||
|
rps_div.line_break()
|
||||||
|
local rps_dmg = IconIndicator{parent=rps_div,x=1,label="High Damage",states=red_ind_s}
|
||||||
|
local rps_tmp = IconIndicator{parent=rps_div,x=1,label="High Temperature",states=red_ind_s}
|
||||||
|
local rps_nof = IconIndicator{parent=rps_div,x=1,label="Low Fuel",states=yel_ind_s}
|
||||||
|
local rps_exw = IconIndicator{parent=rps_div,x=1,label="High Waste",states=yel_ind_s}
|
||||||
|
local rps_loc = IconIndicator{parent=rps_div,x=1,label="Low Coolant",states=yel_ind_s}
|
||||||
|
local rps_exh = IconIndicator{parent=rps_div,x=1,label="High Hot Coolant",states=yel_ind_s}
|
||||||
|
|
||||||
|
rps_dmg.register(u_ps, "high_dmg", rps_dmg.update)
|
||||||
|
rps_tmp.register(u_ps, "high_temp", rps_tmp.update)
|
||||||
|
rps_nof.register(u_ps, "no_fuel", rps_nof.update)
|
||||||
|
rps_exw.register(u_ps, "ex_waste", rps_exw.update)
|
||||||
|
rps_loc.register(u_ps, "low_cool", rps_loc.update)
|
||||||
|
rps_exh.register(u_ps, "ex_hcool", rps_exh.update)
|
||||||
|
|
||||||
|
local rps_page = app.new_page(u_page, #panes)
|
||||||
|
rps_page.tasks = { update }
|
||||||
|
|
||||||
|
nav_links[i].rps = rps_page.nav_to
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- setup multipane
|
||||||
|
local u_pane = MultiPane{parent=page_div,x=1,y=1,panes=panes}
|
||||||
|
app.set_root_pane(u_pane)
|
||||||
|
|
||||||
|
set_sidebar(active_unit)
|
||||||
end
|
end
|
||||||
|
|
||||||
app.set_on_load(load)
|
app.set_on_load(load)
|
||||||
|
Loading…
Reference in New Issue
Block a user