1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #ifndef TIMERREMAINING_H
- #define TIMERREMAINING_H
- #include "Timer.h"
- #include "Arduino.h"
- #include "system_timer.h"
- #include <limits.h>
- class TimerRemaining : public LongTimer
- {
- public:
- TimerRemaining() : m_period(){}
- void start() = delete;
- bool expired(unsigned long msPeriod) = delete;
-
- void start(unsigned long msPeriod)
- {
- m_period = msPeriod;
- LongTimer::start();
- }
-
- unsigned long remaining()
- {
- if (!running()) return 0;
- if (expired()) return 0;
- const unsigned long now = _millis();
- return (started() + m_period - now);
- }
-
- bool expired()
- {
- return LongTimer::expired(m_period);
- }
- private:
- unsigned long m_period;
- };
- #endif
|