Skip to content

Commit fd019c7

Browse files
mark9064JF002
authored andcommitted
Use DirtyValue for timer
1 parent 975bfc5 commit fd019c7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/displayapp/screens/Timer.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ void Timer::UpdateMask() {
104104

105105
void 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+
122128
void Timer::SetTimerRunning() {
123129
minuteCounter.HideControls();
124130
secondCounter.HideControls();
@@ -133,9 +139,7 @@ void Timer::SetTimerStopped() {
133139

134140
void 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

149153
void Timer::Reset() {
150-
minuteCounter.SetValue(0);
151-
secondCounter.SetValue(0);
154+
DisplayTime();
152155
SetTimerStopped();
153156
}

src/displayapp/screens/Timer.h

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "systemtask/SystemTask.h"
66
#include "displayapp/LittleVgl.h"
77
#include "displayapp/widgets/Counter.h"
8+
#include "utility/DirtyValue.h"
89
#include <lvgl/lvgl.h>
910

1011
#include "components/timer/Timer.h"
@@ -26,6 +27,7 @@ namespace Pinetime::Applications {
2627
void SetTimerRunning();
2728
void SetTimerStopped();
2829
void UpdateMask();
30+
void DisplayTime();
2931
Pinetime::Controllers::Timer& timer;
3032

3133
lv_obj_t* btnPlayPause;
@@ -43,6 +45,7 @@ namespace Pinetime::Applications {
4345
bool buttonPressing = false;
4446
lv_coord_t maskPosition = 0;
4547
TickType_t pressTime = 0;
48+
Utility::DirtyValue<std::chrono::seconds> displaySeconds;
4649
};
4750
}
4851

0 commit comments

Comments
 (0)