-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterval.h
56 lines (43 loc) · 987 Bytes
/
Interval.h
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
#ifndef _ACROBOT_INTERVAL_H
#define _ACROBOT_INTERVAL_H
#include "Utils.h"
namespace ACRobot {
class Interval: public PollingInterface
{
public:
Interval(): _interval(0), _last(0) {}
Interval(long ms): _interval(ms), _last(0) {}
bool poll() { return poll(millis()); }
bool poll(unsigned long ms);
unsigned long& operator =(unsigned long ms) { return _interval = ms; }
bool operator !() { return _interval == 0; }
private:
unsigned long _interval;
unsigned long _last;
};
template <int n>
class Intervals
{
public:
Intervals() {}
int status()
{
unsigned long ms = millis();
for (register int i = 0; i < n; i++)
{
if (!_intervals[i])
continue;
if (_intervals[i].poll(ms))
return i;
}
return -1;
}
Interval& operator[] (const int index)
{
return _intervals[index];
}
private:
Interval _intervals[n];
};
} // ACRobot namespace
#endif