From f720a7fb3ce40880319ceba79eb00a9699dbc1ef Mon Sep 17 00:00:00 2001 From: codingjourney Date: Thu, 28 Nov 2024 05:19:34 +0100 Subject: upper bound for lap numbers --- src/components/stopwatch/StopWatchController.cpp | 2 +- src/components/stopwatch/StopWatchController.h | 3 ++- src/displayapp/screens/StopWatch.cpp | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/components/stopwatch/StopWatchController.cpp b/src/components/stopwatch/StopWatchController.cpp index 7af80367..311bccc7 100644 --- a/src/components/stopwatch/StopWatchController.cpp +++ b/src/components/stopwatch/StopWatchController.cpp @@ -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--; } diff --git a/src/components/stopwatch/StopWatchController.h b/src/components/stopwatch/StopWatchController.h index 800ca1b3..0791701c 100644 --- a/src/components/stopwatch/StopWatchController.h +++ b/src/components/stopwatch/StopWatchController.h @@ -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 history; - // Highest lap number; may exceed histSize + // Highest lap number; less than lapNumberBoundary, may exceed histSize int maxLapNumber; }; } diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp index 710c4d44..08bc5ddd 100644 --- a/src/displayapp/screens/StopWatch.cpp +++ b/src/displayapp/screens/StopWatch.cpp @@ -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"); -- cgit v1.2.3-70-g09d2