Software Timers  1.4
Software timer library
 All Classes Files Functions Variables Pages
SoftTimer.h
Go to the documentation of this file.
1 /***************************************************************************/
46 #ifndef SOFTTIMER_H_
47 #define SOFTTIMER_H_
48 
49 
57 class SoftTimer
58 {
59  public:
61  bool is_expired();
62 
64  void start(uint16_t delay_ms);
66  void startW(unsigned long delay_ms);
68  void startN(uint8_t delay_ms);
69 
71  bool interval(uint16_t delay_ms);
73  bool intervalW(unsigned long delay_ms);
75  bool intervalN(uint8_t delay_ms);
76 
77  protected:
79  unsigned long _finish_ms;
80 };
81 
82 
91  : public SoftTimer
92 {
93  public:
95  SoftTimerExt();
97  SoftTimerExt(unsigned long delay_ms);
98 
100  void restart();
101 
103  bool interval();
104 
106  uint32_t remaining();
108  uint32_t remaining_s();
110  uint32_t elapsed();
112  uint32_t elapsed_s();
113 
115  bool is_new_s();
116 
118  void start(uint16_t delay_ms);
120  void startW(unsigned long delay_ms);
122  void startN(uint8_t delay_ms);
123 
124  protected:
126  unsigned long _length_ms;
127 
128  private:
130  uint8_t _last_s;
131 };
132 
133 
134 #endif // SOFTTIMER_H_
135 
136 /******************************************************************************/
bool is_new_s()
Return true if a new second has started since last call.
Definition: SoftTimer.cpp:255
uint32_t elapsed()
Return elapsed milliseconds since (re-)start.
Definition: SoftTimer.cpp:234
void start(uint16_t delay_ms)
Same as for SoftTimer.
Definition: SoftTimer.cpp:272
void startN(uint8_t delay_ms)
Same as for SoftTimer.
Definition: SoftTimer.cpp:297
bool is_expired()
Return true if the timer has expired.
Definition: SoftTimer.cpp:68
bool interval(uint16_t delay_ms)
Return true when timer expires, and restart. 65535 ms max.
Definition: SoftTimer.cpp:123
uint8_t _last_s
Hold the seconds when is_new_s() was last called.
Definition: SoftTimer.h:130
void startW(unsigned long delay_ms)
Same as for SoftTimer.
Definition: SoftTimer.cpp:285
Software timer object with extended features.
Definition: SoftTimer.h:90
Software timer object.
Definition: SoftTimer.h:57
void restart()
Restart timer (that was previously started).
Definition: SoftTimer.cpp:193
unsigned long _finish_ms
Expiry time, in milliseconds.
Definition: SoftTimer.h:79
SoftTimerExt()
Default constructor, does nothing.
Definition: SoftTimer.cpp:169
bool intervalN(uint8_t delay_ms)
Return true when timer expires, and restart. 255 ms max.
Definition: SoftTimer.cpp:157
uint32_t remaining()
Return remaining timer milliseconds.
Definition: SoftTimer.cpp:213
void start(uint16_t delay_ms)
Start timer with up to 65535 ms.
Definition: SoftTimer.cpp:79
bool intervalW(unsigned long delay_ms)
Return true when timer expires, and restart.
Definition: SoftTimer.cpp:141
unsigned long _length_ms
Timer interval in milliseconds.
Definition: SoftTimer.h:126
void startN(uint8_t delay_ms)
Start timer with up to 255 ms.
Definition: SoftTimer.cpp:104
uint32_t elapsed_s()
Return elapsed seconds since (re-)start.
Definition: SoftTimer.cpp:244
uint32_t remaining_s()
Return remaining timer seconds.
Definition: SoftTimer.cpp:226
void startW(unsigned long delay_ms)
Start timer.
Definition: SoftTimer.cpp:93
bool interval()
Return true when timer expires, and restart.
Definition: SoftTimer.cpp:205