16 char ok[] PROGMEM="OK\n"; |
16 char ok[] PROGMEM="OK\n"; |
17 char busy[] PROGMEM="BUSY\n"; |
17 char busy[] PROGMEM="BUSY\n"; |
18 char prepare[] PROGMEM="!RACE PREPARE\n"; |
18 char prepare[] PROGMEM="!RACE PREPARE\n"; |
19 char countdownstart[] PROGMEM="!COUNTDOWN\n"; |
19 char countdownstart[] PROGMEM="!COUNTDOWN\n"; |
20 char racestart[] PROGMEM="!RACE START\n"; |
20 char racestart[] PROGMEM="!RACE START\n"; |
|
21 |
|
22 char SHORTCUT[] PROGMEM="!SHORTCUT\n"; |
|
23 char PANIC[] PROGMEM="!PANIC\n"; |
|
24 char RESUME[] PROGMEM="!RESUME\n"; |
21 |
25 |
22 typedef union { |
26 typedef union { |
23 uint32_t value; |
27 uint32_t value; |
24 uint16_t word[2]; // high, low word |
28 uint16_t word[2]; // high, low word |
25 uint8_t byte[4]; // all four bytes |
29 uint8_t byte[4]; // all four bytes |
42 u32 lap_time_start, lap_time; |
46 u32 lap_time_start, lap_time; |
43 } cardata; |
47 } cardata; |
44 |
48 |
45 static char s[8]; |
49 static char s[8]; |
46 static uint8_t countdown, countdown_loops; |
50 static uint8_t countdown, countdown_loops; |
47 uint8_t mode = 0; |
51 extern uint8_t mode = 0; |
48 // valid race modes: |
52 // valid race modes: |
49 // 0: free drive / idle |
53 // 0: free drive / idle |
50 // 1: waiting for countdown start |
54 // 1: waiting for countdown start |
51 // 2: race countdown initiated |
55 // 2: race countdown initiated |
52 // 3: Race start condition |
56 // 3: Race start condition |
|
57 // 255 PANIC MODE -> TURN OFF TRACK POWER |
|
58 |
|
59 extern uint8_t btn_start = _BV(SW_START); |
|
60 extern uint8_t old_start = _BV(SW_START); |
|
61 |
|
62 |
53 uint8_t liveinfo = 0; |
63 uint8_t liveinfo = 0; |
54 uint8_t fuel_enabled = 1; |
64 uint8_t fuel_enabled = 1; |
55 |
65 |
56 volatile u32 sysclk; |
66 volatile u32 sysclk; |
57 volatile uint8_t sysclk_packettimer = 0; |
67 volatile uint8_t sysclk_packettimer = 0; |
234 case '*': // set live information |
244 case '*': // set live information |
235 liveinfo = buffer[1]-'0'; |
245 liveinfo = buffer[1]-'0'; |
236 RS232_puts_p(ok); |
246 RS232_puts_p(ok); |
237 break; |
247 break; |
238 |
248 |
|
249 case '+': // toggle panic mode |
|
250 RS232_puts_p(ok); |
|
251 if (mode != 0xff) { |
|
252 mode = 0xff; |
|
253 RS232_puts_p(PANIC); |
|
254 } else { |
|
255 mode = 0; |
|
256 RS232_puts_p(RESUME); |
|
257 } |
|
258 break; |
239 |
259 |
240 case 'I': // get Information data (incl. important global parameter dump) |
260 case 'I': // get Information data (incl. important global parameter dump) |
241 RS232_puts(VERSION); |
261 RS232_puts(VERSION); |
242 RS232_putc(':'); |
262 RS232_putc(':'); |
243 for (tmp=0;tmp<MAX_SLOTS;tmp++) RS232_putc(slot[tmp].speedlimit); // output speed limits |
263 for (tmp=0;tmp<MAX_SLOTS;tmp++) RS232_putc(slot[tmp].speedlimit); // output speed limits |
567 |
585 |
568 while (1) { |
586 while (1) { |
569 // check for short circuit on the rails |
587 // check for short circuit on the rails |
570 check_rails_shortcut(); |
588 check_rails_shortcut(); |
571 check_cars(); |
589 check_cars(); |
|
590 while (mode == 0xff) panic_mode(); |
572 |
591 |
573 if (response_len > 0) { |
592 if (response_len > 0) { |
574 itoa(response, s, 2); |
593 itoa(response, s, 2); |
575 response_len = 0; |
594 response_len = 0; |
576 //RS232_puts("ANSWER RX: "); |
595 //RS232_puts("ANSWER RX: "); |