fw: Fix debouncing for rotary encoder

This commit is contained in:
Markus Koch 2020-07-30 21:41:22 +02:00
parent ba069861ff
commit 86b6b0897a

View File

@ -21,13 +21,16 @@ inline int8_t get_rotary_delta()
return rotary_delta;
}
#define ROTARY_DEBOUNCE 150
static inline void input_proc_rotary()
{
static int8_t last_a;
int8_t a;
int8_t b;
int8_t p;
uint8_t silly_debounce = 0;
if (silly_debounce == 0) {
p = PORT_ROTARY(PIN);
a = (p & PIN_ROTARY_A);
b = (p & PIN_ROTARY_B);
@ -35,15 +38,18 @@ static inline void input_proc_rotary()
b = !b;
if (a == 1 && last_a == 0) {
_delay_ms(1); // TODO
silly_debounce = ROTARY_DEBOUNCE;
rotary_delta += !!(a ^ b);
}
if (a == 0 && last_a == 1) {
_delay_ms(1); // TODO
silly_debounce = ROTARY_DEBOUNCE;
rotary_delta -= !(a ^ b);
}
last_a = a;
} else {
silly_debounce--;
}
}
// TODO: Pressing two keys at the same time can lead to unfortunate behavior.