Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Sat Jun 29 02:44:02 2013 +0000
Branch:
Metric
Parent:
106:f016912a03db
Child:
108:29b5a760adc2
Commit message:
Added trip meter

Changed in this revision

common.h Show annotated file Show diff for this revision Revisions of this file
displayModes.cpp Show annotated file Show diff for this revision Revisions of this file
displayModes.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
utility.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/common.h	Fri Jun 28 20:26:11 2013 +0000
+++ b/common.h	Sat Jun 29 02:44:02 2013 +0000
@@ -13,7 +13,8 @@
 #define dateScreen 12
 #define configScreen 13
 #define indexScreen 14
-#define maxScreens 14
+#define tripScreen 15
+#define maxScreens 15
 
 #define btnGap 10
 #define ttSkin 0
@@ -24,13 +25,6 @@
 #define canTimeout 5
 #define userTimeout 15
 
-//#define BatDataBaseG1 0x24 
-//#define BatDataBaseG2 0x00 // Cell Pair data
-//#define BatDataBaseG3 0x2B 
-//#define BatDataBaseG4 0x20 // Temperature data 0x20 * 7 = 224
-//#define BatDataBaseG5 0x31
-//#define BatDataBufMax 0x1B2 // 7 x 3E bytes
-
 #define BatDataBaseG1 0x00 // 6 frames - SOH, SOC, Ah
 #define BatDataBaseG2 0x06 // 29 frames - Cell Pair data
 #define BatDataBaseG3 0x23 // 5 frames
--- a/displayModes.cpp	Fri Jun 28 20:26:11 2013 +0000
+++ b/displayModes.cpp	Sat Jun 29 02:44:02 2013 +0000
@@ -71,10 +71,30 @@
     lastldl=ldl;
 }
 
