blackbox/main.c

changeset 83
c8e7a69a318a
parent 81
4f2f94a043fd
child 89
4b5b4c7ba03d
equal deleted inserted replaced
82:c89221096db7 83:c8e7a69a318a
26 } u32; 26 } u32;
27 27
28 #define FUEL_FULL 10000 28 #define FUEL_FULL 10000
29 #define FUEL_JUMPSTART 5000 29 #define FUEL_JUMPSTART 5000
30 #define FUEL_DIV_DEFAULT 25 30 #define FUEL_DIV_DEFAULT 25
31 #define PITLANE_SPEEDLIMIT 4
31 volatile uint8_t fuel_divisor = FUEL_DIV_DEFAULT; // default, can be set via serial command 32 volatile uint8_t fuel_divisor = FUEL_DIV_DEFAULT; // default, can be set via serial command
32 33
33 typedef struct { 34 typedef struct {
34 unsigned speedlimit:4; // 4bits speedlimit 35 unsigned speedlimit:4; // 4bits speedlimit
35 unsigned speedminimum:4; // 4bits speedminimum 36 unsigned speedminimum:4; // 4bits speedminimum
309 310
310 if (controller < 4) { 311 if (controller < 4) {
311 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; 312 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum;
312 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } 313 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; }
313 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; 314 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit;
315 if (slot[controller].canrefuel && (tmp > PITLANE_SPEEDLIMIT)) tmp = PITLANE_SPEEDLIMIT;
314 speed = tmp; 316 speed = tmp;
315 tmp = tmp << 1; 317 tmp = tmp << 1;
316 } else { 318 } else {
317 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; 319 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum;
318 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; 320 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit;
496 slot[car0-1].lap_time_start.value = clk.value; 498 slot[car0-1].lap_time_start.value = clk.value;
497 } 499 }
498 } 500 }
499 } car0 = 0; 501 } car0 = 0;
500 502
503
501 if (car1 != car1_state) { 504 if (car1 != car1_state) {
502 car1_state = car1; 505 car1_state = car1;
503 if (car1_state != 0) { 506 if (car1_state != 0) {
504 diff.value = clk.value - slot[car1-1].lap_time_start.value; 507 diff.value = clk.value - slot[car1-1].lap_time_start.value;
505 if ( diff.value > 3000 ) { // minimum 1.5 second for 1 lap! 508 if ( diff.value > 3000 ) { // minimum 1.5 second for 1 lap!
521 } 524 }
522 slot[car1-1].lap_time_start.value = clk.value; 525 slot[car1-1].lap_time_start.value = clk.value;
523 } 526 }
524 } 527 }
525 } car1 = 0; 528 } car1 = 0;
529
526 } 530 }
527 531
528 void slot_liveinfo(uint8_t idx) { 532 void slot_liveinfo(uint8_t idx) {
529 if (liveinfo == 0) return; 533 if (liveinfo == 0) return;
530 // increment packet counter, if == 10 output some live info 534 // increment packet counter, if == 10 output some live info

mercurial