X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=firmware%2Ftuer.pde;h=6c966a25b5d35390b440966b3dfe8485ce11a8e5;hb=612479558c6a9be836c331c46e04b8f0b28fbabc;hp=c949297784203b613d7d393681aa17ecc88ad2b6;hpb=d55a820fcac08bdee77070de938011ecd6af1875;p=svn42.git diff --git a/firmware/tuer.pde b/firmware/tuer.pde index c949297..6c966a2 100644 --- a/firmware/tuer.pde +++ b/firmware/tuer.pde @@ -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 @@ -38,6 +38,7 @@ int debounce_cnt = 0; #define CMD_OPEN 'o' #define CMD_CLOSE 'c' +#define CMD_TOGGLE 't' #define CMD_STATUS 's' #define CMD_RESET 'r' @@ -125,18 +126,13 @@ 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; } debounce_state |= DEBOUNCE_FINISHED; - - if(digitalRead(HEARTBEAT_PIN)) - digitalWrite(HEARTBEAT_PIN, LOW); - else - digitalWrite(HEARTBEAT_PIN, HIGH); } debounce_cnt = DEBOUNCE_DELAY; } @@ -160,7 +156,7 @@ boolean manual_open() return true; } } - else { + else if(debounce_state & DEBOUNCE_OPEN) { stop_debounce_timer(); debounce_state = DEBOUNCE_IDLE; } @@ -187,7 +183,7 @@ boolean manual_close() return true; } } - else { + else if(debounce_state & DEBOUNCE_CLOSE) { stop_debounce_timer(); debounce_state = DEBOUNCE_IDLE; } @@ -364,6 +360,12 @@ ISR(TIMER1_COMPA_vect) stop_timer(); reset_stepper(); current_state = IDLE; + Serial.print("Status: "); + if(is_opened()) + Serial.print("opened"); + else if(is_closed()) + Serial.print("closed"); + Serial.println(", idle"); return; } else if(current_state == ERROR) { @@ -418,13 +420,11 @@ void init_heartbeat() pinMode(HEARTBEAT_PIN, OUTPUT); reset_heartbeat(); // timer 2: ~10 ms, timebase for heartbeat signal -/* TCCR2A = 1< ~10 ms @ 16 MHz TCNT2 = 0; // reseting timer TIMSK2 = 1<