@@ -63,7 +63,9 @@ Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController&
6363 // Create the label as a child of the button so it stays centered by default
6464 txtPlayPause = lv_label_create (btnPlayPause, nullptr );
6565
66- if (motorController.IsRinging ()) {
66+ auto timerStatus = timer.GetTimerState ();
67+
68+ if (timerStatus && timerStatus->expired ) {
6769 SetTimerRinging ();
6870 } else if (timer.IsRunning ()) {
6971 SetTimerRunning ();
@@ -76,6 +78,15 @@ Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController&
7678
7779Timer::~Timer () {
7880 lv_task_del (taskRefresh);
81+
82+ // If timer has expired, reset it when leaving the screen
83+ auto timerStatus = timer.GetTimerState ();
84+ if (timerStatus && timerStatus->expired ) {
85+ motorController.StopRinging ();
86+ wakeLock.Release ();
87+ timer.ResetExpiredTime ();
88+ }
89+
7990 lv_obj_clean (lv_scr_act ());
8091}
8192
@@ -106,20 +117,20 @@ void Timer::UpdateMask() {
106117}
107118
108119void Timer::Refresh () {
109- if (isRinging) {
120+ auto timerStatus = timer.GetTimerState ();
121+
122+ if (timerStatus && timerStatus->expired ) {
123+ // Timer exists and has expired, so we're in ringing mode
110124 DisplayTime ();
111- if (motorController.IsRinging ()) {
112- if (displaySeconds.Get ().count () > 10 ) {
113- // Stop buzzing after 10 seconds, but continue the counter
114- motorController.StopRinging ();
115- wakeLock.Release ();
116- } else {
117- // Keep the screen awake during the first 10 seconds
118- wakeLock.Lock ();
119- }
125+
126+ if (timerStatus->distanceToExpiry .count () > 10000 && motorController.IsRinging ()) {
127+ // Stop buzzing after 10 seconds, but continue the counter
128+ motorController.StopRinging ();
129+ wakeLock.Release ();
120130 }
131+
121132 // Reset timer after 1 minute
122- if (displaySeconds. Get (). count () > 60 ) {
133+ if (timerStatus-> distanceToExpiry . count () > 60000 ) {
123134 Reset ();
124135 }
125136 } else if (timer.IsRunning ()) {
@@ -153,23 +164,24 @@ void Timer::SetTimerRunning() {
153164}
154165
155166void Timer::SetTimerStopped () {
156- isRinging = false ;
157167 minuteCounter.ShowControls ();
158168 secondCounter.ShowControls ();
159169 lv_label_set_text_static (txtPlayPause, " Start" );
160170 lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
161171}
162172
163173void Timer::SetTimerRinging () {
164- isRinging = true ;
174+ motorController.StartRinging ();
175+ wakeLock.Lock ();
165176 minuteCounter.HideControls ();
166177 secondCounter.HideControls ();
167178 lv_label_set_text_static (txtPlayPause, " Reset" );
168179 lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
169180}
170181
171182void Timer::ToggleRunning () {
172- if (isRinging) {
183+ auto timerStatus = timer.GetTimerState ();
184+ if (timerStatus && timerStatus->expired ) {
173185 motorController.StopRinging ();
174186 Reset ();
175187 } else if (timer.IsRunning ()) {
0 commit comments