implemented lap counter, doesnt count first sensor touch

Thu, 08 Dec 2011 15:56:20 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Thu, 08 Dec 2011 15:56:20 +0100
changeset 47
34ac9f92bc1e
parent 46
d200e3d8a550
child 48
5bba01aad0a6

implemented lap counter, doesnt count first sensor touch

blackbox/main.c file | annotate | diff | comparison | revisions
blackbox/main.h file | annotate | diff | comparison | revisions
--- 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;
--- 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 <avr/wdt.h>
 #include <stdint.h>
 
-#define VERSION "1.2"
+#define VERSION "1.3"
 
 #define COUNTDOWN_DELAY         10 // x/10 seconds
 

mercurial