Skip to content

Commit 2d8f4d9

Browse files
committed
upper bound for elapsed time
1 parent 93f902a commit 2d8f4d9

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/components/stopwatch/StopWatchController.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ void StopWatchController::Start() {
1414
}
1515

1616
void StopWatchController::Pause() {
17+
timeElapsedPreviously = GetElapsedTime();
1718
currentState = StopWatchStates::Paused;
18-
timeElapsedPreviously += xTaskGetTickCount() - startTime;
1919
}
2020

2121
void StopWatchController::Clear() {
@@ -55,7 +55,8 @@ TickType_t StopWatchController::GetElapsedTime() {
5555
if (!IsRunning()) {
5656
return timeElapsedPreviously;
5757
}
58-
return timeElapsedPreviously + (xTaskGetTickCount() - startTime);
58+
TickType_t delta = xTaskGetTickCount() - startTime;
59+
return (timeElapsedPreviously + delta) % elapsedTimeBoundary;
5960
}
6061

6162
bool StopWatchController::IsRunning() {

src/components/stopwatch/StopWatchController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ namespace Pinetime {
4646
bool IsPaused();
4747

4848
private:
49+
// Time at which stopwatch wraps around to zero (1000 hours)
50+
TickType_t elapsedTimeBoundary = configTICK_RATE_HZ * 60 * 60 * 1000;
4951
// Current state of stopwatch
5052
StopWatchStates currentState = StopWatchStates::Cleared;
5153
// Start time of current duration
@@ -55,6 +57,7 @@ namespace Pinetime {
5557

5658
// Maximum number of stored laps
5759
static constexpr int histSize = 2;
60+
// Value at which lap numbers wrap around to zero
5861
static constexpr int lapNumberBoundary = 1000;
5962
// Lap storage
6063
Utility::CircularBuffer<LapInfo, histSize> history;

0 commit comments

Comments
 (0)