@@ -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" );
@@ -129,16 +142,31 @@ void Timer::SetTimerRunning() {
129142 minuteCounter.HideControls ();
130143 secondCounter.HideControls ();
131144 lv_label_set_text_static (txtPlayPause, " Pause" );
145+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
132146}
133147
134148void Timer::SetTimerStopped () {
149+ isRinging = false ;
135150 minuteCounter.ShowControls ();
136151 secondCounter.ShowControls ();
137152 lv_label_set_text_static (txtPlayPause, " Start" );
153+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
154+ }
155+
156+ void Timer::SetTimerRinging () {
157+ isRinging = true ;
158+ minuteCounter.HideControls ();
159+ secondCounter.HideControls ();
160+ lv_label_set_text_static (txtPlayPause, " Reset" );
161+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
162+ timer.SetExpiredTime ();
138163}
139164
140165void Timer::ToggleRunning () {
141- if (timer.IsRunning ()) {
166+ if (isRinging) {
167+ motorController.StopRinging ();
168+ Reset ();
169+ } else if (timer.IsRunning ()) {
142170 DisplayTime ();
143171 timer.StopTimer ();
144172 SetTimerStopped ();
@@ -151,6 +179,7 @@ void Timer::ToggleRunning() {
151179}
152180
153181void Timer::Reset () {
182+ timer.ResetExpiredTime ();
154183 DisplayTime ();
155184 SetTimerStopped ();
156185}
0 commit comments