@@ -104,9 +104,7 @@ void Timer::UpdateMask() {
104104
105105void Timer::Refresh () {
106106 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 ();
110108 } else if (buttonPressing && xTaskGetTickCount () > pressTime + pdMS_TO_TICKS (150 )) {
111109 lv_label_set_text_static (txtPlayPause, " Reset" );
112110 maskPosition += 15 ;
@@ -119,6 +117,14 @@ void Timer::Refresh() {
119117 }
120118}
121119
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+
122128void Timer::SetTimerRunning () {
123129 minuteCounter.HideControls ();
124130 secondCounter.HideControls ();
@@ -133,9 +139,7 @@ void Timer::SetTimerStopped() {
133139
134140void Timer::ToggleRunning () {
135141 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 ();
139143 timer.StopTimer ();
140144 SetTimerStopped ();
141145 } else if (secondCounter.GetValue () + minuteCounter.GetValue () > 0 ) {
@@ -147,7 +151,6 @@ void Timer::ToggleRunning() {
147151}
148152
149153void Timer::Reset () {
150- minuteCounter.SetValue (0 );
151- secondCounter.SetValue (0 );
154+ DisplayTime ();
152155 SetTimerStopped ();
153156}
0 commit comments