diff options
| author | mark9064 <30447455+mark9064@users.noreply.github.com> | 2024-04-22 23:53:08 +0100 |
|---|---|---|
| committer | JF <JF002@users.noreply.github.com> | 2024-09-14 11:20:47 +0200 |
| commit | fd019c7aada09dc78d72eb599798952d608baeb8 (patch) | |
| tree | 6197c8279ac5cb6ed038ebab0f47145ed27667a9 /src/displayapp/screens/Timer.cpp | |
| parent | 975bfc5420e7e53d134956ca919a29a921942c82 (diff) | |
Use DirtyValue for timer
Diffstat (limited to 'src/displayapp/screens/Timer.cpp')
| -rw-r--r-- | src/displayapp/screens/Timer.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp index a1ede6be..f6d5e73b 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer.cpp @@ -104,9 +104,7 @@ void Timer::UpdateMask() { void Timer::Refresh() { if (timer.IsRunning()) { - auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining()); - minuteCounter.SetValue(secondsRemaining.count() / 60); - secondCounter.SetValue(secondsRemaining.count() % 60); + DisplayTime(); } else if (buttonPressing && xTaskGetTickCount() > pressTime + pdMS_TO_TICKS(150)) { lv_label_set_text_static(txtPlayPause, "Reset"); maskPosition += 15; @@ -119,6 +117,14 @@ void Timer::Refresh() { } } +void Timer::DisplayTime() { + displaySeconds = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining()); + if (displaySeconds.IsUpdated()) { + minuteCounter.SetValue(displaySeconds.Get().count() / 60); + secondCounter.SetValue(displaySeconds.Get().count() % 60); + } +} + void Timer::SetTimerRunning() { minuteCounter.HideControls(); secondCounter.HideControls(); @@ -133,9 +139,7 @@ void Timer::SetTimerStopped() { void Timer::ToggleRunning() { if (timer.IsRunning()) { - auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining()); - minuteCounter.SetValue(secondsRemaining.count() / 60); - secondCounter.SetValue(secondsRemaining.count() % 60); + DisplayTime(); timer.StopTimer(); SetTimerStopped(); } else if (secondCounter.GetValue() + minuteCounter.GetValue() > 0) { @@ -147,7 +151,6 @@ void Timer::ToggleRunning() { } void Timer::Reset() { - minuteCounter.SetValue(0); - secondCounter.SetValue(0); + DisplayTime(); SetTimerStopped(); } |
