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.
This commit is contained in:
Yuri D'Elia 2022-06-28 21:05:03 +02:00
parent dc2d596f40
commit 8d9d367d6b
2 changed files with 9 additions and 2 deletions

View File

@ -77,5 +77,11 @@ T Timer<T>::elapsed() {
return m_isRunning ? (_millis() - m_started) : 0; return m_isRunning ? (_millis() - m_started) : 0;
} }
template<typename T>
bool Timer<T>::expired_cont(T msPeriod)
{
return !m_isRunning || expired(msPeriod);
}
template class Timer<unsigned long>; template class Timer<unsigned long>;
template class Timer<unsigned short>; template class Timer<unsigned short>;

View File

@ -21,8 +21,9 @@ public:
void start(); void start();
void stop(){m_isRunning = false;} void stop(){m_isRunning = false;}
bool running()const {return m_isRunning;} bool running()const {return m_isRunning;}
bool expired(T msPeriod); bool expired(T msPeriod); // returns true only once after expiration, then stops running
T elapsed(); 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: protected:
T started()const {return m_started;} T started()const {return m_started;}
private: private: