diff options
| author | codingjourney <coding@journey.sk> | 2024-10-23 23:29:00 +0200 |
|---|---|---|
| committer | JF <JF002@users.noreply.github.com> | 2025-11-04 21:25:31 +0100 |
| commit | f28aca75419ebaae55b34b688f4d3b9d2f913246 (patch) | |
| tree | bf8378d19599a26ce964ece21804934ee19b825a /src/components/stopwatch/StopWatchController.h | |
| parent | db5d4704cc4a7361c80d1eab199af268364545c7 (diff) | |
minor fixes:
* more consistent function names
* lapCapacity as constexpr
* LastLap returns std::optional
* simplified handling of TickType_t values
* removed unused methods
* minor fix in lap rendering
Diffstat (limited to 'src/components/stopwatch/StopWatchController.h')
| -rw-r--r-- | src/components/stopwatch/StopWatchController.h | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/components/stopwatch/StopWatchController.h b/src/components/stopwatch/StopWatchController.h index 0aaeb5ca..c549a71e 100644 --- a/src/components/stopwatch/StopWatchController.h +++ b/src/components/stopwatch/StopWatchController.h @@ -1,10 +1,9 @@ #pragma once #include <FreeRTOS.h> +#include <optional> #include <timers.h> -#define LAP_CAPACITY 2 - namespace Pinetime { namespace System { class SystemTask; @@ -18,6 +17,8 @@ namespace Pinetime { TickType_t time = 0; // Delta time from beginning of stopwatch }; + constexpr int lapCapacity = 2; + class StopWatchController { public: StopWatchController(); @@ -34,22 +35,17 @@ namespace Pinetime { /// Only the latest laps are stored, the lap count is saved until reset void PushLap(); - /// Returns actual count of stored laps - int GetLapNum(); - /// Returns lapCount int GetLapCount(); /// Indexes into lap history, with 0 being the latest lap. - /// If the lap is unavailable, count and time will be 0. If there is a - /// real value, count should be above 0 - LapInfo* LastLap(int lap = 0); + std::optional<LapInfo> LastLap(int lap = 0); bool IsRunning(); bool IsCleared(); bool IsPaused(); - private: + // private: // Current state of stopwatch StopWatchStates currentState = StopWatchStates::Cleared; // Start time of current duration @@ -57,9 +53,10 @@ namespace Pinetime { // How much time was elapsed before current duration TickType_t timeElapsedPreviously = 0; // Stores lap times - LapInfo laps[LAP_CAPACITY]; - LapInfo emptyLapInfo = {.count = 0, .time = 0}; + LapInfo laps[lapCapacity]; + // Total lap count; may exceed lapCapacity int lapCount = 0; + // Index for next lap time; must be lower than lapCapacity int lapHead = 0; }; } |
