diff options
author | panky-codes <pankaj.sarathy1992@gmail.com> | 2021-03-12 20:24:53 +0100 |
---|---|---|
committer | panky-codes <pankaj.sarathy1992@gmail.com> | 2021-03-12 20:24:53 +0100 |
commit | 00f2a053bf65058465c8b2f6913a66e85dbd6864 (patch) | |
tree | 5b098c890662ae365a7d09e314a32b69e071ccc9 /src/displayapp/screens/StopWatch.h | |
parent | a090664a4c1709a7925621632e579632e3f1e39a (diff) |
Laps introduced. Tested. Need to change the icon.
Diffstat (limited to 'src/displayapp/screens/StopWatch.h')
-rw-r--r-- | src/displayapp/screens/StopWatch.h | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h index 929813f8..c1dd0af9 100644 --- a/src/displayapp/screens/StopWatch.h +++ b/src/displayapp/screens/StopWatch.h @@ -7,6 +7,8 @@ #include "FreeRTOS.h" #include "portmacro_cmsis.h" +#include <array> + namespace Pinetime::Applications::Screens { enum class States { INIT, RUNNING, HALTED }; @@ -19,6 +21,38 @@ namespace Pinetime::Applications::Screens { int msecs; }; + template <int N> struct LapTextBuffer_t { + LapTextBuffer_t() : _arr {}, currentSz {}, capacity {N}, head {-1} { + } + + void addLaps(const TimeSeparated_t& timeVal) { + head %= capacity; + _arr[head++] = timeVal; + + if (currentSz < capacity) { + currentSz++; + } + } + + // 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; + return (&_arr[transformed_idx]); + } + } + return nullptr; + } + + private: + std::array<TimeSeparated_t, N> _arr; + uint8_t currentSz; + uint8_t capacity; + int8_t head; + }; + class StopWatch : public Screen { public: StopWatch(DisplayApp* app, const Pinetime::Controllers::DateTime& dateTime); @@ -36,8 +70,10 @@ namespace Pinetime::Applications::Screens { Events currentEvent; TickType_t startTime; TickType_t oldTimeElapsed; - TimeSeparated_t timeSeparated; // Holds Mins, Secs, millisecs + TimeSeparated_t currentTimeSeparated; // Holds Mins, Secs, millisecs + LapTextBuffer_t<2> lapBuffer; int lapNr; + bool lapPressed; lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap; lv_obj_t *lapOneText, *lapTwoText; }; |