manual key debounceing works now (100ms)
[svn42.git] / firmware / tuer.pde
index c0c4bf1..ac1a18a 100644 (file)
@@ -22,7 +22,7 @@ byte next_led = 0;
 
 #define MANUAL_OPEN_PIN 12  // keys for manual open and close
 #define MANUAL_CLOSE_PIN 13 // 
-#define DEBOUNCE_DELAY 625  // * 16us = 10ms
+#define DEBOUNCE_DELAY 6250  // * 16us = 100ms
 #define DEBOUNCE_IDLE 0     // currently no debouncing
 #define DEBOUNCE_OPEN 1     // debouncing open key
 #define DEBOUNCE_CLOSE 2    // debouncing close key
@@ -109,7 +109,7 @@ void start_debounce_timer()  // this breaks millis() function, but who cares
   debounce_cnt = DEBOUNCE_DELAY;
 
   TCCR0A = 0;         // no prescaler, WGM = 0 (normal)
-  TCCR0B = 1<<WGM01;  // 
+  TCCR0B = 1<<CS00;   // 
   OCR0A = 255;        // 1+255 = 256 -> 16us @ 16 MHz
   TCNT0 = 0;          // reseting timer
   TIMSK0 = 1<<OCF0A;  // enable Interrupt
@@ -125,8 +125,8 @@ void stop_debounce_timer()
 
 ISR(TIMER0_COMPA_vect)
 {
-  if((debounce_state & DEBOUNCE_OPEN && manual_open_pressed()) ||
-     (debounce_state & DEBOUNCE_CLOSE && manual_close_pressed())) {
+  if(((debounce_state & DEBOUNCE_OPEN) && manual_open_pressed()) ||
+     ((debounce_state & DEBOUNCE_CLOSE) && manual_close_pressed())) {
     if(debounce_cnt) {
       debounce_cnt--;
       return;
@@ -155,7 +155,7 @@ boolean manual_open()
       return true;
     }
   }
-  else {
+  else if(debounce_state & DEBOUNCE_OPEN) {
     stop_debounce_timer();
     debounce_state = DEBOUNCE_IDLE;
   }
@@ -182,7 +182,7 @@ boolean manual_close()
       return true;
     }
   }
-  else {
+  else if(debounce_state & DEBOUNCE_CLOSE) {
     stop_debounce_timer();
     debounce_state = DEBOUNCE_IDLE;
   }