blackbox/main.c

changeset 10
6d6e982bbc41
parent 8
84249ab5d691
child 11
69c2a1408619
--- a/blackbox/main.c	Wed Nov 16 17:04:10 2011 +0100
+++ b/blackbox/main.c	Fri Nov 18 08:42:24 2011 +0100
@@ -54,7 +54,11 @@
                     if (program_count == 0) {
                         program_id = buffer[3]-'0';
                         program_command = buffer[1]-'0';
+                        if (program_command > 9)
+                            program_command = buffer[1]-'A'+10;
                         program_parameter = buffer[2]-'0';
+                        if (program_parameter > 9)
+                            program_parameter = buffer[2]-'A'+10;
                         if (program_command < 4)
                             program_count = 0x02; // send commands twice (fuel, speed, brake)
                             else
@@ -91,19 +95,31 @@
     switch (controller) {
         case 0:
             tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
-            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) tmp |= (1<<5);
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) {
+                tmp |= (1<<5);
+                LED(1,0);
+            } else LED(1,1);
             break;
         case 1:
             tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
-            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) tmp |= (1<<5);
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) {
+                tmp |= (1<<5);
+                LED(2,0);
+            } else LED(2,1);
             break;
         case 2:
             tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
-            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) tmp |= (1<<5);
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) {
+                tmp |= (1<<5);
+                LED(3,0);
+            } else LED(3,1);
             break;
         case 3:
             tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
-            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) tmp |= (1<<5);
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) {
+                tmp |= (1<<5);
+                LED(4,0);
+            } else LED(4,1);
             break;
         case 4: tmp = (1<<5); break; // todo regler 5
         case 5: tmp = (1<<5); break; // todo regler 6
@@ -157,7 +173,7 @@
 ISR ( TIMER1_COMPA_vect ) {
     // trigger packet transfer:
     transmit_len = transmit_len_next;
-    LED(2,2);
+    //LED(2,2);
 
     // here is some more time to do something else...
 }
@@ -201,14 +217,14 @@
         }
     }
 
-    LED(3,2);
+    //LED(3,2);
 }
 
 
 ISR ( TIMER0_OVF_vect ) {
 // TODO: last bit should be set by the sender, not from us!
     TCNT0 = TIMER0_250US;
-    LED(1,2);
+    //LED(1,2);
     if (timer0_delay == 0) {
         RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // pull rails low
         _delay_us(28); // wait some cycles
@@ -283,6 +299,7 @@
                     program_parameter = 9;
                     program_id = 0;
                     program_count = 1;
+                    LAP_COUNTER_PORT |= _BV(LAP_COUNTER);
                 } else {
                     // do a reset, switch back to free drive mode 0
                     mode = 0;
@@ -291,6 +308,7 @@
                     program_parameter = 0;
                     program_id = 7;
                     program_count = 1;
+                    LAP_COUNTER_PORT &= ~_BV(LAP_COUNTER);
                 }
             }
             //LAP_COUNTER_PORT |= _BV(LAP_COUNTER);

mercurial