From 8d9d367d6be7e001c4a81446a97f1f9ac06cdb0e Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 28 Jun 2022 21:05:03 +0200 Subject: [PATCH] Implement Timer::expired_cont() Returns true if the timer is not running, effectively allowing to check if a certain set time in the future has passed. --- Firmware/Timer.cpp | 6 ++++++ Firmware/Timer.h | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Firmware/Timer.cpp b/Firmware/Timer.cpp index f63bf296..d0a552b0 100644 --- a/Firmware/Timer.cpp +++ b/Firmware/Timer.cpp @@ -77,5 +77,11 @@ T Timer::elapsed() { return m_isRunning ? (_millis() - m_started) : 0; } +template +bool Timer::expired_cont(T msPeriod) +{ + return !m_isRunning || expired(msPeriod); +} + template class Timer; template class Timer; diff --git a/Firmware/Timer.h b/Firmware/Timer.h index dcff5223..9cb18a30 100644 --- a/Firmware/Timer.h +++ b/Firmware/Timer.h @@ -21,8 +21,9 @@ public: void start(); void stop(){m_isRunning = false;} bool running()const {return m_isRunning;} - bool expired(T msPeriod); - T elapsed(); + bool expired(T msPeriod); // returns true only once after expiration, then stops running + T elapsed(); // returns the time in milliseconds since the timer was started or 0 otherwise + bool expired_cont(T msPeriod); // return true when continuosly when expired / not running protected: T started()const {return m_started;} private: