diff options
| author | panky-codes <pankaj.sarathy1992@gmail.com> | 2021-03-13 12:59:54 (GMT) |
|---|---|---|
| committer | panky-codes <pankaj.sarathy1992@gmail.com> | 2021-03-13 12:59:54 (GMT) |
| commit | 5d57b9054a9d30d8724fac87108d68a4f2c95e68 (patch) | |
| tree | d56ab2ef8fa9b59d69fe5ad447402c2020e32831 /src/displayapp/screens/StopWatch.h | |
| parent | 00f2a053bf65058465c8b2f6913a66e85dbd6864 (diff) | |
Adding laps completed.
Diffstat (limited to 'src/displayapp/screens/StopWatch.h')
| -rw-r--r-- | src/displayapp/screens/StopWatch.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h index c1dd0af..0d425f7 100644 --- a/src/displayapp/screens/StopWatch.h +++ b/src/displayapp/screens/StopWatch.h @@ -26,20 +26,27 @@ namespace Pinetime::Applications::Screens { } void addLaps(const TimeSeparated_t& timeVal) { + head++; head %= capacity; - _arr[head++] = timeVal; + _arr[head] = timeVal; if (currentSz < capacity) { currentSz++; } } + void clearBuffer() { + _arr = {}; + currentSz = 0; + head = -1; + } + // Optional return type would be much more appropriate here TimeSeparated_t* operator[](std::size_t idx) { // Sanity check for out-of-bounds if (idx >= 0 && idx < capacity) { if (idx < currentSz) { - const auto transformed_idx = (head + capacity - idx) % capacity; + const auto transformed_idx = (head - idx) % capacity; return (&_arr[transformed_idx]); } } |
