-
Notifications
You must be signed in to change notification settings - Fork 0
/
Avail.h
40 lines (28 loc) · 958 Bytes
/
Avail.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
#ifndef AVAIL_H
#define AVAIL_H
#include <Arduino.h>
class Avail {
public:
static bool micros(uint32_t *margin, uint32_t *lastMicros, bool &rollover) {
return Avail::_avail(::micros(), margin, lastMicros, rollover);
};
static bool micros(uint32_t *margin, uint32_t *lastMicros) {
bool _;
return Avail::micros(margin, lastMicros, _);
};
static bool millis(uint32_t *margin, uint32_t *lastMillis, bool &rollover) {
return Avail::_avail(::millis(), margin, lastMillis, rollover);
};
static bool millis(uint32_t *margin, uint32_t *lastMillis) {
bool _;
return Avail::millis(margin, lastMillis, _);
};
private:
static bool _avail(uint32_t metric, uint32_t *margin, uint32_t *lastLong, bool &rollover) {
uint32_t diff = metric - *lastLong;
rollover = diff > metric;
if (rollover) { diff = 4294967295 - *lastLong + metric; }
return *margin <= diff;
};
};
#endif