File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ void StopWatchController::Start() {
1414}
1515
1616void StopWatchController::Pause () {
17+ timeElapsedPreviously = GetElapsedTime ();
1718 currentState = StopWatchStates::Paused;
18- timeElapsedPreviously += xTaskGetTickCount () - startTime;
1919}
2020
2121void 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
6162bool StopWatchController::IsRunning () {
Original file line number Diff line number Diff 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;
You can’t perform that action at this time.
0 commit comments