Skip to content

Commit 3f524e5

Browse files
author
Louis Pearson
committed
Fix stopwatch display issues
1 parent e087cda commit 3f524e5

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/displayapp/screens/StopWatch.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ StopWatch::StopWatch(DisplayApp* app, System::SystemTask& systemTask, Controller
110110
lv_obj_set_style_local_text_color(dateTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
111111

112112
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
113+
114+
if (stopWatchController.isRunning()) {
115+
start();
116+
} else if (stopWatchController.isPaused()) {
117+
pause();
118+
currentTimeSeparated = convertTicksToTimeSegments(stopWatchController.getElapsedPreviously());
119+
120+
lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs);
121+
lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths);
122+
lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
123+
lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT);
124+
}
113125
}
114126

115127
StopWatch::~StopWatch() {
@@ -119,8 +131,6 @@ StopWatch::~StopWatch() {
119131
}
120132

121133
void StopWatch::reset() {
122-
stopWatchController.clear();
123-
124134
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
125135
lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
126136

@@ -136,8 +146,6 @@ void StopWatch::reset() {
136146
}
137147

138148
void StopWatch::start() {
139-
stopWatchController.start(xTaskGetTickCount());
140-
141149
lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
142150
lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT);
143151
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
@@ -149,13 +157,14 @@ void StopWatch::start() {
149157
}
150158

151159
void StopWatch::pause() {
152-
stopWatchController.pause(xTaskGetTickCount());
160+
lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
153161

154-
lv_label_set_text(txtPlayPause, Symbols::play);
155-
lv_label_set_text(txtStopLap, Symbols::stop);
156162
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
157163
lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
158164

165+
lv_label_set_text(txtPlayPause, Symbols::play);
166+
lv_label_set_text(txtStopLap, Symbols::stop);
167+
159168
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
160169
}
161170

@@ -176,8 +185,10 @@ void StopWatch::playPauseBtnEventHandler(lv_event_t event) {
176185
}
177186
if (stopWatchController.isCleared() || stopWatchController.isPaused()) {
178187
stopWatchController.start(xTaskGetTickCount());
188+
start();
179189
} else if (stopWatchController.isRunning()) {
180190
stopWatchController.pause(xTaskGetTickCount());
191+
pause();
181192
}
182193
}
183194

@@ -197,13 +208,15 @@ void StopWatch::stopLapBtnEventHandler(lv_event_t event) {
197208
lv_label_set_text_fmt(lapTwoText, "#%2d %2d:%02d.%02d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->hundredths);
198209
}
199210
} else if (stopWatchController.isPaused()) {
211+
stopWatchController.clear();
200212
reset();
201213
}
202214
}
203215

204216
bool StopWatch::OnButtonPushed() {
205217
if (stopWatchController.isRunning()) {
206218
stopWatchController.pause(xTaskGetTickCount());
219+
pause();
207220
return true;
208221
}
209222
return false;

0 commit comments

Comments
 (0)