From e808ee2be05f736880f08c6e4fce8f9477308d70 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Mon, 23 Jan 2023 20:47:45 -0500 Subject: [PATCH] #137 save/recall waste configuration with config file --- coordinator/coordinator.lua | 8 ++++++-- coordinator/process.lua | 29 +++++++++++++++++++++++++++++ coordinator/startup.lua | 2 +- supervisor/session/unit.lua | 3 +++ supervisor/startup.lua | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index 227b020..a0fe10f 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -70,7 +70,9 @@ function coordinator.configure_monitors(num_units) end -- attempt to load settings - settings.load("/coord.settings") + if not settings.load("/coord.settings") then + log.warning("configure_monitors(): failed to load coordinator settings file (may not exist yet)") + end --------------------- -- PRIMARY DISPLAY -- @@ -143,7 +145,9 @@ function coordinator.configure_monitors(num_units) end settings.set("UNIT_DISPLAYS", unit_displays) - settings.save("/coord.settings") + if not settings.save("/coord.settings") then + log.warning("configure_monitors(): failed to save coordinator settings file") + end for i = 1, #unit_displays do monitors.unit_displays[i] = ppm.get_periph(unit_displays[i]) diff --git a/coordinator/process.lua b/coordinator/process.lua index d404e06..963e2c7 100644 --- a/coordinator/process.lua +++ b/coordinator/process.lua @@ -23,6 +23,21 @@ local self = { function process.init(iocontrol, comms) self.io = iocontrol self.comms = comms + + -- load settings + if not settings.load("/coord.settings") then + log.error("process.init(): failed to load coordinator settings file") + end + + local waste_mode = settings.get("WASTE_MODES") ---@type table|nil + + if type(waste_mode) == "table" then + for id = 1, math.min(#waste_mode, self.io.facility.num_units) do + self.comms.send_unit_command(UNIT_COMMANDS.SET_WASTE, id, waste_mode[id]) + end + + log.info("PROCESS: loaded waste mode settings from coord.settings") + end end -- start reactor @@ -62,6 +77,20 @@ end function process.set_waste(id, mode) self.comms.send_command(UNIT_COMMANDS.SET_WASTE, id, mode) log.debug(util.c("UNIT[", id, "]: SET WASTE = ", mode)) + + local waste_mode = settings.get("WASTE_MODES") ---@type table|nil + + if type(waste_mode) ~= "table" then + waste_mode = {} + end + + waste_mode[id] = mode + + settings.set("WASTE_MODES", waste_mode) + + if not settings.save("/coord.settings") then + log.error("process.set_waste(): failed to save coordinator settings file") + end end -- acknowledge all alarms diff --git a/coordinator/startup.lua b/coordinator/startup.lua index bda6ba0..b41c73b 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -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.9" +local COORDINATOR_VERSION = "beta-v0.8.10" local print = util.print local println = util.println diff --git a/supervisor/session/unit.lua b/supervisor/session/unit.lua index 073c1f2..7b5e08d 100644 --- a/supervisor/session/unit.lua +++ b/supervisor/session/unit.lua @@ -322,6 +322,9 @@ function unit.new(for_reactor, num_boilers, num_turbines) ---@param rs_unit unit_session function public.add_redstone(rs_unit) table.insert(self.redstone, rs_unit) + + -- send or re-send waste settings + public.set_waste(self.waste_mode) end -- link a turbine RTU session diff --git a/supervisor/startup.lua b/supervisor/startup.lua index f05eaf8..f4f28da 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -14,7 +14,7 @@ local svsessions = require("supervisor.session.svsessions") local config = require("supervisor.config") local supervisor = require("supervisor.supervisor") -local SUPERVISOR_VERSION = "beta-v0.9.5" +local SUPERVISOR_VERSION = "beta-v0.9.6" local print = util.print local println = util.println