diff --git a/Firmware/Timer.cpp b/Firmware/Timer.cpp index a94a8586a..f63bf2969 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 599371b4e..dcff52232 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: