Pārlūkot izejas kodu

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.
Yuri D'Elia 1 gadu atpakaļ
vecāks
revīzija
8d9d367d6b
2 mainītis faili ar 9 papildinājumiem un 2 dzēšanām
  1. 6 0
      Firmware/Timer.cpp
  2. 3 2
      Firmware/Timer.h

+ 6 - 0
Firmware/Timer.cpp

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

+ 3 - 2
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: