From cac2b9ae40ce8fff508da9639c1d3e2cf9f565db Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sat, 2 Jul 2022 21:09:36 +0200 Subject: [PATCH] Implement timer elapsed function also fix build --- Firmware/Timer.cpp | 13 +++++++++++++ Firmware/Timer.h | 1 + 2 files changed, 14 insertions(+) diff --git a/Firmware/Timer.cpp b/Firmware/Timer.cpp index a94a8586..f63bf296 100644 --- a/Firmware/Timer.cpp +++ b/Firmware/Timer.cpp @@ -64,5 +64,18 @@ bool Timer::expired(T msPeriod) return expired; } +/** + * @brief Ticks since the timer was started + * + * This function returns 0 if the timer is not started. Otherwise, it returns + * the time in milliseconds since the timer was started. + * This function is expected to handle wrap around of time register well. + * The maximum elapsed time is dictated by the template type + */ +template +T Timer::elapsed() { + return m_isRunning ? (_millis() - m_started) : 0; +} + template class Timer; template class Timer; diff --git a/Firmware/Timer.h b/Firmware/Timer.h index 599371b4..dcff5223 100644 --- a/Firmware/Timer.h +++ b/Firmware/Timer.h @@ -22,6 +22,7 @@ public: void stop(){m_isRunning = false;} bool running()const {return m_isRunning;} bool expired(T msPeriod); + T elapsed(); protected: T started()const {return m_started;} private: