@@ -104,9 +104,7 @@ void Timer::UpdateMask() {
104
104
105
105
void Timer::Refresh () {
106
106
if (timer.IsRunning ()) {
107
- auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
108
- minuteCounter.SetValue (secondsRemaining.count () / 60 );
109
- secondCounter.SetValue (secondsRemaining.count () % 60 );
107
+ DisplayTime ();
110
108
} else if (buttonPressing && xTaskGetTickCount () > pressTime + pdMS_TO_TICKS (150 )) {
111
109
lv_label_set_text_static (txtPlayPause, " Reset" );
112
110
maskPosition += 15 ;
@@ -119,6 +117,14 @@ void Timer::Refresh() {
119
117
}
120
118
}
121
119
120
+ void Timer::DisplayTime () {
121
+ displaySeconds = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
122
+ if (displaySeconds.IsUpdated ()) {
123
+ minuteCounter.SetValue (displaySeconds.Get ().count () / 60 );
124
+ secondCounter.SetValue (displaySeconds.Get ().count () % 60 );
125
+ }
126
+ }
127
+
122
128
void Timer::SetTimerRunning () {
123
129
minuteCounter.HideControls ();
124
130
secondCounter.HideControls ();
@@ -133,9 +139,7 @@ void Timer::SetTimerStopped() {
133
139
134
140
void Timer::ToggleRunning () {
135
141
if (timer.IsRunning ()) {
136
- auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
137
- minuteCounter.SetValue (secondsRemaining.count () / 60 );
138
- secondCounter.SetValue (secondsRemaining.count () % 60 );
142
+ DisplayTime ();
139
143
timer.StopTimer ();
140
144
SetTimerStopped ();
141
145
} else if (secondCounter.GetValue () + minuteCounter.GetValue () > 0 ) {
@@ -147,7 +151,6 @@ void Timer::ToggleRunning() {
147
151
}
148
152
149
153
void Timer::Reset () {
150
- minuteCounter.SetValue (0 );
151
- secondCounter.SetValue (0 );
154
+ DisplayTime ();
152
155
SetTimerStopped ();
153
156
}
0 commit comments