@@ -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 txtPlayPause = lv_label_create (lv_scr_act (), nullptr );
6364 lv_obj_align (txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0 , 0 );
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,33 @@ 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+ if (ringTime == 0 ) {
163+ ringTime = xTaskGetTickCount ();
164+ }
138165}
139166
140167void Timer::ToggleRunning () {
141- if (timer.IsRunning ()) {
168+ if (isRinging) {
169+ motorController.StopRinging ();
170+ Reset ();
171+ } else if (timer.IsRunning ()) {
142172 DisplayTime ();
143173 timer.StopTimer ();
144174 SetTimerStopped ();
0 commit comments