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:
Thu Sep 12 14:42:22 2013 +0000
Parent:
147:e0f1c84c62a6
Child:
149:e9739523109f
Commit message:
// No longer save config after firmware update; // Added config health check after read; // Added debugScreen; // Switched friction monitor to msgId:292 so MY2013 will work; // Added ambient to main display; // Added Resr to trip log

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	Wed Aug 07 13:36:13 2013 +0000
+++ b/common.h	Thu Sep 12 14:42:22 2013 +0000
@@ -15,7 +15,8 @@
 #define indexScreen 14
 #define tripScreen 15
 #define healthScreen 16
-#define maxScreens 16
+#define debugScreen 17
+#define maxScreens 17
 
 #define btnGap 10
 #define ttSkin 0
--- a/displayModes.cpp	Wed Aug 07 13:36:13 2013 +0000
+++ b/displayModes.cpp	Thu Sep 12 14:42:22 2013 +0000
@@ -7,9 +7,9 @@
 void mainDisplay (bool force, bool showButtons){
     unsigned short gids, SOC_x10, packV_x2, tireP;
     float useable_kWh,dte;
-    //unsigned char aTemp,c1Temp,c2Temp;
-    static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0, maxPS=0;
-    //static unsigned char laTemp=0,lc1Temp=0,lc2Temp=0;
+    unsigned char aTemp;
+    static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0;
+    static unsigned char laTemp=0;
     static float lmaxTemp=0, lkW=0, laccV=0, lmpkWh=0;
 
     CANMessage msg;
@@ -20,6 +20,8 @@
     SOC_x10 = (msg.data[0]<<2)+(msg.data[1]>>6);
     msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts
     packV_x2 = (msg.data[2]<<2)+(msg.data[3]>>6);
+    msg = lastMsg[indexLastMsg[0x54c]]; //Get ambient
+    aTemp = msg.data[6]-56;
     //msg = lastMsg[indexLastMsg[0x79a]]; //Get ambient and cabin temperature
     //aTemp = msg.data[5]-41; // Need to add convertsion to C if metric
     //c1Temp = msg.data[4]-41;
@@ -42,11 +44,6 @@
                 useable_kWh=0;
             }
             printf("%4.1f kWh \n",useable_kWh);
-            if(debugMode){
-                if(pointerSep>maxPS){maxPS=pointerSep;}
-                tt.locate(10,110);
-                printf("%3d sep  %3d max\n",pointerSep,maxPS);
-            }
 
             // Display DTE
             dte=convertDistance(minTripEff*useable_kWh);
@@ -124,32 +121,26 @@
             lpackV_x2=packV_x2;
             ltireP=0;//Force tire pressure redraw, too
         }
-        /*if(force||aTemp!=laTemp){
+        if(force||aTemp!=laTemp){
             tt.foreground(Cyan);
-            tt.locate(10,146);
-            printf("%d %d %d\n",aTemp,c1Temp,c2Temp);
+            tt.locate(20,146);
+            printf("%2.0f%s\n",convertF(aTemp),temperatureUnit());
             laTemp=aTemp;
-            lc1Temp=c1Temp;
-            lc2Temp=c2Temp;
-        }*/
+        }
         if(force||maxTemp!=lmaxTemp){
             tt.foreground(Cyan);
             tt.locate(210,146);
-            if (convertTemperature(maxTemp)<100){
-                printf(" %3.1f%s\n",convertTemperature(maxTemp),temperatureUnit());
+            if (convertC(maxTemp)<100){
+                printf(" %3.1f%s\n",convertC(maxTemp),temperatureUnit());
             }else{
-                printf("%4.1f%s\n",convertTemperature(maxTemp),temperatureUnit());
+                printf("%4.1f%s\n",convertC(maxTemp),temperatureUnit());
             }
             lmaxTemp=maxTemp;
         }
         if(force||accV!=laccV){
             tt.locate(20,176);
             tt.foreground(Yellow);
-            if(debugMode){
-                printf("%4.2f %4.2f \n",accV,accV2);
-            }else{
-                printf("%3.1fV  \n",accV);
-            }
+            printf("%3.1fV  \n",accV);
             laccV=accV;
         }
         if(force||tireP!=ltireP){
@@ -396,7 +387,7 @@
     }
     if(force||maxTemp!=lmaxTemp){
         tt.locate(10,130);
-        printf(" %4.1f %s (max) \n",convertTemperature(maxTemp),temperatureUnit());
+        printf(" %4.1f %s (max) \n",convertC(maxTemp),temperatureUnit());
         lmaxTemp=maxTemp;
     }
     if(force||unloadedV_x2!=lunlV){
@@ -588,8 +579,8 @@
             case 1:
                 tt.locate(0,6);
                 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);
+                    max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
+                    convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
                 tt.rect(8+0*41,16,40+0*41,28,Green);
                 tt.rect(8+1*41,16,40+1*41,28,Yellow);
                 //tt.rect(8+2*41,16,40+2*41,28,White);
@@ -752,8 +743,8 @@
         tt.locate( 0, yWinMax+40 );
         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",
-            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);
+            max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
+            convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
         //printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",
         //        max,min,avg,jv,  battData[BatDataBaseG4*7+5],battData[BatDataBaseG4*7+8],  battData[BatDataBaseG4*7+11],battData[BatDataBaseG4*7+14]);
         
