Prusa3d Marlin fork
TimerRemaining.h
Go to the documentation of this file.
1 
6 #ifndef TIMERREMAINING_H
7 #define TIMERREMAINING_H
8 
9 #include "Timer.h"
10 #include "Arduino.h"
11 #include "system_timer.h"
12 #include <limits.h>
13 
14 class TimerRemaining : public LongTimer
15 {
16 public:
17  TimerRemaining() : m_period(){}
18  void start() = delete;
19  bool expired(unsigned long msPeriod) = delete;
24  void start(unsigned long msPeriod)
25  {
26  m_period = msPeriod;
28  }
36  unsigned long remaining()
37  {
38  if (!running()) return 0;
39  if (expired()) return 0;
40  const unsigned long now = _millis();
41  return (started() + m_period - now);
42  }
48  bool expired()
49  {
50  return LongTimer::expired(m_period);
51  }
52 private:
53  unsigned long m_period;
54 };
55 
56 #endif // ifndef TIMERREMAINING_H
Definition: TimerRemaining.h:15
void start(unsigned long msPeriod)
Start timer.
Definition: TimerRemaining.h:24
bool expired()
Timer has expired.
Definition: TimerRemaining.h:48
unsigned long remaining()
Time remaining to expiration.
Definition: TimerRemaining.h:36
bool expired(unsigned long msPeriod)
Timer has expired.
Definition: Timer.cpp:33
void start()
Start timer.
Definition: Timer.cpp:13