-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_idea.hh
More file actions
47 lines (39 loc) · 793 Bytes
/
class_idea.hh
File metadata and controls
47 lines (39 loc) · 793 Bytes
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
#include <concepts>
enum class ButtonError {
None,
StuckDown,
NoisyPress,
NoisyRelease,
MultipleHighs,
Unknown,
};
template<typename T>
concept BoardC = requires(T t, unsigned chan) {
{
t.read_button(chan)
} -> std::same_as<bool>;
t.set_indicator(chan, bool{});
t.set_error_indicator(chan, ButtonError{});
};
template<BoardC Board>
class ButtonTester {
Board board;
unsigned cur_chan = 0;
public:
bool check() {
board.read_button(cur_chan);
cur_chan++;
return true;
}
};
////// in project:
struct SWNButtonIO {
bool read_button(unsigned num) { return false; }
void set_indicator(unsigned num, bool high) {}
void set_error_indicator(unsigned num, ButtonError err) {}
};
void test_buttons() {
ButtonTester<SWNButtonIO> checker;
while (!checker.check()) {
}
}