blackbox/main.c

changeset 124
0b12a8bf23b2
parent 123
ec623e5fcbca
child 125
edaf6a50276a
equal deleted inserted replaced
123:ec623e5fcbca 124:0b12a8bf23b2
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 15 35 #define PITLANE_SPEEDLIMIT 10
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
61 // 255 PANIC MODE -> TURN OFF TRACK POWER 61 // 255 PANIC MODE -> TURN OFF TRACK POWER
62 62
63 extern uint8_t btn_start = _BV(SW_START); 63 extern uint8_t btn_start = _BV(SW_START);
64 extern uint8_t old_start = _BV(SW_START); 64 extern uint8_t old_start = _BV(SW_START);
65 65
66 66 // todo: pack as bit structure:
67 uint8_t liveinfo = 0; 67 uint8_t liveinfo = 0;
68 uint8_t fuel_enabled = 1; 68 uint8_t fuel_enabled = 1;
69 uint8_t pitlane_finishline = 0;
69 70
70 volatile u32 sysclk; 71 volatile u32 sysclk;
71 volatile uint8_t sysclk_packettimer = 0; 72 volatile uint8_t sysclk_packettimer = 0;
72 volatile cardata slot[MAX_SLOTS]; 73 volatile cardata slot[MAX_SLOTS];
73 74
149 uint8_t sender = (data & 0b1111); 150 uint8_t sender = (data & 0b1111);
150 data >>= 4; 151 data >>= 4;
151 uint8_t type = (data & 0b111); 152 uint8_t type = (data & 0b111);
152 if (type == 4) { 153 if (type == 4) {
153 // pitlane response 154 // pitlane response
154 if (status == 5) slot[car].canrefuel = 1; 155 if (status == 5) {
156 slot[car].canrefuel = 1;
157 if (pitlane_finishline) slot[car].laps++;
158 }
155 if (status == 6) for (data=0; data<MAX_SLOTS; data++) slot[data].canrefuel = 0; 159 if (status == 6) for (data=0; data<MAX_SLOTS; data++) slot[data].canrefuel = 0;
156 if (status == 7) slot[car].canrefuel = 0; 160 if (status == 7) slot[car].canrefuel = 0;
157 } 161 }
158 RS232_puts("RW:"); 162 RS232_puts("RW:");
159 RS232_putc(car + '0'); 163 RS232_putc(car + '0');
274 278
275 case '*': // set live information 279 case '*': // set live information
276 liveinfo = buffer[1]-'0'; 280 liveinfo = buffer[1]-'0';
277 RS232_puts_p(ok); 281 RS232_puts_p(ok);
278 break; 282 break;
283
284 case 'X': // set Pitlane act as finish line
285 // this can be used if pitlane exit comes after finish line while pitlane entry is before finish line
286 pitlane_finishline = buffer[1]-'0';
287 RS232_puts_p(ok);
288 break;
289
279 290
280 case '#': // remote start button press 291 case '#': // remote start button press
281 RS232_puts_p(ok); 292 RS232_puts_p(ok);
282 startbutton(); 293 startbutton();
283 break; 294 break;

mercurial