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 |
21 |
22 |
22 |
|
23 static unsigned char s[10]; |
23 static uint8_t countdown, countdown_loops; |
24 static uint8_t countdown, countdown_loops; |
24 uint8_t mode = 0; |
25 uint8_t mode = 0; |
25 // valid race modes: |
26 // valid race modes: |
26 // 0: free drive / idle |
27 // 0: free drive / idle |
27 // 1: waiting for countdown start |
28 // 1: waiting for countdown start |
34 volatile uint16_t sysclk_ms_high = 0; |
35 volatile uint16_t sysclk_ms_high = 0; |
35 volatile uint8_t sysclk_packettimer = 0; |
36 volatile uint8_t sysclk_packettimer = 0; |
36 |
37 |
37 volatile uint8_t speedlimit[MAX_SLOTS]; |
38 volatile uint8_t speedlimit[MAX_SLOTS]; |
38 volatile uint8_t fuel[MAX_SLOTS]; |
39 volatile uint8_t fuel[MAX_SLOTS]; |
39 volatile uint8_t jumpstart_time[MAX_SLOTS]; |
40 volatile uint16_t jumpstart_time[MAX_SLOTS]; |
40 |
41 |
41 volatile uint16_t car0, car1; |
42 volatile uint16_t car0, car1; |
42 volatile uint16_t car0_new, car0_old; |
43 volatile uint16_t car0_new, car0_old; |
43 volatile uint16_t car1_new, car1_old; |
44 volatile uint16_t car1_new, car1_old; |
44 uint8_t car0_state, car1_state; |
45 uint8_t car0_state, car1_state; |
116 case 'I': // get Information data (incl. important global parameter dump) |
117 case 'I': // get Information data (incl. important global parameter dump) |
117 RS232_puts(VERSION); |
118 RS232_puts(VERSION); |
118 RS232_putc(':'); |
119 RS232_putc(':'); |
119 for (tmp=0;tmp<MAX_SLOTS;tmp++) RS232_putc(speedlimit[tmp]); // output speed limits |
120 for (tmp=0;tmp<MAX_SLOTS;tmp++) RS232_putc(speedlimit[tmp]); // output speed limits |
120 RS232_putc(':'); |
121 RS232_putc(':'); |
121 for (tmp=0;tmp<MAX_SLOTS;tmp++) RS232_putc(fuel[tmp]); // output fuel levels (0=empty, 100=full, 0xff=no fuel option) |
122 for (tmp=0;tmp<MAX_SLOTS;tmp++) { |
|
123 itoa(fuel[tmp], s, 16); |
|
124 RS232_putc(s); // output fuel levels (0=empty, 100=full, 0xff=no fuel option) |
|
125 RS232_putc(','); |
|
126 } |
122 RS232_putc(':'); |
127 RS232_putc(':'); |
123 for (tmp=0;tmp<MAX_SLOTS;tmp++) RS232_putc(jumpstart_time[tmp]); // output jumpstart times |
128 for (tmp=0;tmp<MAX_SLOTS;tmp++) { |
|
129 itoa(jumpstart_time[tmp], s, 16); |
|
130 RS232_puts(s); // output jumpstart times |
|
131 RS232_putc(','); |
|
132 } |
124 RS232_putc(':'); |
133 RS232_putc(':'); |
125 RS232_putc('\n'); |
134 RS232_putc('\n'); |
126 break; |
135 break; |
127 |
136 |
128 } |
137 } |
139 void jumpstart(uint8_t controller) { |
148 void jumpstart(uint8_t controller) { |
140 if (jumpstart_time[controller] == 0) { |
149 if (jumpstart_time[controller] == 0) { |
141 jumpstart_time[controller] = sysclk_ms_low; |
150 jumpstart_time[controller] = sysclk_ms_low; |
142 RS232_putc('~'); |
151 RS232_putc('~'); |
143 RS232_putc('0'-controller); |
152 RS232_putc('0'-controller); |
|
153 RS232_putc(','); |
|
154 itoa(jumpstart_time[controller], s, 16); |
|
155 RS232_puts(s); |
144 RS232_putc('\n'); |
156 RS232_putc('\n'); |
145 } |
157 } |
146 |
158 |
147 } |
159 } |
148 |
160 |