@@ -17,7 +17,8 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
17
17
}
18
18
}
19
19
20
- Timer::Timer (Controllers::Timer& timerController) : timer {timerController} {
20
+ Timer::Timer (Controllers::Timer& timerController, Controllers::MotorController& motorController, System::SystemTask& systemTask)
21
+ : timer {timerController}, motorController {motorController}, wakeLock(systemTask) {
21
22
22
23
lv_obj_t * colonLabel = lv_label_create (lv_scr_act (), nullptr );
23
24
lv_obj_set_style_local_text_font (colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
@@ -62,7 +63,9 @@ Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
62
63
txtPlayPause = lv_label_create (lv_scr_act (), nullptr );
63
64
lv_obj_align (txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0 , 0 );
64
65
65
- if (timer.IsRunning ()) {
66
+ if (motorController.IsRinging ()) {
67
+ SetTimerRinging ();
68
+ } else if (timer.IsRunning ()) {
66
69
SetTimerRunning ();
67
70
} else {
68
71
SetTimerStopped ();
@@ -103,7 +106,23 @@ void Timer::UpdateMask() {
103
106
}
104
107
105
108
void Timer::Refresh () {
106
- if (timer.IsRunning ()) {
109
+ if (isRinging) {
110
+ 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
+ }
120
+ }
121
+ // Reset timer after 1 minute
122
+ if (displaySeconds.Get ().count () > 60 ) {
123
+ Reset ();
124
+ }
125
+ } else if (timer.IsRunning ()) {
107
126
DisplayTime ();
108
127
} else if (buttonPressing && xTaskGetTickCount () > pressTime + pdMS_TO_TICKS (150 )) {
109
128
lv_label_set_text_static (txtPlayPause, " Reset" );
@@ -129,16 +148,31 @@ void Timer::SetTimerRunning() {
129
148
minuteCounter.HideControls ();
130
149
secondCounter.HideControls ();
131
150
lv_label_set_text_static (txtPlayPause, " Pause" );
151
+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
132
152
}
133
153
134
154
void Timer::SetTimerStopped () {
155
+ isRinging = false ;
135
156
minuteCounter.ShowControls ();
136
157
secondCounter.ShowControls ();
137
158
lv_label_set_text_static (txtPlayPause, " Start" );
159
+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
160
+ }
161
+
162
+ void Timer::SetTimerRinging () {
163
+ isRinging = true ;
164
+ minuteCounter.HideControls ();
165
+ secondCounter.HideControls ();
166
+ lv_label_set_text_static (txtPlayPause, " Reset" );
167
+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
168
+ timer.SetExpiredTime ();
138
169
}
139
170
140
171
void Timer::ToggleRunning () {
141
- if (timer.IsRunning ()) {
172
+ if (isRinging) {
173
+ motorController.StopRinging ();
174
+ Reset ();
175
+ } else if (timer.IsRunning ()) {
142
176
DisplayTime ();
143
177
timer.StopTimer ();
144
178
SetTimerStopped ();
@@ -151,6 +185,7 @@ void Timer::ToggleRunning() {
151
185
}
152
186
153
187
void Timer::Reset () {
188
+ timer.ResetExpiredTime ();
154
189
DisplayTime ();
155
190
SetTimerStopped ();
156
191
}
0 commit comments