Skip to content

Commit a4a0a4c

Browse files
author
Louis Pearson
committed
Prevent lap count check when watch is stopped
1 parent c7c6309 commit a4a0a4c

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/displayapp/screens/StopWatch.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ StopWatch::StopWatch(DisplayApp* app,
6363
lv_label_set_text(time, "00:00");
6464
lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -45);
6565

66+
// Create millisecond label
6667
msecTime = lv_label_create(lv_scr_act(), nullptr);
67-
// lv_obj_set_style_local_text_font(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
6868
lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
6969
lv_label_set_text(msecTime, "00");
7070
lv_obj_align(msecTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 3);
7171

72+
// Create play/pause button
7273
btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
7374
btnPlayPause->user_data = this;
7475
lv_obj_set_event_cb(btnPlayPause, play_pause_event_handler);
@@ -78,6 +79,7 @@ StopWatch::StopWatch(DisplayApp* app,
7879
txtPlayPause = lv_label_create(btnPlayPause, nullptr);
7980
lv_label_set_text(txtPlayPause, Symbols::play);
8081

82+
// Create stop/lap button
8183
btnStopLap = lv_btn_create(lv_scr_act(), nullptr);
8284
btnStopLap->user_data = this;
8385
lv_obj_set_event_cb(btnStopLap, stop_lap_event_handler);
@@ -91,19 +93,19 @@ StopWatch::StopWatch(DisplayApp* app,
9193
lv_obj_set_state(btnStopLap, LV_STATE_DISABLED);
9294
lv_obj_set_state(txtStopLap, LV_STATE_DISABLED);
9395

96+
// Create first lap text label
9497
lapOneText = lv_label_create(lv_scr_act(), nullptr);
95-
// lv_obj_set_style_local_text_font(lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
9698
lv_obj_set_style_local_text_color(lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
9799
lv_obj_align(lapOneText, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 50, 30);
98100
lv_label_set_text(lapOneText, "");
99101

102+
// Create second lap text label
100103
lapTwoText = lv_label_create(lv_scr_act(), nullptr);
101-
// lv_obj_set_style_local_text_font(lapTwoText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
102104
lv_obj_set_style_local_text_color(lapTwoText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
103105
lv_obj_align(lapTwoText, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 50, 55);
104106
lv_label_set_text(lapTwoText, "");
105107

106-
// Date time
108+
// Create Date time label
107109
dateTime = lv_label_create(lv_scr_act(), nullptr);
108110
lv_label_set_text_fmt(dateTime, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
109111
lv_label_set_align(dateTime, LV_LABEL_ALIGN_CENTER);
@@ -112,22 +114,26 @@ StopWatch::StopWatch(DisplayApp* app,
112114

113115
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
114116

115-
if (stopWatchController.isRunning()) {
116-
displayRunning();
117-
} else if (stopWatchController.isPaused()) {
118-
displayPaused();
119-
currentTimeSeparated = convertTicksToTimeSegments(stopWatchController.getElapsedPreviously());
120-
121-
lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs);
122-
lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths);
123-
lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
124-
lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT);
125-
} else {
117+
// Figure out what the current state of the stopwatch is and select the correct display
118+
if (stopWatchController.isCleared()) {
126119
displayCleared();
127-
}
120+
} else {
121+
// Add laps if there are any
122+
if (stopWatchController.getLapCount() > 0) {
123+
updateLaps();
124+
}
128125

129-
if (stopWatchController.getLapCount() > 0) {
130-
updateLaps();
126+
if (stopWatchController.isRunning()) {
127+
displayRunning();
128+
} else if (stopWatchController.isPaused()) {
129+
displayPaused();
130+
currentTimeSeparated = convertTicksToTimeSegments(stopWatchController.getElapsedPreviously());
131+
132+
lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs);
133+
lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths);
134+
lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
135+
lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT);
136+
}
131137
}
132138
}
133139

0 commit comments

Comments
 (0)