9namespace tinyrobotics {
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
59 Scheduler() =
default;
61 void begin(uint16_t repeatMs,
void (*cb)(
void*),
void* ref =
nullptr) {
63 start_time = millis() + repeatMs;
66 is_active_ = repeatMs > 0 && cb !=
nullptr;
69 void end() { is_active_ =
false; }
71 void setCallback(
void (*cb)(
void*)) {
77 if (is_active_ && callback && millis() >= start_time) {
80 start_time += repeatMs_;
84 bool isActive()
const {
return is_active_; }
87 unsigned long millis() {
89 static auto start_time = std::chrono::steady_clock::now();
90 auto now = std::chrono::steady_clock::now();
91 return std::chrono::duration_cast<std::chrono::milliseconds>(now -
98 unsigned long start_time = 0;
99 bool is_active_ =
false;
100 void (*callback)(
void*) =
nullptr;
101 void *reference =
nullptr;
Simple periodic task scheduler for embedded and Arduino environments.
Definition: Scheduler.h:57