@@ -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,12 @@ void Timer::UpdateMask() {
103106}
104107
105108void Timer::Refresh () {
106- if (timer.IsRunning ()) {
109+ if (motorController.IsRinging ()) {
110+ SetTimerRinging ();
111+ auto secondsElapsed = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
112+ minuteCounter.SetValue (secondsElapsed.count () / 60 );
113+ secondCounter.SetValue (secondsElapsed.count () % 60 );
114+ } else if (timer.IsRunning ()) {
107115 auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
108116 minuteCounter.SetValue (secondsRemaining.count () / 60 );
109117 secondCounter.SetValue (secondsRemaining.count () % 60 );
@@ -123,16 +131,31 @@ void Timer::SetTimerRunning() {
123131 minuteCounter.HideControls ();
124132 secondCounter.HideControls ();
125133 lv_label_set_text_static (txtPlayPause, " Pause" );
134+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
126135}
127136
128137void Timer::SetTimerStopped () {
129138 minuteCounter.ShowControls ();
130139 secondCounter.ShowControls ();
131140 lv_label_set_text_static (txtPlayPause, " Start" );
141+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
142+ }
143+
144+ void Timer::SetTimerRinging () {
145+ minuteCounter.HideControls ();
146+ secondCounter.HideControls ();
147+ lv_label_set_text_static (txtPlayPause, " Reset" );
148+ lv_obj_set_style_local_bg_color (btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
149+ if (ringTime == 0 ) {
150+ ringTime = xTaskGetTickCount ();
151+ }
132152}
133153
134154void Timer::ToggleRunning () {
135- if (timer.IsRunning ()) {
155+ if (motorController.IsRinging ()) {
156+ motorController.StopRinging ();
157+ Reset ();
158+ } else if (timer.IsRunning ()) {
136159 auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
137160 minuteCounter.SetValue (secondsRemaining.count () / 60 );
138161 secondCounter.SetValue (secondsRemaining.count () % 60 );
0 commit comments