firmware: reset with manual keys
[svn42.git] / firmware / tuer.pde
index ddf8ba3..6c966a2 100644 (file)
@@ -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'
 
@@ -554,16 +555,27 @@ void loop()
       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");
+    }
     else if (command == CMD_STATUS)
       print_status();
     else
       Serial.println("Error: unknown command");
   }
-  if(manual_open() && !is_opened() && current_state == IDLE) {
+  if(manual_open() && !is_opened() && (current_state == IDLE || current_state == ERROR)) {
     Serial.println("open forced manually");
     start_open();
   }
-  if(manual_close() && !is_closed() && current_state == IDLE) {
+  if(manual_close() && !is_closed() && (current_state == IDLE || current_state == ERROR)) {
     Serial.println("close forced manually");
     start_close();
   }