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,29 +21,35 @@ 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;
p = PORT_ROTARY(PIN);
a = (p & PIN_ROTARY_A);
b = (p & PIN_ROTARY_B);
a = !a;
b = !b;
if (silly_debounce == 0) {
p = PORT_ROTARY(PIN);
a = (p & PIN_ROTARY_A);
b = (p & PIN_ROTARY_B);
a = !a;
b = !b;
if (a == 1 && last_a == 0) {
_delay_ms(1); // TODO
rotary_delta += !!(a ^ b);
if (a == 1 && last_a == 0) {
silly_debounce = ROTARY_DEBOUNCE;
rotary_delta += !!(a ^ b);
}
if (a == 0 && last_a == 1) {
silly_debounce = ROTARY_DEBOUNCE;
rotary_delta -= !(a ^ b);
}
last_a = a;
} else {
silly_debounce--;
}
if (a == 0 && last_a == 1) {
_delay_ms(1); // TODO
rotary_delta -= !(a ^ b);
}
last_a = a;
}
// TODO: Pressing two keys at the same time can lead to unfortunate behavior.