| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /** | |||
| 2 | * @file timer.h | |||
| 3 | */ | |||
| 4 | ||||
| 5 | #pragma once | |||
| 6 | ||||
| 7 | #include <rusefi/rusefi_time_types.h> | |||
| 8 | ||||
| 9 | /** | |||
| 10 | * Helper class with "has X amount of time elapsed since most recent reset" methods | |||
| 11 | * Brand new instances have most recent reset time far in the past, i.e. "hasElapse" is true for any reasonable range | |||
| 12 | */ | |||
| 13 | class Timer final { | |||
| 14 | public: | |||
| 15 | 55602 | Timer() = default; | ||
| 16 | ||||
| 17 | void reset(); | |||
| 18 | ||||
| 19 | // Reset the timer to a known timestamp (don't take a timestamp internally) | |||
| 20 | void reset(efitick_t nowNt); | |||
| 21 | ||||
| 22 | // returns timer to the most original-as-constructed state | |||
| 23 | void init(); | |||
| 24 | ||||
| 25 | [[nodiscard]] bool hasElapsedSec(float seconds) const; | |||
| 26 | [[nodiscard]] bool hasElapsedMs(float ms) const; | |||
| 27 | [[nodiscard]] bool hasElapsedUs(float us) const; | |||
| 28 | ||||
| 29 | // Return the elapsed time since the last reset. | |||
| 30 | // If the elapsed time is longer than 2^32 timer tick counts, | |||
| 31 | // then a time period representing 2^32 counts will be returned. | |||
| 32 | [[nodiscard]] float getElapsedSeconds() const; | |||
| 33 | [[nodiscard]] float getElapsedSeconds(efitick_t nowNt) const; | |||
| 34 | [[nodiscard]] float getElapsedUs() const; | |||
| 35 | // WOW yes returns US while parameter is NT | |||
| 36 | [[nodiscard]] float getElapsedUs(efitick_t nowNt) const; | |||
| 37 | // too many options for the API probably? | |||
| 38 | [[nodiscard]] uint32_t getElapsedNt(efitick_t nowNt) const; | |||
| 39 | ||||
| 40 | // Perform an atomic update event based on the passed timestamp, | |||
| 41 | // returning the delta between the last reset and the provided timestamp | |||
| 42 | [[nodiscard]] float getElapsedSecondsAndReset(efitick_t nowNt); | |||
| 43 | ||||
| 44 | [[nodiscard]] efitick_t get() const; | |||
| 45 | ||||
| 46 | static constexpr efitick_t InitialState = INT64_MIN / 8; | |||
| 47 | ||||
| 48 | private: | |||
| 49 | efitick_t m_lastReset{InitialState}; | |||
| 50 | }; | |||
| 51 |