rotaryio: shared_module_softencoder_state_update: no need for BAD state
All we do on a BAD state transition is avoid counting up or down, but the same is accomplished by using the "0" table value instead.
This commit is contained in:
parent
23d2c96476
commit
a0dd2ccec1
@ -35,21 +35,20 @@ void shared_module_softencoder_state_init(rotaryio_incrementalencoder_obj_t *sel
|
||||
}
|
||||
|
||||
void shared_module_softencoder_state_update(rotaryio_incrementalencoder_obj_t *self, uint8_t new_state) {
|
||||
#define BAD 7
|
||||
static const int8_t transitions[16] = {
|
||||
0, // 00 -> 00 no movement
|
||||
-1, // 00 -> 01 3/4 ccw (11 detent) or 1/4 ccw (00 at detent)
|
||||
+1, // 00 -> 10 3/4 cw or 1/4 cw
|
||||
BAD, // 00 -> 11 non-Gray-code transition
|
||||
0, // 00 -> 11 non-Gray-code transition
|
||||
+1, // 01 -> 00 2/4 or 4/4 cw
|
||||
0, // 01 -> 01 no movement
|
||||
BAD, // 01 -> 10 non-Gray-code transition
|
||||
0, // 01 -> 10 non-Gray-code transition
|
||||
-1, // 01 -> 11 4/4 or 2/4 ccw
|
||||
-1, // 10 -> 00 2/4 or 4/4 ccw
|
||||
BAD, // 10 -> 01 non-Gray-code transition
|
||||
0, // 10 -> 01 non-Gray-code transition
|
||||
0, // 10 -> 10 no movement
|
||||
+1, // 10 -> 11 4/4 or 2/4 cw
|
||||
BAD, // 11 -> 00 non-Gray-code transition
|
||||
0, // 11 -> 00 non-Gray-code transition
|
||||
+1, // 11 -> 01 1/4 or 3/4 cw
|
||||
-1, // 11 -> 10 1/4 or 3/4 ccw
|
||||
0, // 11 -> 11 no movement
|
||||
@ -60,10 +59,6 @@ void shared_module_softencoder_state_update(rotaryio_incrementalencoder_obj_t *s
|
||||
self->state = new_state;
|
||||
|
||||
int8_t quarter_incr = transitions[idx];
|
||||
if (quarter_incr == BAD) {
|
||||
// Missed a transition. We don't know which way we're going, so do nothing.
|
||||
return;
|
||||
}
|
||||
|
||||
self->quarter_count += quarter_incr;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user