diff --git a/coordinator/configure.lua b/coordinator/configure.lua index 7abb267..25dc93b 100644 --- a/coordinator/configure.lua +++ b/coordinator/configure.lua @@ -39,7 +39,9 @@ local CENTER = core.ALIGN.CENTER local RIGHT = core.ALIGN.RIGHT -- changes to the config data/format to let the user know -local changes = {} +local changes = { + {"v1.2.4", { "Added temperature scale options" } } +} ---@class crd_configurator local configurator = {} @@ -119,6 +121,7 @@ local tmp_cfg = { UnitCount = 1, SpeakerVolume = 1.0, Time24Hour = true, + TempScale = 1, DisableFlowView = false, MainDisplay = nil, ---@type string FlowDisplay = nil, ---@type string @@ -148,6 +151,7 @@ local fields = { { "UnitDisplays", "Unit Monitors", {} }, { "SpeakerVolume", "Speaker Volume", 1.0 }, { "Time24Hour", "Use 24-hour Time Format", true }, + { "TempScale", "Temperature Scale", 1 }, { "DisableFlowView", "Disable Flow Monitor (legacy, discouraged)", false }, { "SVR_Channel", "SVR Channel", 16240 }, { "CRD_Channel", "CRD Channel", 16243 }, @@ -739,8 +743,12 @@ local function config_view(display) TextBox{parent=crd_c_1,x=1,y=4,height=1,text="Clock Time Format"} 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 function submit_ui_opts() tmp_cfg.Time24Hour = clock_fmt.get_value() == 1 + tmp_cfg.TempScale = temp_scale.get_value() main_pane.set_value(7) end @@ -1186,6 +1194,8 @@ 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" else val = "Rankine" end elseif f[1] == "UnitDisplays" and type(cfg.UnitDisplays) == "table" then val = "" for idx = 1, #cfg.UnitDisplays do diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index ae2ab77..5ed4a99 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -35,6 +35,7 @@ function coordinator.load_config() config.UnitCount = settings.get("UnitCount") config.SpeakerVolume = settings.get("SpeakerVolume") config.Time24Hour = settings.get("Time24Hour") + config.TempScale = settings.get("TempScale") config.DisableFlowView = settings.get("DisableFlowView") config.MainDisplay = settings.get("MainDisplay") @@ -58,6 +59,8 @@ function coordinator.load_config() cfv.assert_type_int(config.UnitCount) cfv.assert_range(config.UnitCount, 1, 4) cfv.assert_type_bool(config.Time24Hour) + cfv.assert_type_int(config.TempScale) + cfv.assert_range(config.TempScale, 1, 4) cfv.assert_type_bool(config.DisableFlowView) cfv.assert_type_table(config.UnitDisplays) @@ -676,7 +679,7 @@ function coordinator.comms(version, nic, sv_watchdog) if conf.num_units == config.UnitCount then -- init io controller - iocontrol.init(conf, public) + iocontrol.init(conf, public, config.TempScale) self.sv_addr = src_addr self.sv_linked = true diff --git a/coordinator/iocontrol.lua b/coordinator/iocontrol.lua index 3e32d6d..16cde18 100644 --- a/coordinator/iocontrol.lua +++ b/coordinator/iocontrol.lua @@ -47,7 +47,23 @@ end -- initialize the coordinator IO controller ---@param conf facility_conf configuration ---@param comms coord_comms comms reference -function iocontrol.init(conf, comms) +---@param temp_scale integer temperature unit (1 = K, 2 = C, 3 = F, 4 = R) +function iocontrol.init(conf, comms, temp_scale) + -- temperature unit label and conversion function (from Kelvin) + if temp_scale == 2 then + io.temp_label = "\xb0C" + io.temp_convert = function (t) return t - 273.15 end + elseif temp_scale == 3 then + io.temp_label = "\xb0F" + io.temp_convert = function (t) return (1.8 * (t - 273.15)) + 32 end + elseif temp_scale == 4 then + io.temp_label = "\xb0R" + io.temp_convert = function (t) return 1.8 * t end + else + io.temp_label = "K" + io.temp_convert = function (t) return t end + end + -- facility data structure ---@class ioctl_facility io.facility = { diff --git a/coordinator/renderer.lua b/coordinator/renderer.lua index fd08c6b..a1826e4 100644 --- a/coordinator/renderer.lua +++ b/coordinator/renderer.lua @@ -94,8 +94,8 @@ end -- initialize the dmesg output window function renderer.init_dmesg() - local disp_x, disp_y = engine.monitors.primary.getSize() - engine.dmesg_window = window.create(engine.monitors.primary, 1, 1, disp_x, disp_y) + local disp_w, disp_h = engine.monitors.primary.getSize() + engine.dmesg_window = window.create(engine.monitors.primary, 1, 1, disp_w, disp_h) log.direct_dmesg(engine.dmesg_window) end @@ -302,9 +302,6 @@ function renderer.handle_reconnect(name, device) is_used = true engine.monitors.primary = device - local disp_x, disp_y = engine.monitors.primary.getSize() - engine.dmesg_window.reposition(1, 1, disp_x, disp_y, engine.monitors.primary) - renderer.handle_resize(name) elseif engine.monitors.flow_name == name then is_used = true @@ -347,10 +344,8 @@ function renderer.handle_resize(name) -- resize dmesg window if needed, but don't make it thinner local disp_w, disp_h = engine.monitors.primary.getSize() - local dmsg_w, dmsg_h = engine.dmesg_window.getSize() - if disp_h ~= dmsg_h then - engine.dmesg_window = window.reposition(1, 1, math.max(disp_w, dmsg_w), disp_h, engine.monitors.primary) - end + local dmsg_w, _ = engine.dmesg_window.getSize() + engine.dmesg_window.reposition(1, 1, math.max(disp_w, dmsg_w), disp_h, engine.monitors.primary) if ui.main_display then ui.main_display.delete() diff --git a/coordinator/startup.lua b/coordinator/startup.lua index b3ba2b8..de911a2 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -22,7 +22,7 @@ local sounder = require("coordinator.sounder") local apisessions = require("coordinator.session.apisessions") -local COORDINATOR_VERSION = "v1.2.3" +local COORDINATOR_VERSION = "v1.2.4" local println = util.println local println_ts = util.println_ts diff --git a/coordinator/ui/components/boiler.lua b/coordinator/ui/components/boiler.lua index 0d651d9..ce2f1bc 100644 --- a/coordinator/ui/components/boiler.lua +++ b/coordinator/ui/components/boiler.lua @@ -1,5 +1,7 @@ local style = require("coordinator.ui.style") +local iocontrol = require("coordinator.iocontrol") + local core = require("graphics.core") local Rectangle = require("graphics.elements.rectangle") @@ -13,6 +15,7 @@ local cpair = core.cpair local border = core.border local text_fg_bg = style.text_colors +local lu_col = style.lu_colors -- new boiler view ---@param root graphics_element parent @@ -20,14 +23,16 @@ local text_fg_bg = style.text_colors ---@param y integer top left y ---@param ps psil ps interface local function new_view(root, x, y, ps) + local db = iocontrol.get_db() + local boiler = Rectangle{parent=root,border=border(1,colors.gray,true),width=31,height=7,x=x,y=y} local status = StateIndicator{parent=boiler,x=9,y=1,states=style.boiler.states,value=1,min_width=12} - local temp = DataIndicator{parent=boiler,x=5,y=3,lu_colors=style.lu_col,label="Temp:",unit="K",format="%10.2f",value=0,width=22,fg_bg=text_fg_bg} - local boil_r = DataIndicator{parent=boiler,x=5,y=4,lu_colors=style.lu_col,label="Boil:",unit="mB/t",format="%10.0f",value=0,commas=true,width=22,fg_bg=text_fg_bg} + local temp = DataIndicator{parent=boiler,x=5,y=3,lu_colors=lu_col,label="Temp:",unit=db.temp_label,format="%10.2f",value=0,commas=true,width=22,fg_bg=text_fg_bg} + local boil_r = DataIndicator{parent=boiler,x=5,y=4,lu_colors=lu_col,label="Boil:",unit="mB/t",format="%10.0f",value=0,commas=true,width=22,fg_bg=text_fg_bg} status.register(ps, "computed_status", status.update) - temp.register(ps, "temperature", temp.update) + temp.register(ps, "temperature", function (t) temp.update(db.temp_convert(t)) end) boil_r.register(ps, "boil_rate", boil_r.update) TextBox{parent=boiler,text="H",x=2,y=5,height=1,width=1,fg_bg=text_fg_bg} diff --git a/coordinator/ui/components/reactor.lua b/coordinator/ui/components/reactor.lua index c74ab0a..27b033e 100644 --- a/coordinator/ui/components/reactor.lua +++ b/coordinator/ui/components/reactor.lua @@ -1,5 +1,7 @@ local types = require("scada-common.types") +local iocontrol = require("coordinator.iocontrol") + local style = require("coordinator.ui.style") local core = require("graphics.core") @@ -23,15 +25,17 @@ local lu_col = style.lu_colors ---@param y integer top left y ---@param ps psil ps interface local function new_view(root, x, y, ps) + local db = iocontrol.get_db() + local reactor = Rectangle{parent=root,border=border(1, colors.gray, true),width=30,height=7,x=x,y=y} local status = StateIndicator{parent=reactor,x=6,y=1,states=style.reactor.states,value=1,min_width=16} - local core_temp = DataIndicator{parent=reactor,x=2,y=3,lu_colors=lu_col,label="Core Temp:",unit="K",format="%10.2f",value=0,width=26,fg_bg=text_fg_bg} + local core_temp = DataIndicator{parent=reactor,x=2,y=3,lu_colors=lu_col,label="Core Temp:",unit=db.temp_label,format="%10.2f",value=0,commas=true,width=26,fg_bg=text_fg_bg} local burn_r = DataIndicator{parent=reactor,x=2,y=4,lu_colors=lu_col,label="Burn Rate:",unit="mB/t",format="%10.2f",value=0,width=26,fg_bg=text_fg_bg} local heating_r = DataIndicator{parent=reactor,x=2,y=5,lu_colors=lu_col,label="Heating:",unit="mB/t",format="%12.0f",value=0,commas=true,width=26,fg_bg=text_fg_bg} status.register(ps, "computed_status", status.update) - core_temp.register(ps, "temp", core_temp.update) + core_temp.register(ps, "temp", function (t) core_temp.update(db.temp_convert(t)) end) burn_r.register(ps, "act_burn_rate", burn_r.update) heating_r.register(ps, "heating_rate", heating_r.update) diff --git a/coordinator/ui/components/unit_detail.lua b/coordinator/ui/components/unit_detail.lua index 52b633a..64fc1e0 100644 --- a/coordinator/ui/components/unit_detail.lua +++ b/coordinator/ui/components/unit_detail.lua @@ -3,6 +3,7 @@ -- local types = require("scada-common.types") +local util = require("scada-common.util") local iocontrol = require("coordinator.iocontrol") @@ -51,8 +52,9 @@ local period = core.flasher.PERIOD ---@param parent graphics_element parent ---@param id integer local function init(parent, id) - local unit = iocontrol.get_db().units[id] ---@type ioctl_unit - local f_ps = iocontrol.get_db().facility.ps + local db = iocontrol.get_db() + local unit = db.units[id] ---@type ioctl_unit + local f_ps = db.facility.ps local main = Div{parent=parent,x=1,y=1} @@ -114,8 +116,9 @@ local function init(parent, id) end) TextBox{parent=main,x=32,y=22,text="Core Temp",height=1,width=9,fg_bg=style.label} - local core_temp = DataIndicator{parent=main,x=32,label="",format="%11.2f",value=0,unit="K",lu_colors=lu_cpair,width=13,fg_bg=bw_fg_bg} - core_temp.register(u_ps, "temp", core_temp.update) + local fmt = util.trinary(string.len(db.temp_label) == 2, "%10.2f", "%11.2f") + local core_temp = DataIndicator{parent=main,x=32,label="",format=fmt,value=0,commas=true,unit=db.temp_label,lu_colors=lu_cpair,width=13,fg_bg=bw_fg_bg} + core_temp.register(u_ps, "temp", function (t) core_temp.update(db.temp_convert(t)) end) TextBox{parent=main,x=32,y=25,text="Burn Rate",height=1,width=9,fg_bg=style.label} local act_burn_r = DataIndicator{parent=main,x=32,label="",format="%8.2f",value=0,unit="mB/t",lu_colors=lu_cpair,width=13,fg_bg=bw_fg_bg}