@@ -17,7 +17,8 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
1717 }
1818}
1919
20- Timer::Timer (Controllers::Timer& timerController) : timer {timerController} {
20+ Timer::Timer (Controllers::Timer& timerController, Controllers::MotorController& motorController)
21+ : timer {timerController}, motorController {motorController} {
2122
2223 lv_obj_t * colonLabel = lv_label_create (lv_scr_act (), nullptr );
2324 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} {
6263 // Create the label as a child of the button so it stays centered by default
6364 txtPlayPause = lv_label_create (btnPlayPause, nullptr );
6465
65- if (timer.IsRunning ()) {
66+ if (motorController.IsRinging ()) {
67+ SetTimerRinging ();
68+ } else if (timer.IsRunning ()) {
6669 SetTimerRunning ();
6770 } else {
6871 SetTimerStopped ();
@@ -103,7 +106,17 @@ void Timer::UpdateMask() {
103106}
104107
105108void Timer::Refresh () {
106- if (timer.IsRunning ()) {
109+ if (isRinging) {
110+ DisplayTime ();
111+ // Stop buzzing after 10 seconds, but continue the counter
112+ if (motorController.IsRinging () && displaySeconds.Get ().count () > 10 ) {
113+ motorController.StopRinging ();
114+ }
115+ // Reset timer after 1 minute
116+ if (displaySeconds.Get ().count () > 60 ) {
117+ Reset ();
118+ }
119+ } else if (timer.IsRunning ()) {
107120 DisplayTime ();
108121 } else if (buttonPressing && xTaskGetTickCount () - pressTime > pdMS_TO_TICKS (150 )) {
109122 lv_label_set_text_static (txtPlayPause, " Reset" );
@@ -130,16 +143,30 @@ void Timer::SetTimerRunning() {
130143 minuteCounter.HideControls ();
131144 secondCounter.HideControls ();
132145 lv_label_set_text_static (txtPlayPause, " Pause" );
146+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
133147}
134148
135149void Timer::SetTimerStopped () {
150+ isRinging = false ;
136151 minuteCounter.ShowControls ();
137152 secondCounter.ShowControls ();
138153 lv_label_set_text_static (txtPlayPause, " Start" );
154+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
155+ }
156+
157+ void Timer::SetTimerRinging () {
158+ isRinging = true ;
159+ minuteCounter.HideControls ();
160+ secondCounter.HideControls ();
161+ lv_label_set_text_static (txtPlayPause, " Reset" );
162+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
139163}
140164
141165void Timer::ToggleRunning () {
142- if (timer.IsRunning ()) {
166+ if (isRinging) {
167+ motorController.StopRinging ();
168+ Reset ();
169+ } else if (timer.IsRunning ()) {
143170 DisplayTime ();
144171 timer.StopTimer ();
145172 SetTimerStopped ();
@@ -152,6 +179,7 @@ void Timer::ToggleRunning() {
152179}
153180
154181void Timer::Reset () {
182+ timer.ResetExpiredTime ();
155183 DisplayTime ();
156184 SetTimerStopped ();
157185}
0 commit comments