6
6
7
7
using namespace Pinetime ::Applications::Screens;
8
8
9
+ static std::chrono::milliseconds lastTimerSetting;
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) {
@@ -17,6 +19,11 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
17
19
}
18
20
}
19
21
22
+ static void counterChangeHandler (void *timerScreen) {
23
+ Timer* timer = (Timer*)timerScreen;
24
+ lastTimerSetting = timer->GetCounters ();
25
+ }
26
+
20
27
Timer::Timer (Controllers::Timer& timerController) : timer {timerController} {
21
28
22
29
lv_obj_t * colonLabel = lv_label_create (lv_scr_act (), nullptr );
@@ -29,6 +36,8 @@ Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
29
36
secondCounter.Create ();
30
37
lv_obj_align (minuteCounter.GetObject (), nullptr , LV_ALIGN_IN_TOP_LEFT, 0 , 0 );
31
38
lv_obj_align (secondCounter.GetObject (), nullptr , LV_ALIGN_IN_TOP_RIGHT, 0 , 0 );
39
+ minuteCounter.SetValueChangedEventCallback (this , counterChangeHandler);
40
+ secondCounter.SetValueChangedEventCallback (this , counterChangeHandler);
32
41
33
42
highlightObjectMask = lv_objmask_create (lv_scr_act (), nullptr );
34
43
lv_obj_set_size (highlightObjectMask, 240 , 50 );
@@ -63,7 +72,7 @@ Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
63
72
64
73
switch (timer.GetState ()) {
65
74
case Controllers::Timer::TimerState::Stopped:
66
- SetCounters (timer. GetLast () );
75
+ SetCounters (lastTimerSetting );
67
76
SetInterfaceStopped ();
68
77
break ;
69
78
case Controllers::Timer::TimerState::Running:
@@ -188,11 +197,14 @@ void Timer::SetCounters(const std::chrono::seconds& duration) {
188
197
secondCounter.SetValue (duration.count () % 60 );
189
198
}
190
199
200
+ std::chrono::seconds Timer::GetCounters () {
201
+ return std::chrono::minutes (minuteCounter.GetValue ()) + std::chrono::seconds (secondCounter.GetValue ());
202
+ }
203
+
191
204
void Timer::ToggleRunning () {
192
205
if (timer.GetState () == Controllers::Timer::TimerState::Stopped) {
193
206
if (secondCounter.GetValue () + minuteCounter.GetValue () > 0 ) {
194
- auto timerDuration = std::chrono::minutes (minuteCounter.GetValue ()) + std::chrono::seconds (secondCounter.GetValue ());
195
- timer.Start (timerDuration);
207
+ timer.Start (GetCounters ());
196
208
Refresh ();
197
209
SetInterfaceRunning ();
198
210
}
@@ -206,12 +218,12 @@ void Timer::ToggleRunning() {
206
218
}
207
219
208
220
void Timer::Reset () {
209
- timer. ResetLast ( );
221
+ lastTimerSetting = std::chrono::seconds ( 0 );
210
222
Stop ();
211
223
}
212
224
213
225
void Timer::Stop () {
214
226
timer.Stop ();
215
- SetCounters (timer. GetLast () );
227
+ SetCounters (lastTimerSetting );
216
228
SetInterfaceStopped ();
217
229
}
0 commit comments