Fixed switch debounce bug.
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 27 Feb 2018 00:17:36 +0000 (16:17 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 27 Feb 2018 00:17:36 +0000 (16:17 -0800)
CHANGELOG.md
package.json
src/avr/src/switch.c
src/py/bbctrl/State.py

index 13e69b6ffa7176648c37bae2b509d4a4cfb39306..ebd69e762591d6b0a1b5e5d25001286cbac83465 100644 (file)
@@ -1,6 +1,9 @@
 Buildbotics CNC Controller Firmware Change Log
 ==============================================
 
+## v0.3.16
+ - Fixed switch debounce bug.
+
 ## v0.3.15
  - Suppress warning missing config.json warning after config reset.
  - Fixed EStop reboot loop.
index 208b4d83ae7c02cec48b168a71067a7f92de74db..b55956cbd213296b6b27af80ef4f136317fdc4ef 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "bbctrl",
-  "version": "0.3.15",
+  "version": "0.3.16",
   "homepage": "http://buildbotics.com/",
   "repository": "https://github.com/buildbotics/bbctrl-firmware",
   "license": "GPL-3.0+",
index 40e3a8815394b2352152a138bdb53a747df86638..45eb3f79141aacd8b26b9e39d4f888821d7be104 100644 (file)
@@ -29,6 +29,7 @@
 #include "config.h"
 
 #include <stdbool.h>
+#include <stdio.h>
 
 
 typedef struct {
@@ -83,7 +84,7 @@ void switch_rtc_callback() {
 
     // Debounce switch
     bool state = IN_PIN(s->pin);
-    if (state == s->state) s->debounce = 0;
+    if (state == s->state && s->initialized) s->debounce = 0;
     else if ((state && ++s->debounce == SWITCH_DEBOUNCE) ||
              (!state && --s->debounce == -SWITCH_DEBOUNCE)) {
       s->state = state;
@@ -96,16 +97,15 @@ void switch_rtc_callback() {
 
 
 bool switch_is_active(switch_id_t sw) {
-  if (sw < 0 || num_switches <= sw) return false;
-
-  if (!switches[sw].initialized) return false;
+  if (sw < 0 || num_switches <= sw || !switches[sw].initialized) return false;
 
   // NOTE, switch inputs are active lo
   switch (switches[sw].type) {
-  case SW_DISABLED: break; // A disabled switch cannot be active
-  case SW_NORMALLY_OPEN: return !switches[sw].state;
+  case SW_DISABLED:        break; // A disabled switch cannot be active
+  case SW_NORMALLY_OPEN:   return !switches[sw].state;
   case SW_NORMALLY_CLOSED: return switches[sw].state;
   }
+
   return false;
 }
 
index f84c0d26cd35737bbf2388fa3723eabbf59bacaf..ad630a0b6343981f9f6a61f555a3ca20f0dca7b6 100644 (file)
@@ -158,7 +158,7 @@ class State(object):
         for motor in range(6):
             if not ('%dan' % motor) in self.vars: continue
             motor_axis = 'xyzabc'[self.vars['%dan' % motor]]
-            if motor_axis == axis.lower() and self.vars['%dpm' % motor]:
+            if motor_axis == axis.lower() and self.vars.get('%dpm' % motor, 0):
                 return motor