@@ -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)
21
+ : timer {timerController}, motorController {motorController} {
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,12 @@ void Timer::UpdateMask() {
103
106
}
104
107
105
108
void 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 ()) {
107
115
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
108
116
minuteCounter.SetValue (secondsRemaining.count () / 60 );
109
117
secondCounter.SetValue (secondsRemaining.count () % 60 );
@@ -123,16 +131,31 @@ void Timer::SetTimerRunning() {
123
131
minuteCounter.HideControls ();
124
132
secondCounter.HideControls ();
125
133
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);
126
135
}
127
136
128
137
void Timer::SetTimerStopped () {
129
138
minuteCounter.ShowControls ();
130
139
secondCounter.ShowControls ();
131
140
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
+ }
132
152
}
133
153
134
154
void Timer::ToggleRunning () {
135
- if (timer.IsRunning ()) {
155
+ if (motorController.IsRinging ()) {
156
+ motorController.StopRinging ();
157
+ Reset ();
158
+ } else if (timer.IsRunning ()) {
136
159
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
137
160
minuteCounter.SetValue (secondsRemaining.count () / 60 );
138
161
secondCounter.SetValue (secondsRemaining.count () % 60 );
0 commit comments