+void tripDisplay (bool force, bool showButtons){
+    static float lmiles=0;
+    tt.background(White);
+    if(force){
+        tt.cls();
+    }
+    if(force||lmiles!=miles_trip[0]){ //only update if changed
+        tt.foreground(Navy);
+        tt.set_font((unsigned char*) Arial28x28);
+        tt.locate(1,10);
+        printf("kWh : %s : Eff\n",distanceUnit());
+        for(int i=0; i<3; i++){
+            tt.locate(1,60+i*40);
+            printf("%3.2f : %3.1f : %2.1f\n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]);
+        }
+        tt.set_font((unsigned char*) Arial12x12);
+        showButton(3,1," Reset","",4,4);
+        showButton(3,2," Reset","",4,4);
+    }
+}
+
 void mainDisplay (bool force, bool showButtons){
     unsigned short gids, SOC, packV;
     static unsigned short lgids=0, lSOC=0, lSOH=0, lpackV=0, maxPS=0;
-    //static unsigned char lbattTemp_x4=0;
     static signed short lbattTemp_x10=0;
     static float lkW=0, laccV=0, lmpkWh=0;
     static unsigned long lAh=0;
@@ -363,6 +383,7 @@
             jv=0;
         }
 
+        char* sTemperatureUnit = temperatureUnit();
         switch(step){
             case 0:
                 tt.cls();
@@ -370,7 +391,6 @@
                 break;
             case 1:
                 tt.locate(0,6);
-                char* sTemperatureUnit = temperatureUnit();
                 printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n",
                     max,min,avg,jv, convertTemperature(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertTemperature(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
                     convertTemperature(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertTemperature(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
@@ -1076,6 +1096,9 @@
         case indexScreen:
             showIndex(changed,(display==whichTouched));
             break;
+        case tripScreen:
+            tripDisplay(changed,(display==whichTouched));
+            break;
         default:
             if (changed){
                 tt.background(Black);
@@ -1141,6 +1164,9 @@
                     case cpBarScreen: // gg - cpbars
                         sprintf(sTemp2,"CP Bars");
                         break;
+                    case tripScreen:
+                        sprintf(sTemp2," Trip");
+                        break;
                     case indexScreen: // gg - index
                         sprintf(sTemp2," Index");
                         break;
--- a/displayModes.h	Fri Jun 28 20:26:11 2013 +0000
+++ b/displayModes.h	Sat Jun 29 02:44:02 2013 +0000
@@ -32,6 +32,8 @@
 extern bool playbackEn;
 extern bool playbackOpen;
 extern float playbackInt;
+extern float miles_trip[3];
+extern float kWh_trip[3];
 extern float kW[39];
 extern float mpkWh[39];
 extern unsigned char whichTouched;
--- a/main.cpp	Fri Jun 28 20:26:11 2013 +0000
+++ b/main.cpp	Sat Jun 29 02:44:02 2013 +0000
@@ -30,7 +30,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "105";
+char revStr[7] = "107";
 
 LocalFileSystem local("local");
 
@@ -125,6 +125,8 @@
 signed long motorRPM;
 unsigned char skin = ttSkin ;
 unsigned char dtePeriod = 14; //ten minute averaging interval
+float kWh_trip[3]={0};
+float miles_trip[3]={0};
 float mph[39]={0};
 float kW[39]={0};
 float mpkWh[39]={0};
@@ -615,6 +617,9 @@
                                     debugMode = !debugMode;                                
                                 } else if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = configScreen ; // GoTo Config Screen                                   
+                                } else if (dMode[whichTouched] == tripScreen) {
+                                    miles_trip[0]=0;
+                                    kWh_trip[0]=0;
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                 }                            
@@ -650,6 +655,9 @@
                              case 32: // right col, bottom row (not nav)  
                                 if (dMode[whichTouched] == configScreen) {
                                     updateFirmware();
+                                } else if (dMode[whichTouched] == tripScreen) {
+                                    miles_trip[1]=0;
+                                    kWh_trip[1]=0;
                                 } else {                             
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                 }
@@ -714,6 +722,10 @@
                     fclose(hfile);
                 }
             }
+            if(!laccOn&&accOn){ // Car turned on
+                miles_trip[2]=0;
+                kWh_trip[2]=0;
+            }
             laccOn=accOn;
             if(!accOn&&!logEn&&userIdle&&!playbackEn){             
                 dled = 0; // turn off display if car off and logging disabled and no user activity
@@ -733,6 +745,10 @@
                 mph[0]=0;
             }
             mpkWh[0]=mph[0];
+            miles_trip[0]+=mph[0]/3600;
+            miles_trip[1]+=mph[0]/3600;
+            miles_trip[2]+=mph[0]/3600;
+
             if(numWsamples>0){ // Avoid div0
                 kW[0]=((float) mWs_x4)/numWsamples/4e3;     
                 mpkWh[0]/=kW[0];
@@ -743,7 +759,9 @@
                 kW[0]=0;
                 mpkWh[0]=0;
             }
-            //mpkWh[0]=floor(mpkWh[0]*10+0.5)/10; // Round to nearest 10th
+            kWh_trip[0]+=kW[0]/3600;
+            kWh_trip[1]+=kW[0]/3600;
+            kWh_trip[2]+=kW[0]/3600;
             motorRPM=0;
             numSsamples=0;
             mWs_x4=0;
--- a/utility.cpp	Fri Jun 28 20:26:11 2013 +0000
+++ b/utility.cpp	Sat Jun 29 02:44:02 2013 +0000
@@ -55,6 +55,8 @@
     signed short packA;
     signed long imWs_x4;
     unsigned short ts;
+    long temp_adc[6]       = {1000,589,487,401,365,0 };
+    signed short temp_C[6] = {-270, 130, 230, 320, 360, 760};
 
     secsNoMsg=0; // reset deadman switch
     if(debugMode||(skin==ggSkin)){ 
@@ -264,22 +266,30 @@
                     battTemp_x4=battData[(BatDataBaseG4*7)+5]+battData[(BatDataBaseG4*7)+8]+battData[(BatDataBaseG4*7)+11]+battData[(BatDataBaseG4*7)+14];
                     // Or =25+(467-ADC)/9.33 (C)
                     // Find hottest temperature
-                    battTemp_x10=467-(battData[(BatDataBaseG4*7)+3]*0x100+battData[(BatDataBaseG4*7)+4]);
-                    j=467-(battData[(BatDataBaseG4*7)+6]*0x100+battData[(BatDataBaseG4*7)+7]);
-                    if(j>battTemp_x10){
+                    battTemp_x10=battData[(BatDataBaseG4*7)+3]*0x100+battData[(BatDataBaseG4*7)+4];
+                    j=battData[(BatDataBaseG4*7)+6]*0x100+battData[(BatDataBaseG4*7)+7];
+                    if(j<battTemp_x10){
+                        battTemp_x10=j;
+                        }
+                    j=battData[(BatDataBaseG4*7)+9]*0x100+battData[(BatDataBaseG4*7)+10];
+                    if(j<battTemp_x10){
                         battTemp_x10=j;
                         }
-                    j=467-(battData[(BatDataBaseG4*7)+9]*0x100+battData[(BatDataBaseG4*7)+10]);
-                    if(j>battTemp_x10){
+                    j=battData[(BatDataBaseG4*7)+12]*0x100+battData[(BatDataBaseG4*7)+13];
+                    if(j<battTemp_x10){
                         battTemp_x10=j;
                         }
-                    j=467-(battData[(BatDataBaseG4*7)+12]*0x100+battData[(BatDataBaseG4*7)+13]);
-                    if(j>battTemp_x10){
-                        battTemp_x10=j;
-                        }
-                    battTemp_x10*=100;
-                    battTemp_x10/=93;
-                    battTemp_x10+=250;
+                    //interpolate for temperature
+                    char k=0;
+                    while(battTemp_x10<=temp_adc[++k]) { } // Find section in table
+                    j=battTemp_x10-temp_adc[k];
+                    j*=(temp_C[k]-temp_C[k-1]);
+                    j/=(temp_adc[k]-temp_adc[k-1]);
+                    j+=temp_C[k];
+                    battTemp_x10=j;
+                    //battTemp_x10*=100;
+                    //battTemp_x10/=93;
+                    //battTemp_x10+=250;
                     SOH_x100=battData[(BatDataBaseG1*7)+29]*0x100+battData[(BatDataBaseG1*7)+30];
                     Ah_x10000=battData[(BatDataBaseG1*7)+36]*0x10000+battData[(BatDataBaseG1*7)+37]*0x100+battData[(BatDataBaseG1*7)+38];
                     SOC_x10000=battData[(BatDataBaseG1*7)+32]*0x10000+battData[(BatDataBaseG1*7)+33]*0x100+battData[(BatDataBaseG1*7)+34];