From 5d57b9054a9d30d8724fac87108d68a4f2c95e68 Mon Sep 17 00:00:00 2001 From: panky-codes Date: Sat, 13 Mar 2021 13:59:54 +0100 Subject: Adding laps completed. --- src/displayapp/screens/StopWatch.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/displayapp/screens/StopWatch.h') diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h index c1dd0af9..0d425f72 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]); } } -- cgit v1.2.3-70-g09d2