From 9d60777223f7d02036b43f353176ed0065ff9b5a Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Fri, 7 Oct 2022 10:19:37 -0400 Subject: [PATCH] #93 added reset RPS command to iocontrol/gui --- coordinator/iocontrol.lua | 5 ++ coordinator/startup.lua | 2 +- coordinator/ui/components/unit_detail.lua | 8 +- .../{scram_button.lua => hazard_button.lua} | 22 +++--- graphics/elements/controls/start_button.lua | 78 ------------------- 5 files changed, 22 insertions(+), 93 deletions(-) rename graphics/elements/controls/{scram_button.lua => hazard_button.lua} (73%) delete mode 100644 graphics/elements/controls/start_button.lua diff --git a/coordinator/iocontrol.lua b/coordinator/iocontrol.lua index f34cfab..bc93f05 100644 --- a/coordinator/iocontrol.lua +++ b/coordinator/iocontrol.lua @@ -44,6 +44,11 @@ function iocontrol.init(conf, comms) log.debug(util.c("sent unit ", i, ": SCRAM")) end, + reset_rps = function () + comms.send_command(i, CRDN_COMMANDS.RESET_RPS) + log.debug(util.c("sent unit ", i, ": RESET_RPS")) + end, + set_burn = function (rate) comms.send_command(i, CRDN_COMMANDS.SET_BURN, rate) log.debug(util.c("sent unit ", i, ": SET_BURN = ", rate)) diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 396a116..708c3d3 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -16,7 +16,7 @@ local config = require("coordinator.config") local coordinator = require("coordinator.coordinator") local renderer = require("coordinator.renderer") -local COORDINATOR_VERSION = "alpha-v0.5.0" +local COORDINATOR_VERSION = "alpha-v0.5.1" local print = util.print local println = util.println diff --git a/coordinator/ui/components/unit_detail.lua b/coordinator/ui/components/unit_detail.lua index 2244fd3..36291cd 100644 --- a/coordinator/ui/components/unit_detail.lua +++ b/coordinator/ui/components/unit_detail.lua @@ -19,10 +19,9 @@ local DataIndicator = require("graphics.elements.indicators.data") local IndicatorLight = require("graphics.elements.indicators.light") local TriIndicatorLight = require("graphics.elements.indicators.trilight") +local HazardButton = require("graphics.elements.controls.hazard_button") local MultiButton = require("graphics.elements.controls.multi_button") local PushButton = require("graphics.elements.controls.push_button") -local SCRAMButton = require("graphics.elements.controls.scram_button") -local StartButton = require("graphics.elements.controls.start_button") local SpinboxNumeric = require("graphics.elements.controls.spinbox_numeric") local TEXT_ALIGN = core.graphics.TEXT_ALIGN @@ -240,8 +239,9 @@ local function init(parent, id) -- reactor controls -- - StartButton{parent=main,x=12,y=44,callback=unit.start,fg_bg=scram_fg_bg} - SCRAMButton{parent=main,x=22,y=44,callback=unit.scram,fg_bg=scram_fg_bg} + HazardButton{parent=main,x=2,y=44,text="START",accent=colors.lightBlue,callback=unit.start,fg_bg=scram_fg_bg} + HazardButton{parent=main,x=12,y=44,text="SCRAM",accent=colors.yellow,callback=unit.scram,fg_bg=scram_fg_bg} + HazardButton{parent=main,x=22,y=44,text="RESET",accent=colors.red,callback=unit.reset_rps,fg_bg=scram_fg_bg} local burn_control = Div{parent=main,x=12,y=40,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=cpair(colors.black,colors.white)} diff --git a/graphics/elements/controls/scram_button.lua b/graphics/elements/controls/hazard_button.lua similarity index 73% rename from graphics/elements/controls/scram_button.lua rename to graphics/elements/controls/hazard_button.lua index 1abe8a1..90a2118 100644 --- a/graphics/elements/controls/scram_button.lua +++ b/graphics/elements/controls/hazard_button.lua @@ -1,13 +1,13 @@ --- SCRAM Button Graphics Element +-- Hazard-bordered Button Graphics Element local tcd = require("scada-common.tcallbackdsp") local core = require("graphics.core") local element = require("graphics.element") -local accent = colors.yellow - ---@class scram_button_args +---@field text string text to show on button +---@field accent color accent color for hazard border ---@field callback function function to call on touch ---@field parent graphics_element ---@field id? string element id @@ -19,23 +19,25 @@ local accent = colors.yellow ---@param args scram_button_args ---@return graphics_element element, element_id id local function scram_button(args) - assert(type(args.callback) == "function", "graphics.elements.controls.scram_button: callback is a required field") + assert(type(args.text) == "string", "graphics.elements.controls.hazard_button: text is a required field") + assert(type(args.accent) == "number", "graphics.elements.controls.hazard_button: accent is a required field") + assert(type(args.callback) == "function", "graphics.elements.controls.hazard_button: callback is a required field") -- static dimensions args.height = 3 - args.width = 9 + args.width = string.len(args.text) + 4 -- create new graphics element base object local e = element.new(args) -- write the button text e.window.setCursorPos(3, 2) - e.window.write("SCRAM") + e.window.write(args.text) -- draw border -- top - e.window.setTextColor(accent) + e.window.setTextColor(args.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") @@ -43,17 +45,17 @@ local function scram_button(args) -- center left e.window.setCursorPos(1, 2) e.window.setTextColor(args.fg_bg.bkg) - e.window.setBackgroundColor(accent) + e.window.setBackgroundColor(args.accent) e.window.write("\x99") -- center right e.window.setTextColor(args.fg_bg.bkg) - e.window.setBackgroundColor(accent) + e.window.setBackgroundColor(args.accent) e.window.setCursorPos(9, 2) e.window.write("\x99") -- bottom - e.window.setTextColor(accent) + e.window.setTextColor(args.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") diff --git a/graphics/elements/controls/start_button.lua b/graphics/elements/controls/start_button.lua deleted file mode 100644 index e512c31..0000000 --- a/graphics/elements/controls/start_button.lua +++ /dev/null @@ -1,78 +0,0 @@ --- SCRAM Button Graphics Element - -local tcd = require("scada-common.tcallbackdsp") - -local core = require("graphics.core") -local element = require("graphics.element") - -local accent = colors.lightBlue - ----@class start_button_args ----@field callback function function to call on touch ----@field parent graphics_element ----@field id? string element id ----@field x? integer 1 if omitted ----@field y? integer 1 if omitted ----@field fg_bg? cpair foreground/background colors - --- new start button ----@param args start_button_args ----@return graphics_element element, element_id id -local function start_button(args) - assert(type(args.callback) == "function", "graphics.elements.controls.start_button: callback is a required field") - - -- static dimensions - args.height = 3 - args.width = 9 - - -- create new graphics element base object - local e = element.new(args) - - -- write the button text - e.window.setCursorPos(3, 2) - e.window.write("START") - - -- draw border - - -- top - 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") - - -- center left - e.window.setCursorPos(1, 2) - e.window.setTextColor(args.fg_bg.bkg) - e.window.setBackgroundColor(accent) - e.window.write("\x99") - - -- center right - e.window.setTextColor(args.fg_bg.bkg) - e.window.setBackgroundColor(accent) - e.window.setCursorPos(9, 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") - - -- handle touch - ---@param event monitor_touch monitor touch event ----@diagnostic disable-next-line: unused-local - function e.handle_touch(event) - -- call the touch callback - args.callback() - end - - -- set the value - ---@param val boolean new value - function e.set_value(val) - if val then e.handle_touch(core.events.touch("", 1, 1)) end - end - - return e.get() -end - -return start_button