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
local cmd = packet.data[1]
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 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
unit.ack_alarms_ack(ack)
elseif cmd == UNIT_COMMANDS.SET_GROUP then
process.sv_assign(unit_id, ack)
elseif cmd == UNIT_COMMANDS.SET_LIMIT then
process.sv_limit(unit_id, ack)
---@todo how is this going to be handled?
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
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
else
log.debug("SCADA_CRDN unit command ack packet length mismatch")

View File

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

View File

@ -306,7 +306,7 @@ function sounder.eval(units)
if units ~= nil then
-- check all alarms for all units
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
alarms[id] = alarms[id] or (unit.alarms[id] == ALARM_STATE.TRIPPED)
end

View File

@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol")
local renderer = require("coordinator.renderer")
local sounder = require("coordinator.sounder")
local COORDINATOR_VERSION = "beta-v0.8.8"
local COORDINATOR_VERSION = "beta-v0.8.9"
local print = util.print
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 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 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}

View File

@ -59,7 +59,7 @@ local waste_opts = {
---@param parent graphics_element parent
---@param id integer
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 b_ps = unit.boiler_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_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"}
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 x integer top left x
---@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 height = 0
local num_boilers = #unit.boiler_data_tbl

View File

@ -1,6 +1,7 @@
-- Hazard-bordered Button Graphics Element
local tcd = require("scada-common.tcallbackdsp")
local util = require("scada-common.util")
local core = require("graphics.core")
local element = require("graphics.element")
@ -42,7 +43,7 @@ local function hazard_button(args)
e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg)
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
e.window.setCursorPos(1, 2)
@ -53,14 +54,14 @@ local function hazard_button(args)
-- center right
e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(accent)
e.window.setCursorPos(9, 2)
e.window.setCursorPos(args.width, 2)
e.window.write("\x99")
-- bottom
e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg)
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
-- 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 fractional_precision integer number of fractional digits
---@field arrow_fg_bg cpair arrow foreground/background colors
---@field arrow_disable? color color when disabled (default light gray)
---@field parent graphics_element
---@field id? string element id
---@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(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_init = "%0" .. (wn_prec + fr_prec + 1) .. "." .. fr_prec .. "f"
local fmt = ""
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
assert(type(args.arrow_fg_bg) == "table", "graphics.element.spinbox_numeric: arrow_fg_bg is a required field")
@ -43,22 +53,26 @@ local function spinbox(args)
local e = element.new(args)
-- set initial value
e.value = args.default or 0.0
e.value = args.default or 0
-- draw the arrows
e.window.setBackgroundColor(args.arrow_fg_bg.bkg)
e.window.setTextColor(args.arrow_fg_bg.fgd)
e.window.setCursorPos(1, 1)
e.window.write(util.strrep("\x1e", wn_prec))
e.window.setCursorPos(1, 3)
e.window.write(util.strrep("\x1f", wn_prec))
if fr_prec > 0 then
e.window.setCursorPos(1 + wn_prec, 1)
e.window.write(" " .. util.strrep("\x1e", fr_prec))
e.window.setCursorPos(1 + wn_prec, 3)
e.window.write(" " .. util.strrep("\x1f", fr_prec))
local function draw_arrows(color)
e.window.setBackgroundColor(args.arrow_fg_bg.bkg)
e.window.setTextColor(color)
e.window.setCursorPos(1, 1)
e.window.write(util.strrep("\x1e", wn_prec))
e.window.setCursorPos(1, 3)
e.window.write(util.strrep("\x1f", wn_prec))
if fr_prec > 0 then
e.window.setCursorPos(1 + wn_prec, 1)
e.window.write(" " .. util.strrep("\x1e", fr_prec))
e.window.setCursorPos(1 + wn_prec, 3)
e.window.write(" " .. util.strrep("\x1f", fr_prec))
end
end
draw_arrows(args.arrow_fg_bg.fgd)
-- populate digits from current value
local function set_digits()
local initial_str = util.sprintf(fmt_init, e.value)
@ -157,6 +171,16 @@ local function spinbox(args)
show_num()
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
e.value = 0
set_digits()