can't push chnages :(

Fork of FBRDash by Michael Allan

Files at this revision

API Documentation at this revision

Comitter:
tomontoast
Date:
Sun Oct 14 21:09:49 2012 +0000
Parent:
4:53b28844b594
Commit message:
14/10/12

Changed in this revision

inc/LEDS.h Show annotated file Show diff for this revision Revisions of this file
inc/State.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
src/Comms.cpp Show annotated file Show diff for this revision Revisions of this file
src/LEDS.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/inc/LEDS.h	Mon Jun 25 21:59:31 2012 +0000
+++ b/inc/LEDS.h	Sun Oct 14 21:09:49 2012 +0000
@@ -1,25 +1,22 @@
-#ifndef FBRDASH_LEDS_H
-#define FBRDASH_LEDS_H
-
-#include "mbed.h"
-
-class LEDS
-{
-    public:
-        LEDS(PwmOut _pins[]);
-        void refresh(float rpm);
-        
-        static const int NUM_LEDS = 6;
-    
-    private:
-        PwmOut* pins;
-    
-    //revs represented by last red LED
-    static const int LIMIT = 18000.0;
-    
-    //number of revs per LED
-    static const int RESOLUTION = LIMIT / NUM_LEDS;
-        
-};
-
+#ifndef FBRDASH_LEDS_H
+#define FBRDASH_LEDS_H
+
+#include "mbed.h"
+
+class LEDS
+{
+    public:
+        LEDS(PwmOut _pins[]);
+        void refresh(float rpm);
+        
+        static const int NUM_LEDS = 6;
+    
+    private:
+        PwmOut* pins;
+    
+    //revs represented by last red LED
+    static const int LIMIT = 12000.0;
+        
+};
+
 #endif
\ No newline at end of file
--- a/inc/State.h	Mon Jun 25 21:59:31 2012 +0000
+++ b/inc/State.h	Sun Oct 14 21:09:49 2012 +0000
@@ -14,8 +14,8 @@
     unsigned char accel_y;
     unsigned char gear;
     unsigned char oil_temp;
-    unsigned char oil_pres;
     unsigned char warnings;
+    float voltage;
 };
 
 #endif
\ No newline at end of file
--- 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);
--- a/src/Comms.cpp	Mon Jun 25 21:59:31 2012 +0000
+++ b/src/Comms.cpp	Sun Oct 14 21:09:49 2012 +0000
@@ -29,7 +29,7 @@
             values->accel_y = data[2];
             values->gear = data[3];
             values->oil_temp = data[4];
-            values->oil_pres = data[5];
+            values->voltage = data[5];
             values->warnings = data[6];
             break;
     }
--- a/src/LEDS.cpp	Mon Jun 25 21:59:31 2012 +0000
+++ b/src/LEDS.cpp	Sun Oct 14 21:09:49 2012 +0000
@@ -14,30 +14,16 @@
 //Calculate new PWM values
 void LEDS::refresh(float rpm)
 {
-    int value;
-    int remainder;
-    int i;
     
-    //Number of fully-lit LEDs
-    value = rpm / RESOLUTION;
-  
-    for(i = 0; i < NUM_LEDS; i++)
-    {          
-        if(i < value)
-        {   
-            //First LEDs on
-            pins[i] = 1.0;
-        }
-        else if(i == value)
-        {
-            //Last LED partially lit - calculate intensity and set.
-            remainder = (int)rpm % RESOLUTION;
-            pins[i] = (float)remainder / (float)RESOLUTION;
-        }
-        else
-        {
-            //All others off
-            pins[i] = 0.0;
-        }
-    }
+    //Engine running
+    pins[0]=(rpm-1000)/4000;
+    //Change Down
+    pins[1]=(rpm-5000)/2000;
+    //Good gear
+    pins[2]=(rpm-7000)/2000;
+    pins[3]=(rpm-9000)/2000;
+    //Change up
+    pins[4]=(rpm-11000)/500;
+    //Change up urgently
+    pins[5]=(rpm-11500)/500;
 }
\ No newline at end of file