X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=firmware%2Ftuer.pde;h=d2c7a09b1aedc4e1aabc47af37e78fe16be352d4;hb=33de7447b0fab42ac6a65fa614a2ae3fe28d5788;hp=ac1a18ac694608d3116c2d6f093a58f98e43b60a;hpb=a40f2d7edc811267d72c0c476050d7e565342f13;p=svn42.git diff --git a/firmware/tuer.pde b/firmware/tuer.pde index ac1a18a..d2c7a09 100644 --- a/firmware/tuer.pde +++ b/firmware/tuer.pde @@ -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' @@ -359,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) { @@ -454,32 +461,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 +526,43 @@ 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"); + } + else if (command == CMD_TOGGLE) { + if(current_state == IDLE) { + if(is_closed()) + start_open(); + else + start_close(); + Serial.println("Ok"); + } else Serial.println("Error: Operation in progress"); }