forked from profezzorn/ProffieOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.h
49 lines (43 loc) · 1.15 KB
/
select.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
#ifndef TRANSITIONS_SELECT_H
#define TRANSITIONS_SELECT_H
#include "random.h"
// Usage: TrSelect<SELECTION, TR1, TR2, ...>
// SELECTION: FUNCTION
// TR1, TR2: TRANSITION
// return value: TRANSITION
// transition option is picked from the specified list of
// transitions based on Int<>
// with Int<0> representing first transition
template<class F, class... TRANSITION>
class TrSelect {
public:
void begin() {
begin_ = true;
}
void run(BladeBase* blade) {
f_.run(blade);
if (begin_) {
begin_ = false;
int f = f_.calculate(blade);
while(f < 0) f += sizeof...(TRANSITION) << 8;
uint8_t selection = f % sizeof...(TRANSITION);
selected_ = transitions_.get(selection % sizeof...(TRANSITION));
selected_->begin();
}
selected_->run(blade);
}
RGBA getColor(const RGBA& a, const RGBA& b, int led) {
return selected_->getColor(a, b, led);
}
bool done() {
if (begin_) return false;
if (!selected_) return true;
return selected_->done();
}
private:
bool begin_ = false;
PONUA SVFWrapper<F> f_;
PONUA TrHelper<TRANSITION...> transitions_;
TransitionInterface* selected_ = nullptr;
};
#endif