Skip to content

Commit d3820f3

Browse files
committed
upper bound for lap numbers
1 parent 0d0af6e commit d3820f3

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/components/stopwatch/StopWatchController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void StopWatchController::Clear() {
3434
void StopWatchController::AddLapToHistory() {
3535
TickType_t lapEnd = GetElapsedTime();
3636
history[0].timeSinceStart = lapEnd;
37-
history[0].number = ++maxLapNumber;
37+
history[0].number = ++maxLapNumber % lapNumberBoundary;
3838
history--;
3939
}
4040

src/components/stopwatch/StopWatchController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ namespace Pinetime {
5555

5656
// Maximum number of stored laps
5757
static constexpr int histSize = 2;
58+
static constexpr int lapNumberBoundary = 1000;
5859
// Lap storage
5960
Utility::CircularBuffer<LapInfo, histSize> history;
60-
// Highest lap number; may exceed histSize
61+
// Highest lap number; less than lapNumberBoundary, may exceed histSize
6162
int maxLapNumber;
6263
};
6364
}

src/displayapp/screens/StopWatch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ void StopWatch::RenderLaps() {
181181
if (lap) {
182182
TimeSeparated laptime = ConvertTicksToTimeSegments(lap->timeSinceStart);
183183
char buffer[16];
184-
sprintf(buffer, "#%2d %2d:%02d.%02d\n", lap->number, laptime.mins, laptime.secs, laptime.hundredths);
184+
snprintf(buffer, sizeof(buffer), "#%3d %2d:%02d.%02d\n",
185+
lap->number, laptime.mins, laptime.secs, laptime.hundredths);
185186
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, buffer);
186187
} else {
187188
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, "\n");

0 commit comments

Comments
 (0)