# HG changeset patch # User Malte Bayer # Date 1323356180 -3600 # Node ID 34ac9f92bc1e0a6776e47f6597d18068faf3bfe0 # Parent d200e3d8a550ca605c0b093b3ba2d749366b0097 implemented lap counter, doesnt count first sensor touch diff -r d200e3d8a550 -r 34ac9f92bc1e blackbox/main.c --- a/blackbox/main.c Thu Dec 08 15:44:43 2011 +0100 +++ b/blackbox/main.c Thu Dec 08 15:56:20 2011 +0100 @@ -27,8 +27,8 @@ #define MAX_SLOTS 6 typedef struct { - uint8_t speedlimit, fuel, laps; - uint16_t jumpstart_time; + uint8_t speedlimit, fuel; + uint16_t jumpstart_time, laps; u32 lap_time_start, lap_time; } cardata; @@ -390,6 +390,7 @@ if (i<4) slot[i].speedlimit = 15; else slot[i].speedlimit = 0; slot[i].fuel = 100; slot[i].jumpstart_time = 0; + slot[i].laps = 0; } sysclk.value = 0; } @@ -426,15 +427,23 @@ if (car0_state != 0) { diff.value = clk.value - slot[car0-1].lap_time_start.value; if ( diff.value > 3000 ) { // minimum 1.5 second for 1 lap! + if (slot[car0-1].lap_time_start.value != 0) { + slot[car0-1].lap_time.value = diff.value; + slot[car0-1].laps++; + RS232_putc('L'); + RS232_putc(':'); + RS232_putc('A'); + RS232_putc(':'); + itoa(slot[car0-1].laps, s, 16); + RS232_puts(s); + RS232_putc(':'); + RS232_putc('0'+car0_state); + RS232_putc(':'); + ultoa(diff.value, s, 16); + RS232_puts(s); + RS232_putc('\n'); + } slot[car0-1].lap_time_start.value = clk.value; - slot[car0-1].lap_time.value = diff.value; - RS232_putc('L'); - RS232_putc('A'); - RS232_putc('0'+car0_state); - RS232_putc(':'); - ultoa(diff.value, s, 16); - RS232_puts(s); - RS232_putc('\n'); } } } car0 = 0; @@ -444,15 +453,23 @@ if (car1_state != 0) { diff.value = clk.value - slot[car1-1].lap_time_start.value; if ( diff.value > 3000 ) { // minimum 1.5 second for 1 lap! + if (slot[car1-1].lap_time_start.value != 0) { + slot[car1-1].lap_time.value = diff.value; + slot[car1-1].laps++; + RS232_putc('L'); + RS232_putc(':'); + RS232_putc('B'); + RS232_putc(':'); + itoa(slot[car1-1].laps, s, 16); + RS232_puts(s); + RS232_putc(':'); + RS232_putc('0'+car1_state); + RS232_putc(':'); + ultoa(diff.value, s, 16); + RS232_puts(s); + RS232_putc('\n'); + } slot[car1-1].lap_time_start.value = clk.value; - slot[car1-1].lap_time.value = diff.value; - RS232_putc('L'); - RS232_putc('B'); - RS232_putc('0'+car1_state); - RS232_putc(':'); - ultoa(diff.value, s, 16); - RS232_puts(s); - RS232_putc('\n'); } } } car1 = 0; diff -r d200e3d8a550 -r 34ac9f92bc1e blackbox/main.h --- a/blackbox/main.h Thu Dec 08 15:44:43 2011 +0100 +++ b/blackbox/main.h Thu Dec 08 15:56:20 2011 +0100 @@ -4,7 +4,7 @@ #include #include -#define VERSION "1.2" +#define VERSION "1.3" #define COUNTDOWN_DELAY 10 // x/10 seconds