11 #include "driver/adc.h" |
11 #include "driver/adc.h" |
12 |
12 |
13 #include "main.h" |
13 #include "main.h" |
14 #include "lowlevel.h" |
14 #include "lowlevel.h" |
15 |
15 |
16 char ok[] PROGMEM="OK\n"; |
16 const char ok[] PROGMEM="OK\n"; |
17 char busy[] PROGMEM="BUSY\n"; |
17 const char busy[] PROGMEM="BUSY\n"; |
18 char prepare[] PROGMEM="!RACE PREPARE\n"; |
18 const char prepare[] PROGMEM="!RACE PREPARE\n"; |
19 char countdownstart[] PROGMEM="!COUNTDOWN\n"; |
19 const char countdownstart[] PROGMEM="!COUNTDOWN\n"; |
20 char racestart[] PROGMEM="!RACE START\n"; |
20 const char racestart[] PROGMEM="!RACE START\n"; |
21 |
21 |
22 char SHORTCUT[] PROGMEM="!SHORTCUT\n"; |
22 const char SHORTCUT[] PROGMEM="!SHORTCUT\n"; |
23 char PANIC[] PROGMEM="!PANIC\n"; |
23 const char PANIC[] PROGMEM="!PANIC\n"; |
24 char RESUME[] PROGMEM="!RESUME\n"; |
24 const char RESUME[] PROGMEM="!RESUME\n"; |
25 |
25 |
26 typedef union { |
26 typedef union { |
27 uint32_t value; |
27 uint32_t value; |
28 uint16_t word[2]; // high, low word |
28 uint16_t word[2]; // high, low word |
29 uint8_t byte[4]; // all four bytes |
29 uint8_t byte[4]; // all four bytes |
38 typedef struct { |
38 typedef struct { |
39 unsigned speedlimit:4; // 4bits speedlimit |
39 unsigned speedlimit:4; // 4bits speedlimit |
40 unsigned speedminimum:4; // 4bits speedminimum |
40 unsigned speedminimum:4; // 4bits speedminimum |
41 unsigned seccnt:4; // 4 bits tenth seconds counter |
41 unsigned seccnt:4; // 4 bits tenth seconds counter |
42 unsigned accel:4; // 4 bits last configured acceleration |
42 unsigned accel:4; // 4 bits last configured acceleration |
|
43 unsigned speed:4; // 4 bits last speed |
43 unsigned trackswitch:1; // 1bit bool |
44 unsigned trackswitch:1; // 1bit bool |
44 unsigned canrefuel:1; // 1bit bool |
45 unsigned canrefuel:1; // 1bit bool |
45 unsigned unlimitedfuel:1; // 1bit bool |
46 unsigned unlimitedfuel:1; // 1bit bool |
|
47 unsigned trackchange:1; // 1bit bool |
46 uint16_t jumpstart_time, laps, fuel; |
48 uint16_t jumpstart_time, laps, fuel; |
47 u32 lap_time_start, lap_time; |
49 u32 lap_time_start, lap_time; |
48 } cardata; |
50 } cardata; |
49 |
51 |
50 static char s[8]; |
52 static char s[8]; |
369 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
371 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
370 // //if ( (trackchange!=0) || (slot[controller].trackswitch)) tmp |= (1<<5); |
372 // //if ( (trackchange!=0) || (slot[controller].trackswitch)) tmp |= (1<<5); |
371 } |
373 } |
372 } |
374 } |
373 speed = tmp; |
375 speed = tmp; |
|
376 slot[controller].speed = tmp; |
|
377 slot[controller].trackchange = (trackchange != 0); |
374 tmp = tmp << 1; |
378 tmp = tmp << 1; |
375 if (trackchange != 0) tmp |= (1<<5); |
379 if (trackchange != 0) tmp |= (1<<5); |
376 |
380 |
377 |
381 |
378 switch (controller) { |
382 switch (controller) { |
575 |
579 |
576 } |
580 } |
577 |
581 |
578 void slot_liveinfo(uint8_t idx) { |
582 void slot_liveinfo(uint8_t idx) { |
579 if (liveinfo == 0) return; |
583 if (liveinfo == 0) return; |
580 // increment packet counter, if == 10 output some live info |
584 |
581 if (slot[idx].seccnt == 10) { |
585 if (liveinfo == 1) { |
582 // output current fuel status |
586 // increment packet counter, if == 10 output some live info |
583 RS232_putc('F'); |
587 if (slot[idx].seccnt == 10) { |
584 RS232_putc(':'); |
588 // output current fuel status |
585 RS232_putc(idx + '0'); |
589 RS232_putc('F'); |
586 RS232_putc(':'); |
590 RS232_putc(':'); |
587 itoa(slot[idx].fuel, s, 16); |
591 RS232_putc(idx + '0'); |
588 RS232_puts(s); |
592 RS232_putc(':'); |
589 RS232_putc(':'); |
593 itoa(slot[idx].fuel, s, 16); |
590 ultoa(sysclk.value, s, 16); |
594 RS232_puts(s); |
591 RS232_puts(s); |
595 RS232_putc(':'); |
592 RS232_putc('\n'); |
596 ultoa(sysclk.value, s, 16); |
593 |
597 RS232_puts(s); |
594 slot[idx].seccnt = 0; |
598 RS232_putc('\n'); |
595 } else slot[idx].seccnt++; |
599 slot[idx].seccnt = 0; |
|
600 } else slot[idx].seccnt++; |
|
601 } else if ( (liveinfo - 2) == idx ) { |
|
602 // output controller status LIVEINFO-2 for remote learning |
|
603 RS232_putc('L'); |
|
604 RS232_putc('N'); |
|
605 RS232_putc(':'); |
|
606 itoa(slot[idx].speed, s, 16); |
|
607 RS232_puts(s); |
|
608 RS232_putc(':'); |
|
609 if (slot[idx].trackchange) |
|
610 RS232_putc('X'); |
|
611 RS232_putc('\n'); |
|
612 } |
596 } |
613 } |
597 |
614 |
598 |
615 |
599 int main(void) |
616 int main(void) |
600 { |
617 { |