cc-mek-scada/coordinator/ui/layout/front_panel.lua

161 lines
5.4 KiB
Lua
Raw Normal View History

2023-07-10 03:31:56 +00:00
--
-- Coordinator Front Panel GUI
--
local types = require("scada-common.types")
local util = require("scada-common.util")
2023-07-10 03:31:56 +00:00
local iocontrol = require("coordinator.iocontrol")
2023-07-10 03:31:56 +00:00
local pgi = require("coordinator.ui.pgi")
local style = require("coordinator.ui.style")
2023-07-10 03:31:56 +00:00
local pkt_entry = require("coordinator.ui.components.pkt_entry")
2023-07-10 03:31:56 +00:00
local core = require("graphics.core")
2023-07-10 03:31:56 +00:00
local Div = require("graphics.elements.div")
local ListBox = require("graphics.elements.listbox")
local MultiPane = require("graphics.elements.multipane")
local TextBox = require("graphics.elements.textbox")
2023-07-10 03:31:56 +00:00
local TabBar = require("graphics.elements.controls.tabbar")
2023-07-10 03:31:56 +00:00
local LED = require("graphics.elements.indicators.led")
local LEDPair = require("graphics.elements.indicators.ledpair")
local RGBLED = require("graphics.elements.indicators.ledrgb")
2023-07-10 03:31:56 +00:00
2024-03-12 03:31:31 +00:00
local LINK_STATE = types.PANEL_LINK_STATE
2023-10-04 03:16:46 +00:00
local ALIGN = core.ALIGN
2023-07-10 03:31:56 +00:00
local cpair = core.cpair
local led_grn = style.led_grn
2023-07-10 03:31:56 +00:00
-- create new front panel view
---@param panel graphics_element main displaybox
---@param num_units integer number of units (number of unit monitors)
2024-03-12 16:24:32 +00:00
local function init(panel, num_units)
2023-07-10 03:31:56 +00:00
local ps = iocontrol.get_db().fp.ps
TextBox{parent=panel,y=1,text="SCADA COORDINATOR",alignment=ALIGN.CENTER,height=1,fg_bg=style.fp_theme.header}
2023-07-10 03:31:56 +00:00
local page_div = Div{parent=panel,x=1,y=3}
--
-- system indicators
--
local main_page = Div{parent=page_div,x=1,y=1}
local system = Div{parent=main_page,width=14,height=17,x=2,y=2}
local status = LED{parent=system,label="STATUS",colors=cpair(colors.green,colors.red)}
local heartbeat = LED{parent=system,label="HEARTBEAT",colors=led_grn}
2023-07-10 03:31:56 +00:00
status.update(true)
system.line_break()
heartbeat.register(ps, "heartbeat", heartbeat.update)
local modem = LED{parent=system,label="MODEM",colors=led_grn}
2024-03-12 03:31:31 +00:00
2024-03-12 16:24:32 +00:00
if not style.colorblind then
2024-03-12 03:31:31 +00:00
local network = RGBLED{parent=system,label="NETWORK",colors={colors.green,colors.red,colors.orange,colors.yellow,colors.gray}}
network.update(types.PANEL_LINK_STATE.DISCONNECTED)
network.register(ps, "link_state", network.update)
else
local nt_lnk = LEDPair{parent=system,label="NT LINKED",off=colors.red_off,c1=colors.red,c2=colors.green}
local nt_ver = LEDPair{parent=system,label="NT VERSION",off=colors.red_off,c1=colors.red,c2=colors.green}
2024-03-12 03:31:31 +00:00
nt_lnk.register(ps, "link_state", function (state)
local value = 2
if state == LINK_STATE.DISCONNECTED then
value = 1
elseif state == LINK_STATE.LINKED then
value = 3
end
nt_lnk.update(value)
end)
nt_ver.register(ps, "link_state", function (state)
local value = 3
if state == LINK_STATE.BAD_VERSION then
value = 2
elseif state == LINK_STATE.DISCONNECTED then
value = 1
end
nt_ver.update(value)
end)
end
2023-07-10 03:31:56 +00:00
system.line_break()
modem.register(ps, "has_modem", modem.update)
local speaker = LED{parent=system,label="SPEAKER",colors=led_grn}
2023-07-10 03:31:56 +00:00
speaker.register(ps, "has_speaker", speaker.update)
---@diagnostic disable-next-line: undefined-field
local comp_id = util.sprintf("(%d)", os.getComputerID())
TextBox{parent=system,x=9,y=4,width=6,height=1,text=comp_id,fg_bg=style.fp.disabled_fg}
2023-07-10 03:31:56 +00:00
local monitors = Div{parent=main_page,width=16,height=17,x=18,y=2}
local main_monitor = LED{parent=monitors,label="MAIN MONITOR",colors=led_grn}
main_monitor.register(ps, "main_monitor", main_monitor.update)
local flow_monitor = LED{parent=monitors,label="FLOW MONITOR",colors=led_grn}
flow_monitor.register(ps, "flow_monitor", flow_monitor.update)
monitors.line_break()
for i = 1, num_units do
local unit_monitor = LED{parent=monitors,label="UNIT "..i.." MONITOR",colors=led_grn}
unit_monitor.register(ps, "unit_monitor_" .. i, unit_monitor.update)
end
2023-07-10 03:31:56 +00:00
--
-- about footer
--
local about = Div{parent=main_page,width=15,height=3,x=1,y=16,fg_bg=style.fp.disabled_fg}
2023-10-04 03:16:46 +00:00
local fw_v = TextBox{parent=about,x=1,y=1,text="FW: v00.00.00",alignment=ALIGN.LEFT,height=1}
local comms_v = TextBox{parent=about,x=1,y=2,text="NT: v00.00.00",alignment=ALIGN.LEFT,height=1}
2023-07-10 03:31:56 +00:00
fw_v.register(ps, "version", function (version) fw_v.set_value(util.c("FW: ", version)) end)
comms_v.register(ps, "comms_version", function (version) comms_v.set_value(util.c("NT: v", version)) end)
--
-- page handling
--
-- API page
local api_page = Div{parent=page_div,x=1,y=1,hidden=true}
local api_list = ListBox{parent=api_page,x=1,y=1,height=17,width=51,scroll_height=1000,fg_bg=style.fp.text_fg,nav_fg_bg=cpair(colors.gray,colors.lightGray),nav_active=cpair(colors.black,colors.gray)}
2023-07-10 03:31:56 +00:00
local _ = Div{parent=api_list,height=1,hidden=true} -- padding
-- assemble page panes
local panes = { main_page, api_page }
local page_pane = MultiPane{parent=page_div,x=1,y=1,panes=panes}
local tabs = {
{ name = "CRD", color = style.fp.text },
{ name = "API", color = style.fp.text },
2023-07-10 03:31:56 +00:00
}
TabBar{parent=panel,y=2,tabs=tabs,min_width=9,callback=page_pane.set_value,fg_bg=style.fp_theme.highlight_box_bright}
2023-07-10 03:31:56 +00:00
-- link pocket API list management to PGI
pgi.link_elements(api_list, pkt_entry)
end
return init