Skip to content

Commit

Permalink
Merge pull request #501 from MikaylaFischler/devel
Browse files Browse the repository at this point in the history
2024.06.15 Release
  • Loading branch information
MikaylaFischler authored Jun 15, 2024
2 parents b96eb7d + f64db66 commit 006c5e6
Show file tree
Hide file tree
Showing 35 changed files with 2,240 additions and 574 deletions.
5 changes: 3 additions & 2 deletions coordinator/configure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local log = require("scada-common.log")
local network = require("scada-common.network")
local ppm = require("scada-common.ppm")
local tcd = require("scada-common.tcd")
local types = require("scada-common.types")
local util = require("scada-common.util")
local themes = require("graphics.themes")

Expand Down Expand Up @@ -756,7 +757,7 @@ local function config_view(display)
local clock_fmt = RadioButton{parent=crd_c_1,x=1,y=5,default=util.trinary(ini_cfg.Time24Hour,1,2),options={"24-Hour","12-Hour"},callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.lime}

TextBox{parent=crd_c_1,x=1,y=8,height=1,text="Temperature Scale"}
local temp_scale = RadioButton{parent=crd_c_1,x=1,y=9,default=ini_cfg.TempScale,options={"Kelvin","Celsius","Fahrenheit","Rankine"},callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.lime}
local temp_scale = RadioButton{parent=crd_c_1,x=1,y=9,default=ini_cfg.TempScale,options=types.TEMP_SCALE_NAMES,callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.lime}

local function submit_ui_opts()
tmp_cfg.Time24Hour = clock_fmt.get_value() == 1
Expand Down Expand Up @@ -1356,7 +1357,7 @@ local function config_view(display)
if f[1] == "AuthKey" then val = string.rep("*", string.len(val))
elseif f[1] == "LogMode" then val = util.trinary(raw == log.MODE.APPEND, "append", "replace")
elseif f[1] == "TempScale" then
if raw == 1 then val = "Kelvin" elseif raw == 2 then val = "Celsius" elseif raw == 3 then val = "Fahrenheit" elseif raw == 4 then val = "Rankine" end
val = types.TEMP_SCALE_NAMES[raw]
elseif f[1] == "MainTheme" then
val = util.strval(themes.ui_theme_name(raw))
elseif f[1] == "FrontPanelTheme" then
Expand Down
22 changes: 14 additions & 8 deletions coordinator/iocontrol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ local pgi = require("coordinator.ui.pgi")

local ALARM_STATE = types.ALARM_STATE
local PROCESS = types.PROCESS
local TEMP_SCALE = types.TEMP_SCALE
local TEMP_UNITS = types.TEMP_SCALE_UNITS

-- nominal RTT is ping (0ms to 10ms usually) + 500ms for CRD main loop tick
local WARN_RTT = 1000 -- 2x as long as expected w/ 0 ping
Expand Down Expand Up @@ -47,17 +49,16 @@ end
-- initialize the coordinator IO controller
---@param conf facility_conf configuration
---@param comms coord_comms comms reference
---@param temp_scale integer temperature unit (1 = K, 2 = C, 3 = F, 4 = R)
---@param temp_scale TEMP_SCALE temperature unit
function iocontrol.init(conf, comms, temp_scale)
io.temp_label = TEMP_UNITS[temp_scale]

-- temperature unit label and conversion function (from Kelvin)
if temp_scale == 2 then
io.temp_label = "\xb0C"
if temp_scale == TEMP_SCALE.CELSIUS then
io.temp_convert = function (t) return t - 273.15 end
elseif temp_scale == 3 then
io.temp_label = "\xb0F"
elseif temp_scale == TEMP_SCALE.FAHRENHEIT then
io.temp_convert = function (t) return (1.8 * (t - 273.15)) + 32 end
elseif temp_scale == 4 then
io.temp_label = "\xb0R"
elseif temp_scale == TEMP_SCALE.RANKINE then
io.temp_convert = function (t) return 1.8 * t end
else
io.temp_label = "K"
Expand Down Expand Up @@ -247,6 +248,9 @@ function iocontrol.init(conf, comms, temp_scale)
waste_mode = types.WASTE_MODE.MANUAL_PLUTONIUM,
waste_product = types.WASTE_PRODUCT.PLUTONIUM,

