30 } u32; |
30 } u32; |
31 |
31 |
32 #define FUEL_FULL 10000 |
32 #define FUEL_FULL 10000 |
33 #define FUEL_JUMPSTART 5000 |
33 #define FUEL_JUMPSTART 5000 |
34 #define FUEL_DIV_DEFAULT 25 |
34 #define FUEL_DIV_DEFAULT 25 |
35 #define PITLANE_SPEEDLIMIT 4 |
35 #define PITLANE_SPEEDLIMIT 6 |
36 volatile uint8_t fuel_divisor = FUEL_DIV_DEFAULT; // default, can be set via serial command |
36 volatile uint8_t fuel_divisor = FUEL_DIV_DEFAULT; // default, can be set via serial command |
37 |
37 |
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 speed:4; // 4 bits last speed |
|
44 unsigned pitlane_limit:4; // 4bits speedlimit |
44 unsigned trackswitch:1; // 1bit bool |
45 unsigned trackswitch:1; // 1bit bool |
45 unsigned canrefuel:1; // 1bit bool |
46 unsigned canrefuel:1; // 1bit bool |
46 unsigned unlimitedfuel:1; // 1bit bool |
47 unsigned unlimitedfuel:1; // 1bit bool |
47 unsigned trackchange:1; // 1bit bool |
48 unsigned trackchange:1; // 1bit bool |
48 uint16_t jumpstart_time, laps, fuel; |
49 uint16_t jumpstart_time, laps, fuel; |
150 uint8_t type = (data & 0b111); |
151 uint8_t type = (data & 0b111); |
151 if (type == 4) { |
152 if (type == 4) { |
152 // pitlane response |
153 // pitlane response |
153 if (status == 5) slot[car].canrefuel = 1; |
154 if (status == 5) slot[car].canrefuel = 1; |
154 if (status == 6) for (data=0; data<MAX_SLOTS; data++) slot[data].canrefuel = 0; |
155 if (status == 6) for (data=0; data<MAX_SLOTS; data++) slot[data].canrefuel = 0; |
|
156 if (status == 7) slot[car].canrefuel = 0; |
155 } |
157 } |
156 RS232_puts("RW:"); |
158 RS232_puts("RW:"); |
157 RS232_putc(car + '0'); |
159 RS232_putc(car + '0'); |
158 RS232_putc(':'); |
160 RS232_putc(':'); |
159 RS232_putc(type + '0'); |
161 RS232_putc(type + '0'); |
363 |
365 |
364 if (controller < 4) { |
366 if (controller < 4) { |
365 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; |
367 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; |
366 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } |
368 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } |
367 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
369 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
368 if (slot[controller].canrefuel && (tmp > PITLANE_SPEEDLIMIT)) tmp = PITLANE_SPEEDLIMIT; |
370 if (slot[controller].canrefuel && (tmp > slot[controller].pitlane_limit)) tmp = slot[controller].pitlane_limit; |
369 } else { |
371 } else { |
370 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; |
372 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; |
371 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
373 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
372 // //if ( (trackchange!=0) || (slot[controller].trackswitch)) tmp |= (1<<5); |
374 // //if ( (trackchange!=0) || (slot[controller].trackswitch)) tmp |= (1<<5); |
373 } |
375 } |
488 slot[i].jumpstart_time = 0; |
490 slot[i].jumpstart_time = 0; |
489 slot[i].laps = 0; |
491 slot[i].laps = 0; |
490 slot[i].seccnt = 0; |
492 slot[i].seccnt = 0; |
491 slot[i].accel = 15; // full acceleration per default - TODO |
493 slot[i].accel = 15; // full acceleration per default - TODO |
492 slot[i].canrefuel = 0; |
494 slot[i].canrefuel = 0; |
|
495 slot[i].pitlane_limit = PITLANE_SPEEDLIMIT; |
493 if (i<4) slot[i].unlimitedfuel = 0; else slot[i].unlimitedfuel = 1; |
496 if (i<4) slot[i].unlimitedfuel = 0; else slot[i].unlimitedfuel = 1; |
494 slot[i].lap_time_start.value = 0; |
497 slot[i].lap_time_start.value = 0; |
495 slot[i].lap_time.value = 0; |
498 slot[i].lap_time.value = 0; |
496 } |
499 } |
497 sysclk.value = 0; |
500 sysclk.value = 0; |