forked from vortex314/serial2mqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cpp
More file actions
59 lines (52 loc) · 926 Bytes
/
Copy pathTimer.cpp
File metadata and controls
59 lines (52 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "Timer.h"
Timer::Timer()
{
}
Timer::~Timer()
{
}
Timer& Timer::atInterval(uint32_t msec)
{
_repeat=true;
if (msec > 0) {
_active=true;
_interval=msec;
_expiresOn=Sys::millis()+_interval;
} else {
_active=false;
}
return *this;
}
Timer& Timer::atExpiry(uint64_t msec)
{
_repeat=false;
_active=true;
_expiresOn=msec;
return *this;
}
Timer& Timer::atDelta(uint32_t msec)
{
_repeat=false;
if (msec > 0) {
_active=true;
_expiresOn=Sys::millis()+msec;
} else {
_active=false;
}
return *this;
}
Timer& Timer::doThis(TimerHandler action){
_action=action;
return *this;
}
void Timer::check(){
// INFO("%lld %lld",_expiresOn,Sys::millis());
if ( _expiresOn < Sys::millis() && _active ) {
if ( _repeat ) {
_expiresOn=Sys::millis()+_interval;
} else {
_active=false;
}
_action();
}
}