last_rate_change_ms = 0,
turbine_flow_stable = false,

-- auto control group
a_group = 0,

Expand Down Expand Up @@ -1214,9 +1218,11 @@ function iocontrol.update_unit_statuses(statuses)
local unit_state = status[5]

if type(unit_state) == "table" then
if #unit_state == 6 then
if #unit_state == 8 then
unit.waste_mode = unit_state[5]
unit.waste_product = unit_state[6]
unit.last_rate_change_ms = unit_state[7]
unit.turbine_flow_stable = unit_state[8]

unit.unit_ps.publish("U_StatusLine1", unit_state[1])
unit.unit_ps.publish("U_StatusLine2", unit_state[2])
Expand Down
4 changes: 3 additions & 1 deletion coordinator/session/pocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ function pocket.new_session(id, s_addr, in_queue, out_queue, timeout)
u.reactor_data,
u.boiler_data_tbl,
u.turbine_data_tbl,
u.tank_data_tbl
u.tank_data_tbl,
u.last_rate_change_ms,
u.turbine_flow_stable
}

_send(CRDN_TYPE.API_GET_UNIT, data)
Expand Down
2 changes: 1 addition & 1 deletion coordinator/startup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local renderer = require("coordinator.renderer")
local sounder = require("coordinator.sounder")
local threads = require("coordinator.threads")

local COORDINATOR_VERSION = "v1.4.6"
local COORDINATOR_VERSION = "v1.4.7"

local CHUNK_LOAD_DELAY_S = 30.0

Expand Down
2 changes: 1 addition & 1 deletion coordinator/threads.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function threads.thread__main(smem)
return public
end

-- coordinator renderer thread, tasked with long duration re-draws
-- coordinator renderer thread, tasked with long duration draws
---@nodiscard
---@param smem crd_shared_memory
function threads.thread__render(smem)
Expand Down
2 changes: 1 addition & 1 deletion graphics/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")

local core = {}

core.version = "2.2.4"
core.version = "2.3.0"

