upper bound for lap numbers

This commit is contained in:
codingjourney 2024-11-28 05:19:34 +01:00 committed by JF
parent 5c2d4a5151
commit f720a7fb3c
3 changed files with 5 additions and 3 deletions

View File

@ -34,7 +34,7 @@ void StopWatchController::Clear() {
void StopWatchController::AddLapToHistory() {
TickType_t lapEnd = GetElapsedTime();
history[0].timeSinceStart = lapEnd;
history[0].number = ++maxLapNumber;
history[0].number = ++maxLapNumber % lapNumberBoundary;
history--;
}

View File

@ -55,9 +55,10 @@ namespace Pinetime {
// Maximum number of stored laps
static constexpr int histSize = 2;
static constexpr int lapNumberBoundary = 1000;
// Lap storage
Utility::CircularBuffer<LapInfo, histSize> history;
// Highest lap number; may exceed histSize
// Highest lap number; less than lapNumberBoundary, may exceed histSize
int maxLapNumber;
};
}

View File

@ -181,7 +181,8 @@ void StopWatch::RenderLaps() {
if (lap) {
TimeSeparated laptime = ConvertTicksToTimeSegments(lap->timeSinceStart);
char buffer[16];
sprintf(buffer, "#%2d %2d:%02d.%02d\n", lap->number, laptime.mins, laptime.secs, laptime.hundredths);
snprintf(buffer, sizeof(buffer), "#%3d %2d:%02d.%02d\n",
lap->number, laptime.mins, laptime.secs, laptime.hundredths);
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, buffer);
} else {
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, "\n");