From 5224dcbd25583360b5480bf03b77b8af6e423c57 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 4 Dec 2022 14:36:29 -0500 Subject: [PATCH] reconnect alarm sounder speaker on peripheral reconnect --- coordinator/sounder.lua | 7 +++++++ coordinator/startup.lua | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/coordinator/sounder.lua b/coordinator/sounder.lua index 92a69ee..594d6c3 100644 --- a/coordinator/sounder.lua +++ b/coordinator/sounder.lua @@ -288,6 +288,13 @@ function sounder.init(speaker, volume) gen_tone_8() end +-- reconnect the speaker peripheral +---@param speaker table speaker peripheral +function sounder.reconnect(speaker) + alarm_ctl.speaker = speaker + alarm_ctl.playing = false +end + -- check alarm state to enable/disable alarms ---@param units table|nil unit list or nil to use test mode function sounder.eval(units) diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 9ede0fc..14cf63d 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -18,7 +18,7 @@ local coordinator = require("coordinator.coordinator") local renderer = require("coordinator.renderer") local sounder = require("coordinator.sounder") -local COORDINATOR_VERSION = "beta-v0.7.3" +local COORDINATOR_VERSION = "beta-v0.7.4" local print = util.print local println = util.println @@ -238,11 +238,15 @@ local function main() elseif type == "monitor" then if renderer.is_monitor_used(device) then -- "halt and catch fire" style handling + println_ts("lost a configured monitor, system will now exit") log_sys("lost a configured monitor, system will now exit") break else log_sys("lost unused monitor, ignoring") end + elseif type == "speaker" then + println_ts("lost alarm sounder speaker") + log_sys("lost alarm sounder speaker") end end elseif event == "peripheral" then @@ -267,6 +271,10 @@ local function main() end elseif type == "monitor" then -- not supported, system will exit on loss of in-use monitors + elseif type == "speaker" then + println_ts("alarm sounder speaker reconnected") + log_sys("alarm sounder speaker reconnected") + sounder.reconnect(device) end end elseif event == "timer" then