6
6
7
7
using namespace Pinetime ::Applications::Screens;
8
8
9
+ static std::chrono::seconds lastTimer;
10
+
9
11
static void btnEventHandler (lv_obj_t * obj, lv_event_t event) {
10
12
auto * screen = static_cast <Timer*>(obj->user_data );
11
13
if (event == LV_EVENT_PRESSED) {
@@ -27,6 +29,7 @@ Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
27
29
28
30
minuteCounter.Create ();
29
31
secondCounter.Create ();
32
+ SetCounters (lastTimer);
30
33
lv_obj_align (minuteCounter.GetObject (), nullptr , LV_ALIGN_IN_TOP_LEFT, 0 , 0 );
31
34
lv_obj_align (secondCounter.GetObject (), nullptr , LV_ALIGN_IN_TOP_RIGHT, 0 , 0 );
32
35
@@ -105,8 +108,7 @@ void Timer::UpdateMask() {
105
108
void Timer::Refresh () {
106
109
if (timer.IsRunning ()) {
107
110
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
108
- minuteCounter.SetValue (secondsRemaining.count () / 60 );
109
- secondCounter.SetValue (secondsRemaining.count () % 60 );
111
+ SetCounters (secondsRemaining);
110
112
} else if (buttonPressing && xTaskGetTickCount () > pressTime + pdMS_TO_TICKS (150 )) {
111
113
lv_label_set_text_static (txtPlayPause, " Reset" );
112
114
maskPosition += 15 ;
@@ -131,23 +133,36 @@ void Timer::SetTimerStopped() {
131
133
lv_label_set_text_static (txtPlayPause, " Start" );
132
134
}
133
135
136
+ void Timer::SetCounters (std::chrono::seconds& duration) {
137
+ minuteCounter.SetValue (duration.count () / 60 );
138
+ secondCounter.SetValue (duration.count () % 60 );
139
+ }
140
+
134
141
void Timer::ToggleRunning () {
135
142
if (timer.IsRunning ()) {
136
143
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining ());
137
- minuteCounter.SetValue (secondsRemaining.count () / 60 );
138
- secondCounter.SetValue (secondsRemaining.count () % 60 );
144
+ if (secondsRemaining == std::chrono::seconds::zero ()) {
145
+ secondsRemaining = lastTimer;
146
+ }
147
+ SetCounters (secondsRemaining);
139
148
timer.StopTimer ();
140
149
SetTimerStopped ();
150
+ lastTimer = secondsRemaining;
141
151
} else if (secondCounter.GetValue () + minuteCounter.GetValue () > 0 ) {
142
152
auto timerDuration = std::chrono::minutes (minuteCounter.GetValue ()) + std::chrono::seconds (secondCounter.GetValue ());
143
153
timer.StartTimer (timerDuration);
144
154
Refresh ();
145
155
SetTimerRunning ();
156
+ lastTimer = timerDuration;
146
157
}
147
158
}
148
159
149
160
void Timer::Reset () {
150
- minuteCounter.SetValue (0 );
151
- secondCounter.SetValue (0 );
161
+ lastTimer = std::chrono::seconds::zero ();
162
+ Stop ();
163
+ }
164
+
165
+ void Timer::Stop () {
166
+ SetCounters (lastTimer);
152
167
SetTimerStopped ();
153
168
}
0 commit comments