From f9858e1fb7eea0c51d59c23dac5e2b60ddc32b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Tue, 13 Oct 2026 03:08:50 +0000 Subject: [PATCH] fix(tone_alarm): stop without waiting for the next note MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The driver only checks should_exit() in Run(), which is not scheduled while no tune is played, and is scheduled at the next note while a tune is played. "tone_alarm stop" then waited for the next note, or for its 5 s timeout and deleted the driver with "timeout, forcing stop" when no tune was played. The driver now schedules Run() when it is asked to stop. Assisted-by: Claude:opus-5.5 Signed-off-by: Benjamin Cabé --- src/drivers/tone_alarm/ToneAlarm.cpp | 8 ++++++++ src/drivers/tone_alarm/ToneAlarm.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/drivers/tone_alarm/ToneAlarm.cpp b/src/drivers/tone_alarm/ToneAlarm.cpp index 554fd5ef50c..7b20ebfbb66 100644 --- a/src/drivers/tone_alarm/ToneAlarm.cpp +++ b/src/drivers/tone_alarm/ToneAlarm.cpp @@ -73,6 +73,14 @@ bool ToneAlarm::Init() return true; } +void ToneAlarm::request_stop() +{ + ModuleBase::request_stop(); + + // Run() is not scheduled while no tune is played + ScheduleNow(); +} + void ToneAlarm::InterruptStopNote(void *arg) { ToneAlarmInterface::stop_note(); diff --git a/src/drivers/tone_alarm/ToneAlarm.h b/src/drivers/tone_alarm/ToneAlarm.h index 3d78274c11f..96187ef9bec 100644 --- a/src/drivers/tone_alarm/ToneAlarm.h +++ b/src/drivers/tone_alarm/ToneAlarm.h @@ -72,6 +72,9 @@ public: /** @see ModuleBase */ static int print_usage(const char *reason = nullptr); + /** @see ModuleBase */ + void request_stop() override; + private: static void InterruptStopNote(void *arg);