refactoring and adjusted spinbox and hazard button elements

This commit is contained in:
Mikayla Fischler 2023-01-23 15:10:41 -05:00
parent 4145949ba7
commit 8abac3fdcb
9 changed files with 60 additions and 36 deletions

View File

@ -426,9 +426,9 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
if packet.length == 3 then if packet.length == 3 then
local cmd = packet.data[1] local cmd = packet.data[1]
local unit_id = packet.data[2] local unit_id = packet.data[2]
local ack = packet.data[3] local ack = packet.data[3] == true
local unit = iocontrol.get_db().units[unit_id] ---@type ioctl_entry local unit = iocontrol.get_db().units[unit_id] ---@type ioctl_unit
if unit ~= nil then if unit ~= nil then
if cmd == UNIT_COMMANDS.SCRAM then if cmd == UNIT_COMMANDS.SCRAM then
@ -444,14 +444,12 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
elseif cmd == UNIT_COMMANDS.ACK_ALL_ALARMS then elseif cmd == UNIT_COMMANDS.ACK_ALL_ALARMS then
unit.ack_alarms_ack(ack) unit.ack_alarms_ack(ack)
elseif cmd == UNIT_COMMANDS.SET_GROUP then elseif cmd == UNIT_COMMANDS.SET_GROUP then
process.sv_assign(unit_id, ack) ---@todo how is this going to be handled?
elseif cmd == UNIT_COMMANDS.SET_LIMIT then
process.sv_limit(unit_id, ack)
else else
log.debug(util.c("received command ack with unknown command ", cmd)) log.debug(util.c("received unit command ack with unknown command ", cmd))
end end
else else
log.debug(util.c("received command ack with unknown unit ", unit_id)) log.debug(util.c("received unit command ack with unknown unit ", unit_id))
end end
else else
log.debug("SCADA_CRDN unit command ack packet length mismatch") log.debug("SCADA_CRDN unit command ack packet length mismatch")

View File

