Use DirtyValue for timer

This commit is contained in:
mark9064 2024-04-22 23:53:08 +01:00 committed by JF
parent 975bfc5420
commit fd019c7aad
2 changed files with 14 additions and 8 deletions

View file

@ -104,9 +104,7 @@ void Timer::UpdateMask() {
void Timer::Refresh() { void Timer::Refresh() {
if (timer.IsRunning()) { if (timer.IsRunning()) {
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining()); DisplayTime();
minuteCounter.SetValue(secondsRemaining.count() / 60);
secondCounter.SetValue(secondsRemaining.count() % 60);
} else if (buttonPressing && xTaskGetTickCount() > pressTime + pdMS_TO_TICKS(150)) { } else if (buttonPressing && xTaskGetTickCount() > pressTime + pdMS_TO_TICKS(150)) {
lv_label_set_text_static(txtPlayPause, "Reset"); lv_label_set_text_static(txtPlayPause, "Reset");
maskPosition += 15; 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() { void Timer::SetTimerRunning() {
minuteCounter.HideControls(); minuteCounter.HideControls();
secondCounter.HideControls(); secondCounter.HideControls();
@ -133,9 +139,7 @@ void Timer::SetTimerStopped() {
void Timer::ToggleRunning() { void Timer::ToggleRunning() {
if (timer.IsRunning()) { if (timer.IsRunning()) {
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining()); DisplayTime();
minuteCounter.SetValue(secondsRemaining.count() / 60);
secondCounter.SetValue(secondsRemaining.count() % 60);
timer.StopTimer(); timer.StopTimer();
SetTimerStopped(); SetTimerStopped();
} else if (secondCounter.GetValue() + minuteCounter.GetValue() > 0) { } else if (secondCounter.GetValue() + minuteCounter.GetValue() > 0) {
@ -147,7 +151,6 @@ void Timer::ToggleRunning() {
} }
void Timer::Reset() { void Timer::Reset() {
minuteCounter.SetValue(0); DisplayTime();
secondCounter.SetValue(0);
SetTimerStopped(); SetTimerStopped();
} }

View file

@ -5,6 +5,7 @@
#include "systemtask/SystemTask.h" #include "systemtask/SystemTask.h"
#include "displayapp/LittleVgl.h" #include "displayapp/LittleVgl.h"
#include "displayapp/widgets/Counter.h" #include "displayapp/widgets/Counter.h"
#include "utility/DirtyValue.h"
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include "components/timer/Timer.h" #include "components/timer/Timer.h"
@ -26,6 +27,7 @@ namespace Pinetime::Applications {
void SetTimerRunning(); void SetTimerRunning();
void SetTimerStopped(); void SetTimerStopped();
void UpdateMask(); void UpdateMask();
void DisplayTime();
Pinetime::Controllers::Timer& timer; Pinetime::Controllers::Timer& timer;
lv_obj_t* btnPlayPause; lv_obj_t* btnPlayPause;
@ -43,6 +45,7 @@ namespace Pinetime::Applications {
bool buttonPressing = false; bool buttonPressing = false;
lv_coord_t maskPosition = 0; lv_coord_t maskPosition = 0;
TickType_t pressTime = 0; TickType_t pressTime = 0;
Utility::DirtyValue<std::chrono::seconds> displaySeconds;
}; };
} }