Improved switch debouncing for better homing.
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 27 Nov 2018 23:07:10 +0000 (15:07 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 27 Nov 2018 23:07:10 +0000 (15:07 -0800)
src/avr/src/config.h
src/avr/src/switch.c

index dc6634d4053da5e0a4815a568b8acee192beb3dd..d86a810f7ad1cbad2be51d5e799d8babc49d5da9 100644 (file)
@@ -102,6 +102,7 @@ enum {
 
 // Switch settings.  See switch.c
 #define SWITCH_DEBOUNCE          5 // ms
+#define SWITCH_LOCKOUT         250 // ms
 
 
 // Motor ISRs
index 4a8966d19b9cc5d3fdf62462e934259d705ec595..3156a17c0e9b6c62c068703ea8f302d51aa34c55 100644 (file)
@@ -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));
     }
   }