@ -21,9 +21,7 @@ local io = {}
---@param comms coord_comms comms reference ---@param comms coord_comms comms reference
---@diagnostic disable-next-line: redefined-local ---@diagnostic disable-next-line: redefined-local
function iocontrol.init(conf, comms) function iocontrol.init(conf, comms)
-- pass IO control here since it can't be require'd due to a require loop ---@class ioctl_facility
process.init(io, comms)
io.facility = { io.facility = {
auto_active = false, auto_active = false,
scram = false, scram = false,
@ -50,7 +48,7 @@ function iocontrol.init(conf, comms)
local function ack(alarm) process.ack_alarm(i, alarm) end local function ack(alarm) process.ack_alarm(i, alarm) end
local function reset(alarm) process.reset_alarm(i, alarm) end local function reset(alarm) process.reset_alarm(i, alarm) end
---@class ioctl_entry ---@class ioctl_unit
local entry = { local entry = {
unit_id = i, ---@type integer unit_id = i, ---@type integer
@ -140,6 +138,9 @@ function iocontrol.init(conf, comms)
table.insert(io.units, entry) table.insert(io.units, entry)
end end
-- pass IO control here since it can't be require'd due to a require loop
process.init(io, comms)
end end
-- populate facility structure builds -- populate facility structure builds
@ -180,7 +181,7 @@ end
function iocontrol.record_unit_builds(builds) function iocontrol.record_unit_builds(builds)
-- note: if not all units and RTUs are connected, some will be nil -- note: if not all units and RTUs are connected, some will be nil
for id, build in pairs(builds) do for id, build in pairs(builds) do
local unit = io.units[id] ---@type ioctl_entry local unit = io.units[id] ---@type ioctl_unit
if type(build) ~= "table" then if type(build) ~= "table" then
log.error(util.c("corrupted unit builds provided, unit ", id, " not a table")) log.error(util.c("corrupted unit builds provided, unit ", id, " not a table"))
@ -330,7 +331,7 @@ function iocontrol.update_unit_statuses(statuses)
-- get all unit statuses -- get all unit statuses
for i = 1, #statuses do for i = 1, #statuses do
local log_header = util.c("iocontrol.update_unit_statuses[unit ", i, "]: ") local log_header = util.c("iocontrol.update_unit_statuses[unit ", i, "]: ")
local unit = io.units[i] ---@type ioctl_entry local unit = io.units[i] ---@type ioctl_unit
local status = statuses[i] local status = statuses[i]
if type(status) ~= "table" or #status ~= 6 then if type(status) ~= "table" or #status ~= 6 then

View File

@ -306,7 +306,7 @@ function sounder.eval(units)
if units ~= nil then if units ~= nil then
-- check all alarms for all units -- check all alarms for all units
for i = 1, #units do for i = 1, #units do
local unit = units[i] ---@type ioctl_entry local unit = units[i] ---@type ioctl_unit
for id = 1, #unit.alarms do for id = 1, #unit.alarms do
alarms[id] = alarms[id] or (unit.alarms[id] == ALARM_STATE.TRIPPED) alarms[id] = alarms[id] or (unit.alarms[id] == ALARM_STATE.TRIPPED)
end end

View File

@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol")
local renderer = require("coordinator.renderer") local renderer = require("coordinator.renderer")
local sounder = require("coordinator.sounder") local sounder = require("coordinator.sounder")
local COORDINATOR_VERSION = "beta-v0.8.8" local COORDINATOR_VERSION = "beta-v0.8.9"
local print = util.print local print = util.print
local println = util.println local println = util.println

View File

@ -38,7 +38,7 @@ local function new_view(root, x, y, data, ps, id)
local label_fg_bg = cpair(colors.gray, colors.lightGray) local label_fg_bg = cpair(colors.gray, colors.lightGray)
local lu_col = cpair(colors.gray, colors.gray) local lu_col = cpair(colors.gray, colors.gray)
local status = StateIndicator{parent=rect,x=11,y=1,states=style.imatrix.states,value=1,min_width=12} local status = StateIndicator{parent=rect,x=10,y=1,states=style.imatrix.states,value=1,min_width=14}
local energy = PowerIndicator{parent=rect,x=7,y=3,lu_colors=lu_col,label="Energy: ",format="%8.2f",value=0,width=26,fg_bg=text_fg_bg} local energy = PowerIndicator{parent=rect,x=7,y=3,lu_colors=lu_col,label="Energy: ",format="%8.2f",value=0,width=26,fg_bg=text_fg_bg}
local capacity = PowerIndicator{parent=rect,x=7,y=4,lu_colors=lu_col,label="Capacity:",format="%8.2f",value=0,width=26,fg_bg=text_fg_bg} local capacity = PowerIndicator{parent=rect,x=7,y=4,lu_colors=lu_col,label="Capacity:",format="%8.2f",value=0,width=26,fg_bg=text_fg_bg}
local input = PowerIndicator{parent=rect,x=7,y=5,lu_colors=lu_col,label="Input: ",format="%8.2f",rate=true,value=0,width=26,fg_bg=text_fg_bg} local input = PowerIndicator{parent=rect,x=7,y=5,lu_colors=lu_col,label="Input: ",format="%8.2f",rate=true,value=0,width=26,fg_bg=text_fg_bg}

View File

@ -59,7 +59,7 @@ local waste_opts = {
---@param parent graphics_element parent ---@param parent graphics_element parent
---@param id integer ---@param id integer
local function init(parent, id) local function init(parent, id)
local unit = iocontrol.get_db().units[id] ---@type ioctl_entry local unit = iocontrol.get_db().units[id] ---@type ioctl_unit
local r_ps = unit.reactor_ps local r_ps = unit.reactor_ps
local b_ps = unit.boiler_ps_tbl local b_ps = unit.boiler_ps_tbl
local t_ps = unit.turbine_ps_tbl local t_ps = unit.turbine_ps_tbl
@ -329,7 +329,7 @@ local function init(parent, id)
---------------------- ----------------------
local burn_control = Div{parent=main,x=12,y=28,width=19,height=3,fg_bg=cpair(colors.gray,colors.white)} local burn_control = Div{parent=main,x=12,y=28,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=bw_fg_bg} local burn_rate = SpinboxNumeric{parent=burn_control,x=2,y=1,whole_num_precision=4,fractional_precision=1,min=0.1,arrow_fg_bg=cpair(colors.gray,colors.white),fg_bg=bw_fg_bg}
TextBox{parent=burn_control,x=9,y=2,text="mB/t"} TextBox{parent=burn_control,x=9,y=2,text="mB/t"}
local set_burn = function () unit.set_burn(burn_rate.get_value()) end local set_burn = function () unit.set_burn(burn_rate.get_value()) end

View File

@ -24,7 +24,7 @@ local pipe = core.graphics.pipe
---@param parent graphics_element parent ---@param parent graphics_element parent
---@param x integer top left x ---@param x integer top left x
---@param y integer top left y ---@param y integer top left y
---@param unit ioctl_entry unit database entry ---@param unit ioctl_unit unit database entry
local function make(parent, x, y, unit) local function make(parent, x, y, unit)
local height = 0 local height = 0
local num_boilers = #unit.boiler_data_tbl local num_boilers = #unit.boiler_data_tbl

View File

@ -1,6 +1,7 @@
-- Hazard-bordered Button Graphics Element -- Hazard-bordered Button Graphics Element
local tcd = require("scada-common.tcallbackdsp") local tcd = require("scada-common.tcallbackdsp")
local util = require("scada-common.util")
local core = require("graphics.core") local core = require("graphics.core")
local element = require("graphics.element") local element = require("graphics.element")
@ -42,7 +43,7 @@ local function hazard_button(args)
e.window.setTextColor(accent) e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg) e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 1) e.window.setCursorPos(1, 1)
e.window.write("\x99\x89\x89\x89\x89\x89\x89\x89\x99") e.window.write("\x99" .. util.strrep("\x89", args.width - 2) .. "\x99")
-- center left -- center left
e.window.setCursorPos(1, 2) e.window.setCursorPos(1, 2)
@ -53,14 +54,14 @@ local function hazard_button(args)
-- center right -- center right
e.window.setTextColor(args.fg_bg.bkg) e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(accent) e.window.setBackgroundColor(accent)
e.window.setCursorPos(9, 2) e.window.setCursorPos(args.width, 2)
e.window.write("\x99") e.window.write("\x99")
-- bottom -- bottom
e.window.setTextColor(accent) e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg) e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 3) e.window.setCursorPos(1, 3)
e.window.write("\x99\x98\x98\x98\x98\x98\x98\x98\x99") e.window.write("\x99" .. util.strrep("\x98", args.width - 2) .. "\x99")
end end
-- on request timeout: recursively calls itself to double flash button text -- on request timeout: recursively calls itself to double flash button text

View File

@ -11,6 +11,7 @@ local element = require("graphics.element")
---@field whole_num_precision integer number of whole number digits ---@field whole_num_precision integer number of whole number digits
---@field fractional_precision integer number of fractional digits ---@field fractional_precision integer number of fractional digits
---@field arrow_fg_bg cpair arrow foreground/background colors ---@field arrow_fg_bg cpair arrow foreground/background colors
---@field arrow_disable? color color when disabled (default light gray)
---@field parent graphics_element ---@field parent graphics_element
---@field id? string element id ---@field id? string element id
---@field x? integer 1 if omitted ---@field x? integer 1 if omitted
@ -29,8 +30,17 @@ local function spinbox(args)
assert(util.is_int(wn_prec), "graphics.element.controls.spinbox_numeric: whole number precision must be an integer") assert(util.is_int(wn_prec), "graphics.element.controls.spinbox_numeric: whole number precision must be an integer")
assert(util.is_int(fr_prec), "graphics.element.controls.spinbox_numeric: fractional precision must be an integer") assert(util.is_int(fr_prec), "graphics.element.controls.spinbox_numeric: fractional precision must be an integer")
local fmt = "%" .. (wn_prec + fr_prec + 1) .. "." .. fr_prec .. "f" local fmt = ""
local fmt_init = "%0" .. (wn_prec + fr_prec + 1) .. "." .. fr_prec .. "f" local fmt_init = ""
if fr_prec > 0 then
fmt = "%" .. (wn_prec + fr_prec + 1) .. "." .. fr_prec .. "f"
fmt_init = "%0" .. (wn_prec + fr_prec + 1) .. "." .. fr_prec .. "f"
else
fmt = "%" .. wn_prec .. "d"
fmt_init = "%0" .. wn_prec .. "d"
end
local dec_point_x = args.whole_num_precision + 1 local dec_point_x = args.whole_num_precision + 1
assert(type(args.arrow_fg_bg) == "table", "graphics.element.spinbox_numeric: arrow_fg_bg is a required field") assert(type(args.arrow_fg_bg) == "table", "graphics.element.spinbox_numeric: arrow_fg_bg is a required field")
@ -43,11 +53,12 @@ local function spinbox(args)
local e = element.new(args) local e = element.new(args)
-- set initial value -- set initial value
e.value = args.default or 0.0 e.value = args.default or 0
-- draw the arrows -- draw the arrows
local function draw_arrows(color)
e.window.setBackgroundColor(args.arrow_fg_bg.bkg) e.window.setBackgroundColor(args.arrow_fg_bg.bkg)
e.window.setTextColor(args.arrow_fg_bg.fgd) e.window.setTextColor(color)
e.window.setCursorPos(1, 1) e.window.setCursorPos(1, 1)
e.window.write(util.strrep("\x1e", wn_prec)) e.window.write(util.strrep("\x1e", wn_prec))
e.window.setCursorPos(1, 3) e.window.setCursorPos(1, 3)
@ -58,6 +69,9 @@ local function spinbox(args)
e.window.setCursorPos(1 + wn_prec, 3) e.window.setCursorPos(1 + wn_prec, 3)
e.window.write(" " .. util.strrep("\x1f", fr_prec)) e.window.write(" " .. util.strrep("\x1f", fr_prec))
end end
end
draw_arrows(args.arrow_fg_bg.fgd)
-- populate digits from current value -- populate digits from current value
local function set_digits() local function set_digits()
@ -157,6 +171,16 @@ local function spinbox(args)
show_num() show_num()
end end
-- enable this input
function e.enable()
draw_arrows(args.arrow_fg_bg.fgd)
end
-- disable this input
function e.disable()
draw_arrows(args.arrow_disable or colors.lightGray)
end
-- default to zero, init digits table -- default to zero, init digits table
e.value = 0 e.value = 0
set_digits() set_digits()