implemented lap time, there is some bug in 32bit substraction yet

Wed, 07 Dec 2011 17:22:58 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Wed, 07 Dec 2011 17:22:58 +0100
changeset 44
4f4326794ba4
parent 43
4e5d389f7b83
child 45
da820f138498

implemented lap time, there is some bug in 32bit substraction yet

blackbox/main.c file | annotate | diff | comparison | revisions
--- a/blackbox/main.c	Wed Dec 07 17:00:32 2011 +0100
+++ b/blackbox/main.c	Wed Dec 07 17:22:58 2011 +0100
@@ -39,6 +39,11 @@
 volatile uint8_t fuel[MAX_SLOTS];
 volatile uint16_t jumpstart_time[MAX_SLOTS];
 
+volatile uint16_t lap_time_start_low[MAX_SLOTS];
+volatile uint16_t lap_time_start_high[MAX_SLOTS];
+volatile uint16_t lap_time_low[MAX_SLOTS];
+volatile uint16_t lap_time_high[MAX_SLOTS];
+
 volatile uint16_t car0, car1;
 volatile uint16_t car0_new, car0_old;
 volatile uint16_t car1_new, car1_old;
@@ -413,23 +418,53 @@
 }
 
 void check_cars(void) {
+    uint16_t diff_low, diff_high;
+
     if (car0 != car0_state) {
         car0_state = car0;
         if (car0_state != 0) {
-            RS232_putc('A');
-            RS232_putc('A');
-            RS232_putc('0'+car0_state);
-            RS232_putc('\n');
+            diff_high = sysclk_ms_high - lap_time_start_high[car0-1];
+            diff_low = sysclk_ms_low - lap_time_start_low[car0-1]; // this could be a bug ;)
+            if ( (diff_high > 0) || (diff_low>2000) ) { // minimum 1 second for 1 lap!
+                lap_time_start_low[car0-1] = sysclk_ms_low;
+                lap_time_start_high[car0-1] = sysclk_ms_high;
+                lap_time_low[car0-1] = diff_low;
+                lap_time_high[car0-1] = diff_high;
+                RS232_putc('L');
+                RS232_putc('A');
+                RS232_putc('0'+car0_state);
+                RS232_putc(':');
+                itoa(diff_high, s, 16);
+                RS232_puts(s);
+                RS232_putc(',');
+                itoa(diff_low, s, 16);
+                RS232_puts(s);
+                RS232_putc('\n');
+            }
         }
     } car0 = 0;
 
     if (car1 != car1_state) {
         car1_state = car1;
         if (car1_state != 0) {
-            RS232_putc('B');
-            RS232_putc('B');
-            RS232_putc('0'+car1_state);
-            RS232_putc('\n');
+            diff_high = sysclk_ms_high - lap_time_start_high[car1-1];
+            diff_low = sysclk_ms_low - lap_time_start_low[car1-1]; // this could be a bug ;)
+            if ( (diff_high > 0) || (diff_low>2000) ) { // minimum 1 second for 1 lap!
+                lap_time_start_low[car1-1] = sysclk_ms_low;
+                lap_time_start_high[car1-1] = sysclk_ms_high;
+                lap_time_low[car1-1] = diff_low;
+                lap_time_high[car1-1] = diff_high;
+                RS232_putc('L');
+                RS232_putc('B');
+                RS232_putc('0'+car1_state);
+                RS232_putc(':');
+                itoa(diff_high, s, 16);
+                RS232_puts(s);
+                RS232_putc(',');
+                itoa(diff_low, s, 16);
+                RS232_puts(s);
+                RS232_putc('\n');
+            }
         }
     } car1 = 0;
 }

mercurial