Prusa3d Marlin fork
Timer.h
Go to the documentation of this file.
1 
6 #ifndef TIMER_H
7 #define TIMER_H
8 
16 template <class T>
17 class Timer
18 {
19 public:
20  inline constexpr Timer()
21  : m_isRunning(false)
22  , m_started(0) {};
23 
24  void start();
25  void stop(){m_isRunning = false;}
26  bool running()const {return m_isRunning;}
27  bool expired(T msPeriod); // returns true only once after expiration, then stops running
28  T elapsed(); // returns the time in milliseconds since the timer was started or 0 otherwise
29  bool expired_cont(T msPeriod); // return true when continuosly when expired / not running
30 protected:
31  T started()const {return m_started;}
32 private:
33  bool m_isRunning;
34  T m_started;
35 };
36 
42 #if __cplusplus>=201103L
44 #else
46 #endif
52 #if __cplusplus>=201103L
54 #else
56 #endif
57 
58 #endif /* TIMER_H */
Timer< unsigned long > LongTimer
Timer unsigned long specialization.
Definition: Timer.h:43
Timer< unsigned short > ShortTimer
Timer unsigned short specialization.
Definition: Timer.h:53
simple timer
Definition: Timer.h:18
T elapsed()
Ticks since the timer was started.
Definition: Timer.cpp:65
bool expired(T msPeriod)
Timer has expired.
Definition: Timer.cpp:33
void start()
Start timer.
Definition: Timer.cpp:13