Skip to content

Commit 4b30ed9

Browse files
committed
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.
1 parent 797f0a1 commit 4b30ed9

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

shared-module/rotaryio/IncrementalEncoder.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,20 @@ void shared_module_softencoder_state_init(rotaryio_incrementalencoder_obj_t *sel
3535
}
3636

3737
void shared_module_softencoder_state_update(rotaryio_incrementalencoder_obj_t *self, uint8_t new_state) {
38-
#define BAD 7
3938
static const int8_t transitions[16] = {
4039
0, // 00 -> 00 no movement
4140
-1, // 00 -> 01 3/4 ccw (11 detent) or 1/4 ccw (00 at detent)
4241
+1, // 00 -> 10 3/4 cw or 1/4 cw
43-
BAD, // 00 -> 11 non-Gray-code transition
42+
0, // 00 -> 11 non-Gray-code transition
4443
+1, // 01 -> 00 2/4 or 4/4 cw
4544
0, // 01 -> 01 no movement
46-
BAD, // 01 -> 10 non-Gray-code transition
45+
0, // 01 -> 10 non-Gray-code transition
4746
-1, // 01 -> 11 4/4 or 2/4 ccw
4847
-1, // 10 -> 00 2/4 or 4/4 ccw
49-
BAD, // 10 -> 01 non-Gray-code transition
48+
0, // 10 -> 01 non-Gray-code transition
5049
0, // 10 -> 10 no movement
5150
+1, // 10 -> 11 4/4 or 2/4 cw
52-
BAD, // 11 -> 00 non-Gray-code transition
51+
0, // 11 -> 00 non-Gray-code transition
5352
+1, // 11 -> 01 1/4 or 3/4 cw
5453
-1, // 11 -> 10 1/4 or 3/4 ccw
5554
0, // 11 -> 11 no movement
@@ -60,10 +59,6 @@ void shared_module_softencoder_state_update(rotaryio_incrementalencoder_obj_t *s
6059
self->state = new_state;
6160

6261
int8_t quarter_incr = transitions[idx];
63-
if (quarter_incr == BAD) {
64-
// Missed a transition. We don't know which way we're going, so do nothing.
65-
return;
66-
}
6762

6863
self->quarter_count += quarter_incr;
6964

0 commit comments

Comments
 (0)