core.flasher = flasher
core.events = events
Expand Down
12 changes: 10 additions & 2 deletions graphics/element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ end
-- a base graphics element, should not be created on its own
---@nodiscard
---@param args graphics_args arguments
---@param constraint? function apply a dimensional constraint based on proposed dimensions function(frame) -> width, height
---@param child_offset_x? integer mouse event offset x
---@param child_offset_y? integer mouse event offset y
function element.new(args, child_offset_x, child_offset_y)
function element.new(args, constraint, child_offset_x, child_offset_y)
local self = {
id = nil, ---@type element_id|nil
is_root = args.parent == nil,
Expand Down Expand Up @@ -199,7 +200,7 @@ function element.new(args, child_offset_x, child_offset_y)
---@param next_y integer next line if no y was provided
function protected.prepare_template(offset_x, offset_y, next_y)
-- don't auto incrememnt y if inheriting height, that would cause an assertion
next_y = util.trinary(args.height == nil, 1, next_y)
next_y = util.trinary(args.height == nil and constraint == nil, 1, next_y)

-- record offsets in case there is a reposition
self.offset_x = offset_x
Expand All @@ -226,6 +227,13 @@ function element.new(args, child_offset_x, child_offset_y)
local w, h = self.p_window.getSize()
f.w = math.min(f.w, w - (f.x - 1))
f.h = math.min(f.h, h - (f.y - 1))

if type(constraint) == "function" then
-- constrain per provided constraint function (can only get smaller than available space)
w, h = constraint(f)
f.w = math.min(f.w, w)
f.h = math.min(f.h, h)
end
end

-- check frame
Expand Down
43 changes: 28 additions & 15 deletions graphics/elements/controls/push_button.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Button Graphics Element

local tcd = require("scada-common.tcd")
local util = require("scada-common.util")

local core = require("graphics.core")
local element = require("graphics.element")
Expand All @@ -21,7 +22,6 @@ local KEY_CLICK = core.events.KEY_CLICK
---@field id? string element id
---@field x? integer 1 if omitted
---@field y? integer auto incremented if omitted
---@field height? integer parent height if omitted
---@field fg_bg? cpair foreground/background colors
---@field hidden? boolean true to hide on initial draw

Expand All @@ -38,29 +38,40 @@ local function push_button(args)

-- set automatic settings
args.can_focus = true
args.height = 1
args.min_width = args.min_width or 0
args.width = math.max(text_width, args.min_width)

-- provide a constraint condition to element creation to prefer a single line button
---@param frame graphics_frame
local function constrain(frame)
return frame.w, math.max(1, #util.strwrap(args.text, frame.w))
end

-- create new graphics element base object
local e = element.new(args)
local e = element.new(args, constrain)

local h_pad = 1
local v_pad = math.floor(e.frame.h / 2) + 1

if alignment == ALIGN.CENTER then
h_pad = math.floor((e.frame.w - text_width) / 2) + 1
elseif alignment == ALIGN.RIGHT then
h_pad = (e.frame.w - text_width) + 1
end
local text_lines = util.strwrap(args.text, e.frame.w)

-- draw the button
function e.redraw()
e.window.clear()

-- write the button text
e.w_set_cur(h_pad, v_pad)
e.w_write(args.text)
for i = 1, #text_lines do
if i > e.frame.h then break end

local len = string.len(text_lines[i])

-- use cursor position to align this line
if alignment == ALIGN.CENTER then
e.w_set_cur(math.floor((e.frame.w - len) / 2) + 1, i)
elseif alignment == ALIGN.RIGHT then
e.w_set_cur((e.frame.w - len) + 1, i)
else
e.w_set_cur(1, i)
end

e.w_write(text_lines[i])
end
end

-- draw the button as pressed (if active_fg_bg set)
Expand Down Expand Up @@ -109,7 +120,9 @@ local function push_button(args)
if event.type == KEY_CLICK.DOWN then
if event.key == keys.space or event.key == keys.enter or event.key == keys.numPadEnter then
args.callback()
e.defocus()
-- visualize click without unfocusing
show_unpressed()
if args.active_fg_bg ~= nil then tcd.dispatch(0.25, show_pressed) end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion graphics/elements/rectangle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local function rectangle(args)
end

-- create new graphics element base object
local e = element.new(args, offset_x, offset_y)
local e = element.new(args, nil, offset_x, offset_y)

-- create content window for child elements
e.content_window = window.create(e.window, 1 + offset_x, 1 + offset_y, e.frame.w - (2 * offset_x), e.frame.h - (2 * offset_y))
Expand Down
19 changes: 17 additions & 2 deletions graphics/elements/textbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ local ALIGN = core.ALIGN
---@class textbox_args
---@field text string text to show
---@field alignment? ALIGN text alignment, left by default
---@field anchor? boolean true to use this as an anchor, making it focusable
---@field parent graphics_element
---@field id? string element id
---@field x? integer 1 if omitted
---@field y? integer auto incremented if omitted
---@field width? integer parent width if omitted
---@field height? integer parent height if omitted
---@field height? integer minimum necessary height for wrapped text if omitted
---@field gframe? graphics_frame frame instead of x/y/width/height
---@field fg_bg? cpair foreground/background colors
---@field hidden? boolean true to hide on initial draw
Expand All @@ -26,8 +27,22 @@ local ALIGN = core.ALIGN
local function textbox(args)
element.assert(type(args.text) == "string", "text is a required field")

if args.anchor == true then args.can_focus = true end

-- provide a constraint condition to element creation to prevent an pointlessly tall text box
---@param frame graphics_frame
local function constrain(frame)
local new_height = math.max(1, #util.strwrap(args.text, frame.w))

if args.height then
new_height = math.max(frame.h, new_height)
end

return frame.w, new_height
end

-- create new graphics element base object
local e = element.new(args)
local e = element.new(args, constrain)

e.value = args.text

Expand Down
Loading

0 comments on commit 006c5e6

Please sign in to comment.