can't push chnages :(

Fork of FBRDash by Michael Allan

Revision:
5:177520d43c87
Parent:
4:53b28844b594
--- a/main.cpp	Mon Jun 25 21:59:31 2012 +0000
+++ b/main.cpp	Sun Oct 14 21:09:49 2012 +0000
@@ -39,21 +39,55 @@
 //Main car state structure
 State car;
 
+//Initialise CAN
+CAN can(p30, p29);
+
 //Classes for various parts of the firmware
-Menu dashMenu(&lcd, p13, p14, p15); //*LCD, OK, Left, Right
+Menu dashMenu(&lcd, p16, p17, p12); //*LCD, OK, Left, Right
 PCComms pc(&car);
-Gears gearButtons(p17, p16, p12, &car.gear, &pc); //Up, Neutral, Down, *Current Gear
+Gears gearButtons(p14, p13, p15, &car.gear, &pc); //Up, Neutral, Down, *Current Gear
 LEDS revs(leds);
 
 //Refresh the rev LEDs and warning LEDs
 void revRefresh()
 {
+    CANMessage msg;
     revs.refresh(car.rpm);
     
-    for(int i = 0; i < 4; i++)
-    {
-        warn[i] = car.warnings & (1 << i);
+    if(car.voltage<12){
+        warn[0]=1;
+    }else{
+        warn[0]=0;
+    }
+    if(car.coolant_temp>110){
+        warn[1]=1;
+    }else{
+        warn[1]=0;
+    }
+    if(car.rpm==0 and car.gear!=0){
+        warn[2]=1;
+    }else{
+        warn[2]=0;
     }
+    if(can.read(msg)) {
+        if(msg.id==100 and msg.len==8){
+            car.rpm = msg.data[0] + (msg.data[1] << 8);
+            car.throttle_pos = msg.data[2];
+            car.manifold_pres = msg.data[3];
+            car.air_temp = msg.data[4];
+            car.coolant_temp = msg.data[5];
+            car.lambda = msg.data[6];
+        }
+        else if(msg.id==200 and msg.len==8){
+            car.speed = msg.data[0];
+            car.accel_x = msg.data[1];
+            car.accel_y = msg.data[2];
+            car.gear = msg.data[3];
+            car.oil_temp = msg.data[4];
+            car.voltage = msg.data[5]/16.0;
+        } 
+    }
+
 }
 
 //Refresh the LCD
@@ -63,9 +97,9 @@
     if(dashMenu.display == false)
     {
         lcd.locate(0, 0);
-        lcd.printf("R:%-11.0d", car.rpm);
+        lcd.printf("%3.0fC%5.1dRPM", car.coolant_temp, car.rpm);
         lcd.locate(0, 1);
-        lcd.printf("S:%-3d T:%-5.0f", car.speed, car.coolant_temp);
+        lcd.printf("%2dMPH %3.1fV", car.speed, car.voltage);
         
         write_bigchar(&lcd, 13, car.gear);
     }
@@ -91,14 +125,36 @@
 void selfTest()
 {
     lcd.printf("    FBR 2012");
-    
+    lcd.locate(0,1);
+    lcd.printf(" Ready to drive");
+    int offset = 0;
+    int type=1;
+    int blk=7;
+    int from=1;
+    int to=0;
+    int id = offset*262144+type*32768+from*2048+to*128+blk*8;
+    CANMessage msg;
+    msg = CANMessage(id,0,8,CANData,CANExtended);
+    lcd.cls();
+    lcd.printf("%x",id);
+    can.reset();
+    if(can.write(msg)){
+    wait(0.01);
+    lcd.printf(" %d errors",can.tderror());
+    can.reset();
+    while(can.read(msg)==false){
+    wait(0.1);
+    }
+    wait(0.5);
+    lcd.printf(" %d errors",can.tderror());
+    }
     //Light up LEDs
     for(int i = 0; i < LEDS::NUM_LEDS; i++)
     {
         leds[i] = true;
         if(i < 4)
             warn[i] = true;
-        wait(0.04);
+        wait(0.2);
     }
     
     //Turn off LEDs
@@ -107,7 +163,7 @@
         leds[i] = false;
         if(i < 4)
             warn[i] = false;
-        wait(0.04);
+        wait(0.2);
     }
     
     lcd.cls();
@@ -115,20 +171,21 @@
 
 int main()
 {   
+    //Initialise CAN
+    can.frequency(500000);
     //Initialise state
-    car.rpm = 5000;
-    car.gear = 0;
-    car.speed = 150;
-    car.coolant_temp = 21.5;    
-    car.throttle_pos = 1;
-    car.manifold_pres = 2;
-    car.air_temp = 3;
-    car.lambda = 5;
-    car.accel_x = 7;
-    car.accel_y = 8;
-    car.oil_temp = 10;
-    car.oil_pres = 11;
-    car.warnings = 12;
+    car.rpm = 0;
+    car.gear = 2;
+    car.speed = 0;
+    car.coolant_temp = 0;    
+    car.throttle_pos = 0;
+    car.manifold_pres = 0;
+    car.air_temp = 0;
+    car.lambda = 0;
+    car.accel_x = 0;
+    car.accel_y = 0;
+    car.oil_temp = 0;
+    car.voltage = 0;
 
     //Set up menu
     dashMenu.addItem<float>("Coolant Temp  ", "%12.1f\xDF\x43", &car.coolant_temp); // \xDF\x43 -> &#65533;C . Need code for C as otherwise it gets taken as hex digit.
@@ -137,7 +194,6 @@
     dashMenu.addItem<unsigned char>("Manifold Pres ", "%10d psi", &car.manifold_pres);
     dashMenu.addItem<unsigned char>("Lambda        ", "%14d", &car.lambda);    
     dashMenu.addItem<unsigned char>("Oil Temp      ", "%12d\xDF\x43", &car.oil_temp);
-    dashMenu.addItem<unsigned char>("Oil Pressure  ", "%10d psi", &car.oil_pres);
     
     //Set up characters on LCS
     setup_bigchar(&lcd);