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;
}
template<typename T>
bool Timer<T>::expired_cont(T msPeriod)
{
return !m_isRunning || expired(msPeriod);
}
template class Timer<unsigned long>;
template class Timer<unsigned short>;

View File

@ -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: