*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
#define pinb(q) AO_QUADRATURE_ ## q ## _B ## _PIN
#define isr(q) ao_quadrature_isr_ ## q
-#define DEBOUNCE 10
+#ifndef AO_QUADRATURE_DEBOUNCE
+#define AO_QUADRATURE_DEBOUNCE 30
+#endif
static uint8_t
ao_debounce(uint8_t cur, struct ao_debounce *debounce)
{
- if (cur == debounce->state)
- debounce->count = 0;
- else {
- if (++debounce->count == DEBOUNCE) {
- debounce->state = cur;
- debounce->count = 0;
- }
+#if AO_QUADRATURE_DEBOUNCE > 0
+ if (debounce->count > 0) {
+ debounce->count--;
+ } else if (cur != debounce->state) {
+ debounce->state = cur;
+ debounce->count = AO_QUADRATURE_DEBOUNCE;
}
return debounce->state;
+#else
+ return cur;
+#endif
}
static uint16_t
uint8_t old = ao_quadrature_state[q];
if (old != new && new == 0) {
- if (old & 2)
+ if (old == 2)
_ao_quadrature_queue(q, 1);
- else if (old & 1)
+ else if (old == 1)
_ao_quadrature_queue(q, -1);
}
ao_quadrature_state[q] = new;