blackbox/main.c

changeset 89
4b5b4c7ba03d
parent 83
c8e7a69a318a
child 90
7ed95dbadf1f
--- a/blackbox/main.c	Fri Dec 16 01:05:37 2011 +0100
+++ b/blackbox/main.c	Sat Dec 17 13:24:20 2011 +0100
@@ -19,6 +19,10 @@
 char countdownstart[]   PROGMEM="!COUNTDOWN\n";
 char racestart[]        PROGMEM="!RACE START\n";
 
+char SHORTCUT[]         PROGMEM="!SHORTCUT\n";
+char PANIC[]            PROGMEM="!PANIC\n";
+char RESUME[]           PROGMEM="!RESUME\n";
+
 typedef union {
     uint32_t value;
     uint16_t word[2]; // high, low word
@@ -44,12 +48,18 @@
 
 static char s[8];
 static uint8_t  countdown, countdown_loops;
-uint8_t  mode = 0;
+extern uint8_t  mode = 0;
 // valid race modes:
 // 0: free drive / idle
 // 1: waiting for countdown start
 // 2: race countdown initiated
 // 3: Race start condition
+// 255 PANIC MODE -> TURN OFF TRACK POWER
+
+extern uint8_t  btn_start = _BV(SW_START);
+extern uint8_t  old_start = _BV(SW_START);
+
+
 uint8_t  liveinfo = 0;
 uint8_t  fuel_enabled = 1;
 
@@ -236,6 +246,16 @@
                     RS232_puts_p(ok);
                     break;
 
+                case '+': // toggle panic mode
+                    RS232_puts_p(ok);
+                    if (mode != 0xff) {
+                        mode = 0xff; 
+                        RS232_puts_p(PANIC);
+                    } else {
+                        mode = 0;
+                        RS232_puts_p(RESUME);
+                    }
+                    break;
 
                 case 'I': // get Information data (incl. important global parameter dump)
                     RS232_puts(VERSION);
@@ -554,8 +574,6 @@
 
     uint8_t  packet_index = 1;
 
-    uint8_t  btn_start = _BV(SW_START);
-    uint8_t  old_start = btn_start;
 
 
     init_hardware();
@@ -569,6 +587,7 @@
         // check for short circuit on the rails
         check_rails_shortcut();
         check_cars();
+        while (mode == 0xff) panic_mode();
 
         if (response_len > 0) {
             itoa(response, s, 2);

mercurial