From: Joseph Coffland Date: Tue, 27 Nov 2018 23:07:10 +0000 (-0800) Subject: Improved switch debouncing for better homing. X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=dd6200bb4f67620d6e773ebfe1477b0de2d6bb56;p=bbctrl-firmware Improved switch debouncing for better homing. --- diff --git a/src/avr/src/config.h b/src/avr/src/config.h index dc6634d..d86a810 100644 --- a/src/avr/src/config.h +++ b/src/avr/src/config.h @@ -102,6 +102,7 @@ enum { // Switch settings. See switch.c #define SWITCH_DEBOUNCE 5 // ms +#define SWITCH_LOCKOUT 250 // ms // Motor ISRs diff --git a/src/avr/src/switch.c b/src/avr/src/switch.c index 4a8966d..3156a17 100644 --- a/src/avr/src/switch.c +++ b/src/avr/src/switch.c @@ -39,6 +39,7 @@ typedef struct { switch_callback_t cb; bool state; int8_t debounce; + uint8_t lockout; bool initialized; } switch_t; @@ -81,6 +82,7 @@ void switch_rtc_callback() { switch_t *s = &switches[i]; if (s->type == SW_DISABLED) continue; + if (s->lockout && --s->lockout) continue; // Debounce switch bool state = IN_PIN(s->pin); @@ -90,6 +92,7 @@ void switch_rtc_callback() { s->state = state; s->debounce = 0; s->initialized = true; + s->lockout = SWITCH_LOCKOUT; if (s->cb) s->cb((switch_id_t)i, switch_is_active((switch_id_t)i)); } }