X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=firmware%2Ftuer.pde;h=ddf8ba3f3d68f9f9e338419de2344aa0b17fcf15;hb=138139e389ccc8acd4a9b26df3ef073fd9d3d2bf;hp=314ade20da1bb24fde558424f3f50ed519e7ac04;hpb=dd21c9b5f5bc14086d884c0cd0e535b56bbd63c8;p=svn42.git diff --git a/firmware/tuer.pde b/firmware/tuer.pde index 314ade2..ddf8ba3 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 @@ -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; } @@ -359,6 +359,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) { @@ -454,32 +460,20 @@ void reset_after_error() void start_open() { - if(is_opened()) { - Serial.println("Already open"); - return; - } - reset_stepper(); reset_leds(); leds_green(); current_state = OPENING; start_step_timer(); - Serial.println("Ok"); } void start_close() { - if(is_closed()) { - Serial.println("Already closed"); - return; - } - reset_stepper(); reset_leds(); leds_red(); current_state = CLOSING; start_step_timer(); - Serial.println("Ok"); } void print_status() @@ -531,20 +525,32 @@ void loop() char command = Serial.read(); if(current_state == ERROR && command != CMD_RESET) { - Serial.println("Error: last open/close operation took to long!"); + Serial.println("Error: last open/close operation took too long!"); } else if (command == CMD_RESET) { reset_after_error(); } else if (command == CMD_OPEN) { - if(current_state == IDLE) - start_open(); + if(current_state == IDLE) { + if(is_opened()) + Serial.println("Already open"); + else { + start_open(); + Serial.println("Ok"); + } + } else Serial.println("Error: Operation in progress"); } else if (command == CMD_CLOSE) { - if(current_state == IDLE) - start_close(); + if(current_state == IDLE) { + if(is_closed()) + Serial.println("Already closed"); + else { + start_close(); + Serial.println("Ok"); + } + } else Serial.println("Error: Operation in progress"); }