diff options
| author | Victor Kareh <vkareh@redhat.com> | 2025-11-18 10:33:54 -0500 |
|---|---|---|
| committer | JF <JF002@users.noreply.github.com> | 2025-12-13 21:31:50 +0100 |
| commit | 66b5977f39bf22e0641be43766439a3ed025d604 (patch) | |
| tree | c1d37a11918291bdd950310c8c490f857e47923e /src/displayapp/screens/Timer.cpp | |
| parent | a4918c0e96c17d98452e150e821565ee03aaa90b (diff) | |
timer: Refactor ringing state management
Consolidate timer ringing logic and use Timer component as single source
of truth for expired state.
Diffstat (limited to 'src/displayapp/screens/Timer.cpp')
| -rw-r--r-- | src/displayapp/screens/Timer.cpp | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp index 02c84160..749d9859 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer.cpp @@ -63,7 +63,9 @@ Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController& // Create the label as a child of the button so it stays centered by default txtPlayPause = lv_label_create(btnPlayPause, nullptr); - if (motorController.IsRinging()) { + auto timerStatus = timer.GetTimerState(); + + if (timerStatus && timerStatus->expired) { SetTimerRinging(); } else if (timer.IsRunning()) { SetTimerRunning(); @@ -76,6 +78,14 @@ Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController& Timer::~Timer() { lv_task_del(taskRefresh); + + // If timer has expired, reset it when leaving the screen + auto timerStatus = timer.GetTimerState(); + if (timerStatus && timerStatus->expired) { + motorController.StopRinging(); + timer.ResetExpiredTime(); + } + lv_obj_clean(lv_scr_act()); } @@ -106,20 +116,20 @@ void Timer::UpdateMask() { } void Timer::Refresh() { - if (isRinging) { + auto timerStatus = timer.GetTimerState(); + + if (timerStatus && timerStatus->expired) { + // Timer exists and has expired, so we're in ringing mode DisplayTime(); - if (motorController.IsRinging()) { - if (displaySeconds.Get().count() > 10) { - // Stop buzzing after 10 seconds, but continue the counter - motorController.StopRinging(); - wakeLock.Release(); - } else { - // Keep the screen awake during the first 10 seconds - wakeLock.Lock(); - } + + if (timerStatus->distanceToExpiry.count() > 10000 && motorController.IsRinging()) { + // Stop buzzing after 10 seconds, but continue the counter + motorController.StopRinging(); + wakeLock.Release(); } + // Reset timer after 1 minute - if (displaySeconds.Get().count() > 60) { + if (timerStatus->distanceToExpiry.count() > 60000) { Reset(); } } else if (timer.IsRunning()) { @@ -153,7 +163,6 @@ void Timer::SetTimerRunning() { } void Timer::SetTimerStopped() { - isRinging = false; minuteCounter.ShowControls(); secondCounter.ShowControls(); lv_label_set_text_static(txtPlayPause, "Start"); @@ -161,7 +170,8 @@ void Timer::SetTimerStopped() { } void Timer::SetTimerRinging() { - isRinging = true; + motorController.StartRinging(); + wakeLock.Lock(); minuteCounter.HideControls(); secondCounter.HideControls(); lv_label_set_text_static(txtPlayPause, "Reset"); @@ -169,7 +179,8 @@ void Timer::SetTimerRinging() { } void Timer::ToggleRunning() { - if (isRinging) { + auto timerStatus = timer.GetTimerState(); + if (timerStatus && timerStatus->expired) { motorController.StopRinging(); Reset(); } else if (timer.IsRunning()) { |