@@ -878,8 +869,8 @@
         tt.locate( 0, yWinMax+40 );
         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);
+            max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
+            convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
         //printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",
         //        max,min,avg,jv,  battData[BatDataBaseG2*7+BatDataBaseG4*7+5],battData[BatDataBaseG2*7+BatDataBaseG4*7+8],  battData[BatDataBaseG2*7+BatDataBaseG4*7+11],battData[BatDataBaseG2*7+BatDataBaseG4*7+14]);
         
@@ -1264,6 +1255,32 @@
     }
 }
 
+void debugDisplay (bool force, bool showButtons){
+    static unsigned short maxPS=0;
+    unsigned char i, uData[8];
+    CANMessage msg;
+
+    for (i=0; i<8; i++){
+        msg = lastMsg[indexLastMsg[(uMsgId[i]>>4)]]; //Get ambient
+        uData[i] = msg.data[(uMsgId[i]&0x000f)];
+    }
+    tt.set_font((unsigned char*) Arial24x23);
+    tt.foreground(Yellow);
+    tt.background(Navy);
+    if(force){
+        tt.cls();
+    }
+    if(pointerSep>maxPS){maxPS=pointerSep;}
+    tt.locate(10,10);
+    printf("%3d sep  %3d max\n",pointerSep,maxPS);
+    tt.locate(10,40);
+    printf("%4.2fV %4.2fV \n",accV,accV2);
+    for (i=0; i<4; i++){
+        tt.locate(10,90+i*30);
+        printf("%4x:%2x %4x:%2x\n",uMsgId[i],uData[i],uMsgId[i+4],uData[i+4]);
+    }
+}
+
 void updateDisplay(char display){
     bool changed,showButtons;
     changed = dMode[display]!=lastDMode[display];
@@ -1318,6 +1335,9 @@
         case healthScreen:
             healthDisplay(changed,showButtons);
             break;
+        case debugScreen:
+            debugDisplay(changed,showButtons);
+            break;
         default:
             if (changed){
                 tt.background(Black);
@@ -1475,7 +1495,7 @@
 
 
 //The temps are stored as metric, distances as imperial... I'm assuming the input based on that - LM
-float convertTemperature(float input) 
+float convertC(float input) 
 {
     if (!metric) {
         //convert!
@@ -1485,6 +1505,17 @@
     }
     return input;
 }
+
+float convertF(float input) 
+{
+    if (metric) {
+        //convert!
+        float output = input -32.0f;
+        output /= 1.8f;
+        return output;   
+    }
+    return input;
+}
 float convertDistance(float input)
 {
     if (metric) {
--- a/displayModes.h	Wed Aug 07 13:36:13 2013 +0000
+++ b/displayModes.h	Thu Sep 12 14:42:22 2013 +0000
@@ -62,6 +62,7 @@
 extern float maxTripEff, minTripEff;
 extern bool brakeMon;
 extern float curEff;
+extern unsigned short uMsgId[8];
 
 extern "C" {
     void printLast (bool force, bool showButtons);
@@ -79,7 +80,8 @@
     void showButton(unsigned char column, unsigned char row, char * text1, char * text2, unsigned char columns, unsigned char rows);
     void highlightButton(unsigned char column, unsigned char row, unsigned char tScn, unsigned char columns, unsigned char rows);
     float convertDistance(float input); // LM - Metric
-    float convertTemperature(float input); // LM - Metric
+    float convertC(float input); // LM - Metric
+    float convertF(float input); // LM - Metric
     char* distanceUnit(); // LM - Metric
     char* temperatureUnit(); // LM - Metric
 }
\ No newline at end of file
--- a/main.cpp	Wed Aug 07 13:36:13 2013 +0000
+++ b/main.cpp	Thu Sep 12 14:42:22 2013 +0000
@@ -12,8 +12,13 @@
 // * Add temperature to efficiency lookup table
 // * Add debug screen
 
-// rev147
-// Changed CONFIG.TXT copy on thumbdrive to CONFIG.BAK to avoid unwanted restore
+// rev148
+// No longer save config after firmware update
+// Added config health check after read
+// Added debugScreen
+// Switched friction monitor to msgId:292 so MY2013 will work
+// Added ambient to main display
+// Added Resr to trip log
 
 #include "mbed.h"
 #include "CAN.h"
@@ -24,7 +29,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "147"; // gg - revision string, max 6 characters
+char revStr[7] = "148"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -152,6 +157,7 @@
 unsigned char saveDmode=99;
 bool moving=false;
 unsigned short chirpInt;
+unsigned short uMsgId[8] = {0x5103, 0x50a3, 0x54a4, 0x54b4, 0x54c0, 0x55b4, 0x0000, 0x0000}; // messages to display on debug screen msgId:byte
 
 int main() {
     char sTemp[40];
@@ -705,7 +711,7 @@
             tick=false;
             curEff = miles_trip[0]/kWh_trip[0];
             headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false;  // headlight/turn signal indicator
-            if(indexLastMsg[0x355]>0){
+            if(accOn&&indexLastMsg[0x355]>0){
                 miles_kmbar = (lastMsg[indexLastMsg[0x355]].data[4]&0x20)?true:false;  // indicates selected distance units
                 metric = !miles_kmbar;
             }
--- a/utility.cpp	Wed Aug 07 13:36:13 2013 +0000
+++ b/utility.cpp	Thu Sep 12 14:42:22 2013 +0000
@@ -354,14 +354,15 @@
             }
             motorRPM+=imotorRPM;
             numSsamples++;
-        }else if((mType==2)&&(canRXmsg.id==0x1ca)){ //Brake Pressure
+//        }else if((mType==2)&&(canRXmsg.id==0x1ca)){ //Brake Pressure
+        }else if((mType==2)&&(canRXmsg.id==0x292)){ //Brake Pressure
             if(brakeMon){
                 if(canRXmsg.data[0]<0xff){
-                    if((canRXmsg.data[0]*imotorRPM)<brkMonThr){
+                    if((canRXmsg.data[6]*imotorRPM)<brkMonThr){
                         chirpInt=0;
                     }else{
                         chirpInt=brkMonRate/imotorRPM;
-                        chirpInt/=canRXmsg.data[0];
+                        chirpInt/=canRXmsg.data[6];
                     }
                 }
             }
@@ -631,6 +632,36 @@
             fscanf(cfile, "brkMonThr %d\r\n", &brkMonThr );            
         }
         fclose(cfile);
+        if((ff>7)||(ff<1)||(ledHi<0.1)||(scale12V<10)||(tt.x_mid<16000)||(ledHi>1)||(ledLo>1)||(dMode[0]>maxScreens)||(dMode[1]>maxScreens)){ //Sanity check a few things
+            //Something wrong. Load defaults
+            printf("Invalid config file.  Loading defaults.\n");
+            wait(3);
+            ff=8;
+            tt.x0_off=5732;
+            tt.y0_off=34009;
+            tt.x0_pp=77;
+            tt.y0_pp=106;
+            tt.x1_off=33955;
+            tt.y1_off=6310;
+            tt.x1_pp=80;
+            tt.y1_pp=104;
+            tt.x_mid=31986;
+            dMode[0]=4;
+            dMode[1]=2;
+            ledHi=0.800;
+            ledLo=0.100;
+            pollInt=300;
+            scale12V=16.20;
+            skin=0;
+            dtePeriod=14;
+            debugMode=false;
+            metric=false;
+            fwCount=1;
+            showHealth=true;
+            brakeMon=true;
+            brkMonRate=400000;
+            brkMonThr=4000;
+            }
         if(ff<7){//If not latest format, save as latest format
             saveConfig();
             printMsg("Config file format updated.\n"); // config forat updates
@@ -806,7 +837,7 @@
         f_lseek(&bfile,0xffffffff); // go to end of file to append
         strftime(sTemp, 40, "%a %m/%d/%Y %X", &t);
         f_printf(&bfile,"%s,",sTemp);
-        sprintf(sTemp,"%d,%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%d,%d,%d,%d,%d,%4.1f,%4.1f",odo,accV,gids,(float)SOC/10, (float)SOH2_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,max,min,avg,max-min,jv,miles_trip[0],kWh_trip[0]);      
+        sprintf(sTemp,"%d,%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%4.1f,%d,%d,%d,%d,%d,%4.1f,%4.1f",odo,accV,gids,(float)SOC/10, (float)SOH2_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,Resr,max,min,avg,max-min,jv,miles_trip[0],kWh_trip[0]);
         f_printf(&bfile,"%s,",sTemp);           
         f_printf(&bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]);
         f_printf(&bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]);
@@ -853,6 +884,7 @@
             fclose(lfile);
         }
         f_close(&efile);
+        readConfig();
         wait(2);
     }
 
@@ -865,9 +897,7 @@
         return;
     }
     fwCount ++;
-    saveConfig();    
-    tt.cls();
-    printf("Saved Configuration\n");
+    saveConfig();
     //delete all bin files in /local
     DIR *dir;
     struct dirent *ent;
@@ -946,6 +976,8 @@
             spkr.beep(500,0.015);
             counter=0;
         }
+    }else{
+        counter=0;
     }
 }
 
@@ -971,7 +1003,7 @@
 dtePeriod 14
 DebugMode 0
 metric 0
-firmware 11
+firmware 1
 showHealth 1
 brakeMon 1
 brkMonRate 400000