fw: Fix debouncing for rotary encoder
This commit is contained in:
parent
ba069861ff
commit
86b6b0897a
@ -21,13 +21,16 @@ inline int8_t get_rotary_delta()
|
|||||||
return rotary_delta;
|
return rotary_delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ROTARY_DEBOUNCE 150
|
||||||
static inline void input_proc_rotary()
|
static inline void input_proc_rotary()
|
||||||
{
|
{
|
||||||
static int8_t last_a;
|
static int8_t last_a;
|
||||||
int8_t a;
|
int8_t a;
|
||||||
int8_t b;
|
int8_t b;
|
||||||
int8_t p;
|
int8_t p;
|
||||||
|
uint8_t silly_debounce = 0;
|
||||||
|
|
||||||
|
if (silly_debounce == 0) {
|
||||||
p = PORT_ROTARY(PIN);
|
p = PORT_ROTARY(PIN);
|
||||||
a = (p & PIN_ROTARY_A);
|
a = (p & PIN_ROTARY_A);
|
||||||
b = (p & PIN_ROTARY_B);
|
b = (p & PIN_ROTARY_B);
|
||||||
@ -35,15 +38,18 @@ static inline void input_proc_rotary()
|
|||||||
b = !b;
|
b = !b;
|
||||||
|
|
||||||
if (a == 1 && last_a == 0) {
|
if (a == 1 && last_a == 0) {
|
||||||
_delay_ms(1); // TODO
|
silly_debounce = ROTARY_DEBOUNCE;
|
||||||
rotary_delta += !!(a ^ b);
|
rotary_delta += !!(a ^ b);
|
||||||
}
|
}
|
||||||
if (a == 0 && last_a == 1) {
|
if (a == 0 && last_a == 1) {
|
||||||
_delay_ms(1); // TODO
|
silly_debounce = ROTARY_DEBOUNCE;
|
||||||
rotary_delta -= !(a ^ b);
|
rotary_delta -= !(a ^ b);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_a = a;
|
last_a = a;
|
||||||
|
} else {
|
||||||
|
silly_debounce--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Pressing two keys at the same time can lead to unfortunate behavior.
|
// TODO: Pressing two keys at the same time can lead to unfortunate behavior.
|
||||||
|
Loading…
Reference in New Issue
Block a user