We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c85b8ee commit 3566d1cCopy full SHA for 3566d1c
util/quadrature_encoder.hh
@@ -10,19 +10,24 @@ class QuadratureEncoder {
10
uint8_t prev_state{};
11
12
public:
13
- enum class State { Undefined, Right, Left };
+ enum Direction { None = 0, CW = 1, CCW = -1 };
14
15
- State update(bool state_a, bool state_b) {
+ Direction get_motion(bool state_a, bool state_b) {
16
const auto cur_state = state_a | (state_b << 1u);
17
+
18
+ if ((prev_state & 0b11) == cur_state)
19
+ return None;
20
21
prev_state <<= 2;
22
prev_state |= cur_state;
23
24
switch (prev_state) {
25
case valid_cw:
- return State::Right;
26
+ return CW;
27
case valid_ccw:
- return State::Left;
28
+ return CCW;
29
default:
- return State::Undefined;
30
31
}
32
33
};
0 commit comments