forked from ivanseidel/ArduinoThread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticThreadControllerLite.h
More file actions
52 lines (42 loc) · 1.37 KB
/
StaticThreadControllerLite.h
File metadata and controls
52 lines (42 loc) · 1.37 KB
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
/*
StaticThreadControllerLite.h - Controlls a list of ThreadsLite with different timings
Basicaly, what it does is to keep track of current ThreadsLite and run when
necessary.
StaticThreadControllerLite is based on the class StaticThreadController,
but takes less memory and maximum period is only 32,767 seconds.
WARNING! It is not recommended to use if you do not have a memory deficit.
Copyright © 2016 Alex Eremin.
Copyright © 2018 Stanislav Hnatiuk.
Released into the public domain.
*/
#ifndef STATICTHREADCONTROLLERLITE_H
#define STATICTHREADCONTROLLERLITE_H
#include "ThreadLite.h"
template <uint8_t N>
class StaticThreadControllerLite {
protected:
ThreadLite thread[N];
public:
template <typename... T>
StaticThreadControllerLite(T... params) : thread{params...} { };
// Runs all ThreadLite
void run() {
for (uint8_t i = 0; i < N; i++) {
// Is enabled? Timeout exceeded?
if (thread[i].shouldRun()) {
thread[i].run();
}
}
}
// Return the quantity of ThreadsLite
static constexpr int size() {
return N;
};
// Return the I ThreadLite on the array
// Doesn't perform any bounds checks and behaviour is
// unpredictable in case of index > N
ThreadLite& operator[](uint8_t index) {
return thread[index];
}
};
#endif // STATICTHREADCONTROLLERLITE_H