@@ -54,9 +54,17 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController)
5454
5555 time = lv_label_create (lv_scr_act (), nullptr );
5656 lv_obj_set_style_local_text_font (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
57- lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
5857
59- uint32_t seconds = timerController.GetTimeRemaining () / 1000 ;
58+ int32_t seconds = timerController.GetSecondsRemaining ();
59+ bool overtime = timerController.IsOvertime ();
60+
61+ if (overtime) {
62+ seconds = -seconds + 1 ; // "+ 1" is to not show -00:00 again after +00:00
63+ lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
64+ } else {
65+ lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
66+ }
67+
6068 lv_label_set_text_fmt (time, " %02lu:%02lu" , seconds / 60 , seconds % 60 );
6169
6270 lv_obj_align (time, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 0 , -20 );
@@ -68,23 +76,39 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController)
6876 lv_obj_set_height (btnPlayPause, 40 );
6977 txtPlayPause = lv_label_create (btnPlayPause, nullptr );
7078 if (timerController.IsRunning ()) {
71- lv_label_set_text (txtPlayPause, Symbols::pause);
79+ lv_label_set_text (txtPlayPause, overtime ? Symbols::stop : Symbols::pause);
7280 } else {
7381 lv_label_set_text (txtPlayPause, Symbols::play);
7482 createButtons ();
7583 }
76-
7784 taskRefresh = lv_task_create (RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this );
7885}
7986
8087Timer::~Timer () {
8188 lv_task_del (taskRefresh);
8289 lv_obj_clean (lv_scr_act ());
90+ if (timerController.IsRunning () and timerController.IsOvertime ()) {
91+ timerController.StopTimer ();
92+ }
8393}
8494
8595void Timer::Refresh () {
8696 if (timerController.IsRunning ()) {
87- uint32_t seconds = timerController.GetTimeRemaining () / 1000 ;
97+ int32_t seconds = timerController.GetSecondsRemaining ();
98+ if (timerController.IsOvertime ()) {
99+ seconds = -seconds + 1 ; // "+ 1" is to not show -00:00 again after +00:00
100+
101+ // safety measures, lets not overflow counter as it will display badly
102+ if (seconds >= 100 * 60 ) {
103+ minutesToSet = 0 ;
104+ secondsToSet = 0 ;
105+ lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
106+ lv_label_set_text_static (time, " 00:00" );
107+ lv_label_set_text (txtPlayPause, Symbols::play);
108+ timerController.StopTimer ();
109+ createButtons ();
110+ }
111+ }
88112 lv_label_set_text_fmt (time, " %02lu:%02lu" , seconds / 60 , seconds % 60 );
89113 }
90114}
@@ -94,16 +118,24 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
94118 if (obj == btnPlayPause) {
95119 if (timerController.IsRunning ()) {
96120 lv_label_set_text (txtPlayPause, Symbols::play);
97- uint32_t seconds = timerController.GetTimeRemaining () / 1000 ;
98- minutesToSet = seconds / 60 ;
99- secondsToSet = seconds % 60 ;
121+ int32_t secondsRemaining = timerController.GetSecondsRemaining ();
122+ if (timerController.IsOvertime ()) {
123+ minutesToSet = 0 ;
124+ secondsToSet = 0 ;
125+ lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
126+ lv_label_set_text_static (time, " 00:00" );
127+ } else {
128+ minutesToSet = secondsRemaining / 60 ;
129+ secondsToSet = secondsRemaining % 60 ;
130+ }
100131 timerController.StopTimer ();
101132 createButtons ();
102133
103134 } else if (secondsToSet + minutesToSet > 0 ) {
104135 lv_label_set_text (txtPlayPause, Symbols::pause);
105136 timerController.StartTimer ((secondsToSet + minutesToSet * 60 ) * 1000 );
106137
138+ // inlined destroyButtons()
107139 lv_obj_del (btnSecondsDown);
108140 btnSecondsDown = nullptr ;
109141 lv_obj_del (btnSecondsUp);
@@ -153,9 +185,6 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
153185}
154186
155187void Timer::setDone () {
156- lv_label_set_text (time, " 00:00" );
157- lv_label_set_text (txtPlayPause, Symbols::play);
158- secondsToSet = 0 ;
159- minutesToSet = 0 ;
160- createButtons ();
188+ lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
189+ lv_label_set_text (txtPlayPause, Symbols::stop);
161190}
0 commit comments