@@ -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,14 @@ 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+ timer.ResetExpiredTime ();
87+ }
88+
7989 lv_obj_clean (lv_scr_act ());
8090}
8191
@@ -106,20 +116,20 @@ void Timer::UpdateMask() {
106116}
107117
108118void Timer::Refresh () {
109- if (isRinging) {
119+ auto timerStatus = timer.GetTimerState ();
120+
121+ if (timerStatus && timerStatus->expired ) {
122+ // Timer exists and has expired, so we're in ringing mode
110123 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- }
124+
125+ if (timerStatus->distanceToExpiry .count () > 10000 && motorController.IsRinging ()) {
126+ // Stop buzzing after 10 seconds, but continue the counter
127+ motorController.StopRinging ();
128+ wakeLock.Release ();
120129 }
130+
121131 // Reset timer after 1 minute
122- if (displaySeconds. Get (). count () > 60 ) {
132+ if (timerStatus-> distanceToExpiry . count () > 60000 ) {
123133 Reset ();
124134 }
125135 } else if (timer.IsRunning ()) {
@@ -153,23 +163,24 @@ void Timer::SetTimerRunning() {
153163}
154164
155165void Timer::SetTimerStopped () {
156- isRinging = false ;
157166 minuteCounter.ShowControls ();
158167 secondCounter.ShowControls ();
159168 lv_label_set_text_static (txtPlayPause, " Start" );
160169 lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
161170}
162171
163172void Timer::SetTimerRinging () {
164- isRinging = true ;
173+ motorController.StartRinging ();
174+ wakeLock.Lock ();
165175 minuteCounter.HideControls ();
166176 secondCounter.HideControls ();
167177 lv_label_set_text_static (txtPlayPause, " Reset" );
168178 lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
169179}
170180
171181void Timer::ToggleRunning () {
172- if (isRinging) {
182+ auto timerStatus = timer.GetTimerState ();
183+ if (timerStatus && timerStatus->expired ) {
173184 motorController.StopRinging ();
174185 Reset ();
175186 } else if (timer.IsRunning ()) {
0 commit comments