@@ -110,21 +110,21 @@ StopWatch::StopWatch(DisplayApp* app, System::SystemTask& systemTask, Controller
110110 taskRefresh = lv_task_create (RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this );
111111
112112 if (stopWatchController.isRunning ()) {
113- start ();
113+ displayRunning ();
114114 } else if (stopWatchController.isPaused ()) {
115- pause ();
115+ displayPaused ();
116116 currentTimeSeparated = convertTicksToTimeSegments (stopWatchController.getElapsedPreviously ());
117117
118118 lv_label_set_text_fmt (time, " %02d:%02d" , currentTimeSeparated.mins , currentTimeSeparated.secs );
119119 lv_label_set_text_fmt (msecTime, " %02d" , currentTimeSeparated.hundredths );
120120 lv_obj_set_state (btnStopLap, LV_STATE_DEFAULT);
121121 lv_obj_set_state (txtStopLap, LV_STATE_DEFAULT);
122122 } else {
123- reset ();
123+ displayCleared ();
124124 }
125125
126126 if (stopWatchController.getLapCount () > 0 ) {
127- refreshLaps ();
127+ updateLaps ();
128128 }
129129}
130130
@@ -134,7 +134,7 @@ StopWatch::~StopWatch() {
134134 lv_obj_clean (lv_scr_act ());
135135}
136136
137- void StopWatch::reset () {
137+ void StopWatch::displayCleared () {
138138 lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
139139 lv_obj_set_style_local_text_color (msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
140140
@@ -148,7 +148,7 @@ void StopWatch::reset() {
148148 lv_obj_set_state (txtStopLap, LV_STATE_DISABLED);
149149}
150150
151- void StopWatch::start () {
151+ void StopWatch::displayRunning () {
152152 lv_obj_set_state (btnStopLap, LV_STATE_DEFAULT);
153153 lv_obj_set_state (txtStopLap, LV_STATE_DEFAULT);
154154 lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
@@ -159,7 +159,7 @@ void StopWatch::start() {
159159 systemTask.PushMessage (Pinetime::System::Messages::DisableSleeping);
160160}
161161
162- void StopWatch::pause () {
162+ void StopWatch::displayPaused () {
163163 lv_obj_set_state (btnStopLap, LV_STATE_DEFAULT);
164164
165165 lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
@@ -171,18 +171,7 @@ void StopWatch::pause() {
171171 systemTask.PushMessage (Pinetime::System::Messages::EnableSleeping);
172172}
173173
174- void StopWatch::Refresh () {
175- lv_label_set_text_fmt (dateTime, " %02i:%02i" , dateTimeController.Hours (), dateTimeController.Minutes ());
176- if (stopWatchController.isRunning ()) {
177- timeElapsed = calculateDelta (stopWatchController.getStart (), xTaskGetTickCount ());
178- currentTimeSeparated = convertTicksToTimeSegments ((stopWatchController.getElapsedPreviously () + timeElapsed));
179-
180- lv_label_set_text_fmt (time, " %02d:%02d" , currentTimeSeparated.mins , currentTimeSeparated.secs );
181- lv_label_set_text_fmt (msecTime, " %02d" , currentTimeSeparated.hundredths );
182- }
183- }
184-
185- void StopWatch::refreshLaps () {
174+ void StopWatch::updateLaps () {
186175 Pinetime::Controllers::LapInfo_t *lap1 = stopWatchController.lastLap ();
187176 Pinetime::Controllers::LapInfo_t *lap2 = stopWatchController.lastLap (1 );
188177
@@ -208,16 +197,27 @@ void StopWatch::refreshLaps() {
208197 }
209198}
210199
200+ void StopWatch::Refresh () {
201+ lv_label_set_text_fmt (dateTime, " %02i:%02i" , dateTimeController.Hours (), dateTimeController.Minutes ());
202+ if (stopWatchController.isRunning ()) {
203+ timeElapsed = calculateDelta (stopWatchController.getStart (), xTaskGetTickCount ());
204+ currentTimeSeparated = convertTicksToTimeSegments ((stopWatchController.getElapsedPreviously () + timeElapsed));
205+
206+ lv_label_set_text_fmt (time, " %02d:%02d" , currentTimeSeparated.mins , currentTimeSeparated.secs );
207+ lv_label_set_text_fmt (msecTime, " %02d" , currentTimeSeparated.hundredths );
208+ }
209+ }
210+
211211void StopWatch::playPauseBtnEventHandler (lv_event_t event) {
212212 if (event != LV_EVENT_CLICKED) {
213213 return ;
214214 }
215215 if (stopWatchController.isCleared () || stopWatchController.isPaused ()) {
216216 stopWatchController.start (xTaskGetTickCount ());
217- start ();
217+ displayRunning ();
218218 } else if (stopWatchController.isRunning ()) {
219219 stopWatchController.pause (xTaskGetTickCount ());
220- pause ();
220+ displayPaused ();
221221 }
222222}
223223
@@ -227,30 +227,12 @@ void StopWatch::stopLapBtnEventHandler(lv_event_t event) {
227227 }
228228 // If running, then this button is used to save laps
229229 if (stopWatchController.isRunning ()) {
230- // lapBuffer.addLaps(currentTimeSeparated);
231- // lapNr++;
232- // if (lapBuffer[1]) {
233- // lv_label_set_text_fmt(
234- // lapOneText, "#%2d %2d:%02d.%02d", (lapNr - 1), lapBuffer[1]->mins, lapBuffer[1]->secs, lapBuffer[1]->hundredths);
235- // }
236- // if (lapBuffer[0]) {
237- // lv_label_set_text_fmt(lapTwoText, "#%2d %2d:%02d.%02d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->hundredths);
238- // }
239230 TickType_t currentTime = stopWatchController.getElapsedPreviously () + calculateDelta (stopWatchController.getStart (), xTaskGetTickCount ());
240231 stopWatchController.pushLap (currentTime);
241232
242- refreshLaps ();
233+ updateLaps ();
243234 } else if (stopWatchController.isPaused ()) {
244235 stopWatchController.clear ();
245- reset ();
246- }
247- }
248-
249- bool StopWatch::OnButtonPushed () {
250- if (stopWatchController.isRunning ()) {
251- stopWatchController.pause (xTaskGetTickCount ());
252- pause ();
253- return true ;
236+ displayCleared ();
254237 }
255- return false ;
256238}
0 commit comments