The Code Repository for the REV0 Steering Wheel.

Dependencies:   CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses

Fork of REVO_Updated_Steering by Penn Electric

Revision:
45:aea289639d6b
Parent:
40:92f08fdc32df
--- a/Screens.h	Thu May 14 18:49:05 2015 +0000
+++ b/Screens.h	Fri May 15 04:14:09 2015 +0000
@@ -3,7 +3,6 @@
 
 // Macro for printing to screen; Where y is the start poition of the text, and y2 is the start position of the variable
 #define PUT2SCREEN(string, var, unit, x, y, y2)   display.PutString(x, y,  string);   display.PutString(x, y2, var);   display.PutString(x,y2+15,unit);
-
 #define HOME_SCREEN     0
 #define BATTERY_SCREEN  1
 #define MOTOR_SCREEN    2
@@ -12,31 +11,55 @@
 #define FAULT_SCREEN    5
 
 
-
+char display_string_buffer[30];
+char* formatPercentage(int CANID){
+    return float_to_string(CANID);
+}
+char* wheel_speed(int CANID){
+    float average_rpm =*((float*)message_data[CANID])+*((float*)(message_data[CANID]+4))
+    //assuming nominal tire diameter of 19.25in
+    sprintf(display_string_buffer,"%2.2f",average_rpm*1.09375);
+    return display_string_buffer;
+}
+char* CtoF(int CANID){
+    sprintf(display_string_buffer,"3.2f", 32+9*((float*)message_data[CANID])/5;
+    return display_string_buffer;
+}
+char* CtoF(int CANID,int index){
+    sprintf(display_string_buffer,"3.2f", 32+9*((float*)message_data[CANID]+index)/5;
+    return display_string_buffer;
+}
+char* float_to_string(int CANID){
+    sprintf(display_string_buffer,"%3.2f",message_data[CANID]);
+    return display_string_buffer;
+}
+char* float_to_string(int CANID,int index){
+    sprintf(display_string_buffer,"%3.2f",*((float*)(message_data[CANID]+index)));
+    return display_string_buffer;
+}
 // Initialize Variables
 int  CurrScreen = HOME_SCREEN;
 int  PrevScreen = !CurrScreen;
 
 // Defines the pins for the dsiplay. These are hardwired.
 KS0108 display(p26, p21, p22, p23, p25, p24, p8, p7, p6, p5, p13, p14, p12, p11);
-
 void DisplayHomeScreen()
 {
     display.ClearScreen();
     display.PutString(0, 54, "Home");
 
     //Info line 1: Battery Life & Vehicle Speed
-    PUT2SCREEN("BatLife:",  BigBatLifeBuffer,   "%",   1,  0, 39);
-    PUT2SCREEN(",",         SmallBatLifeBuffer, "%",   1, 59, 62);
-    PUT2SCREEN("Spd:",      CarSpdBuffer,       "",    1, 89,108);
+    PUT2SCREEN("BatLife:",  formatPercentage(0x30B),   "%",   1,  0, 39);//SOC_TX_ID
+    PUT2SCREEN(",",         formatPercentage(0x513), "%",   1, 59, 62);//SYS_GLV_SOC_ID
+    PUT2SCREEN("Spd:",      wheel_speed(0x222),       "mph",    1, 89,108);//PCM_FRPM_ID
 
     //Info line 2: Average Battery Temp & Peak Battery Temp
-    PUT2SCREEN("AvgBatT:",  AvgBatTBuffer,   "F",      3,  0, 39);
-    PUT2SCREEN("PkBatT:",   MaxBatTBuffer,   "F",      3, 69,103);
+    PUT2SCREEN("AvgBatT:",  CtoF(0x319),   "F",      3,  0, 39);//TEMP_MMA_TX_ID_BASE2
+    PUT2SCREEN("PkBatT:",   CtoF(0x318),   "F",      3, 69,103);//TEMP_MMA_TX_ID_BASE
 
     //Info line 3: Left Motor Temp & Right Motor Temp
-    PUT2SCREEN("LMtTmp:",   LMtrTmpBuffer,   "F",      5,  0, 34);
-    PUT2SCREEN("RMtTmp:",   RMtrTmpBuffer,   "F",      5, 69,103);
+    PUT2SCREEN("LMtTmp:",   CtoF(0x212),   "F",      5,  0, 34);//MOC_MOTEMP_ID
+    PUT2SCREEN("RMtTmp:",   CtoF(0x212,4),   "F",      5, 69,103);//MOC_MOTEMP_ID bytes 4-7
 
     //Fault line
     display.PutString(7, 14, "Reserved for faults");
@@ -48,22 +71,22 @@
     display.PutString(0, 34, "Main Battery");
 
     //Info line 1: Battery Voltage, Power & Current
-    PUT2SCREEN("V:",        BigBatVoltBuffer,       "V",    1,   0, 10);
-    PUT2SCREEN("P:",        BigBatPowerBuffer,      "W",    1,  45, 55);
-    PUT2SCREEN("I:",        BigBatCurrentBuffer,    "A",    1,  90,100);
+    PUT2SCREEN("V:",        float_to_string(0x308),       "V",    1,   0, 10);//VOLTAGE_TX_ID
+    PUT2SCREEN("P:",       float_to_string(0x314),      "W",    1,  45, 55);//POWER_TX_ID
+    PUT2SCREEN("I:",        float_to_string(0x306),    "A",    1,  90,100);//CURRENT_TX_ID
 
     //Info line 2: High, Low, & Average Cell Voltage
-    PUT2SCREEN("Vmx:",      VmaxBuffer,             "V",    3,   0, 20);
-    PUT2SCREEN("Vmn:",      VminBuffer,              "",    3,  47, 67);
-    PUT2SCREEN("Vav:",      VavgBuffer,              "",    3,  88,108);
+    PUT2SCREEN("Vmx:",      VmaxBuffer,             "V",    3,   0, 20);//CELLV_MMA_TX_ID_BASE 4-7
+    PUT2SCREEN("Vmn:",      VminBuffer,              "",    3,  47, 67);//CELLV_MMA_TX_ID_BASE 0-3
+    PUT2SCREEN("Vav:",      VavgBuffer,              "",    3,  88,108);//CELLV_MMA_TX_ID_BASE2
 
     //Info line 3: High, Low, & Average Cell Temp
-    PUT2SCREEN("Tmx:",        MaxBatTBuffer,       "F",     5,  0, 20);
-    PUT2SCREEN("Tmn:",        MinBatTBuffer,        "",     5, 47, 67);
-    PUT2SCREEN("Tav:",        AvgBatTBuffer,        "",     5, 88,108);
+    PUT2SCREEN("Tmx:",        MaxBatTBuffer,       "F",     5,  0, 20);//TEMP_MMA_TX_ID_BASE 4-7
+    PUT2SCREEN("Tmn:",        MinBatTBuffer,        "",     5, 47, 67);//TEMP_MMA_TX_ID_BASE 0-3
+    PUT2SCREEN("Tav:",        AvgBatTBuffer,        "",     5, 88,108);//TEMP_MMA_TX_ID_BASE2
 
     //Info line 4: Highest Board Temp
-    PUT2SCREEN("HighBoardTemp:",  BoardTempBuffer,   "F",   7,  17, 87);
+    PUT2SCREEN("HighBoardTemp:",  BoardTempBuffer,   "F",   7,  17, 87);//BOARDTEMP_TX_ID
 }
 
 void DisplayMotorScreen()