blackbox/main.c

changeset 125
edaf6a50276a
parent 124
0b12a8bf23b2
child 126
0d6fbfaae49b
equal deleted inserted replaced
124:0b12a8bf23b2 125:edaf6a50276a
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 10 35 #define PITLANE_SPEEDLIMIT 10
36 #define FINISHLINE_DIFF_BLOCK 1500 // minimum 750 ms between laps (prevents double counted lapt on finish crossing)
36 volatile uint8_t fuel_divisor = FUEL_DIV_DEFAULT; // default, can be set via serial command 37 volatile uint8_t fuel_divisor = FUEL_DIV_DEFAULT; // default, can be set via serial command
37 38
38 typedef struct { 39 typedef struct {
39 unsigned speedlimit:4; // 4bits speedlimit 40 unsigned speedlimit:4; // 4bits speedlimit
40 unsigned speedminimum:4; // 4bits speedminimum 41 unsigned speedminimum:4; // 4bits speedminimum
543 544
544 if (car0 != car0_state) { 545 if (car0 != car0_state) {
545 car0_state = car0; 546 car0_state = car0;
546 if (car0_state != 0) { 547 if (car0_state != 0) {
547 diff.value = clk.value - slot[car0-1].lap_time_start.value; 548 diff.value = clk.value - slot[car0-1].lap_time_start.value;
548 if ( diff.value > 3000 ) { // minimum 1.5 second for 1 lap! 549 if ( diff.value > FINISHLINE_DIFF_BLOCK ) {
549 if (slot[car0-1].lap_time_start.value != 0) { 550 if (slot[car0-1].lap_time_start.value != 0) {
550 slot[car0-1].lap_time.value = diff.value; 551 slot[car0-1].lap_time.value = diff.value;
551 slot[car0-1].laps++; 552 slot[car0-1].laps++;
552 RS232_puts("L:3:"); // 3 = BB 553 RS232_puts("L:3:"); // 3 = BB
553 itoa(slot[car0-1].laps, s, 16); 554 itoa(slot[car0-1].laps, s, 16);
570 571
571 if (car1 != car1_state) { 572 if (car1 != car1_state) {
572 car1_state = car1; 573 car1_state = car1;
573 if (car1_state != 0) { 574 if (car1_state != 0) {
574 diff.value = clk.value - slot[car1-1].lap_time_start.value; 575 diff.value = clk.value - slot[car1-1].lap_time_start.value;
575 if ( diff.value > 3000 ) { // minimum 1.5 second for 1 lap! 576 if ( diff.value > FINISHLINE_DIFF_BLOCK ) {
576 if (slot[car1-1].lap_time_start.value != 0) { 577 if (slot[car1-1].lap_time_start.value != 0) {
577 slot[car1-1].lap_time.value = diff.value; 578 slot[car1-1].lap_time.value = diff.value;
578 slot[car1-1].laps++; 579 slot[car1-1].laps++;
579 RS232_puts("L:1:"); // 1 = AA 580 RS232_puts("L:1:"); // 1 = AA
580 itoa(slot[car1-1].laps, s, 16); 581 itoa(slot[car1-1].laps, s, 16);

mercurial