66
77using namespace Pinetime ::Applications::Screens;
88
9+ static std::chrono::seconds lastTimer;
10+
911static void btnEventHandler (lv_obj_t * obj, lv_event_t event) {
1012 auto * screen = static_cast <Timer*>(obj->user_data );
1113 if (event == LV_EVENT_PRESSED) {
@@ -27,6 +29,7 @@ Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
2729
2830 minuteCounter.Create ();
2931 secondCounter.Create ();
32+ SetCounters (lastTimer);
3033 lv_obj_align (minuteCounter.GetObject (), nullptr , LV_ALIGN_IN_TOP_LEFT, 0 , 0 );
3134 lv_obj_align (secondCounter.GetObject (), nullptr , LV_ALIGN_IN_TOP_RIGHT, 0 , 0 );
3235
@@ -105,8 +108,7 @@ void Timer::UpdateMask() {
105108void Timer::Refresh () {
106109 if (timer.IsRunning ()) {
107110 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);
110112 } else if (buttonPressing && xTaskGetTickCount () > pressTime + pdMS_TO_TICKS (150 )) {
111113 lv_label_set_text_static (txtPlayPause, " Reset" );
112114 maskPosition += 15 ;
@@ -131,23 +133,36 @@ void Timer::SetTimerStopped() {
131133 lv_label_set_text_static (txtPlayPause, " Start" );
132134}
133135
136+ void Timer::SetCounters (std::chrono::seconds &duration) {
137+ minuteCounter.SetValue (duration.count () / 60 );
138+ secondCounter.SetValue (duration.count () % 60 );
139+ }
140+
134141void Timer::ToggleRunning () {
135142 if (timer.IsRunning ()) {
136143 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);
139148 timer.StopTimer ();
140149 SetTimerStopped ();
150+ lastTimer = secondsRemaining;
141151 } else if (secondCounter.GetValue () + minuteCounter.GetValue () > 0 ) {
142152 auto timerDuration = std::chrono::minutes (minuteCounter.GetValue ()) + std::chrono::seconds (secondCounter.GetValue ());
143153 timer.StartTimer (timerDuration);
144154 Refresh ();
145155 SetTimerRunning ();
156+ lastTimer = timerDuration;
146157 }
147158}
148159
149160void 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);
152167 SetTimerStopped ();
153168}
0 commit comments