Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller

Dependencies:   SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Tue Dec 24 12:20:50 2013 +0000
Parent:
169:84d790ac18a2
Child:
171:355e284f5201
Commit message:
// Added kWperGid scalar to config file. .075 appears to be too small; // Added CCkWh_trip to TripLog (after kWh_trip); // Added uncalibrated available regen bars to dte screen

Changed in this revision

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
utility.h Show annotated file Show diff for this revision Revisions of this file
--- a/displayModes.cpp	Tue Dec 17 15:25:41 2013 +0000
+++ b/displayModes.cpp	Tue Dec 24 12:20:50 2013 +0000
@@ -33,7 +33,7 @@
             tt.locate(10,4);
             tt.foreground(White);
             printf("%dgids \n",gids);
-            useable_kWh = (float)(gids-5)*0.075;
+            useable_kWh = (float)(gids-5)*kWperGid;
             if (useable_kWh<0){
                 useable_kWh=0;
             }
@@ -229,7 +229,7 @@
             tt.locate(40,40); // gg - add GIDs Percent of 281
             printf("%4.1f%s \n", (float)gids*0.355872, "% ") ;
             tt.locate(20,70);
-            printf("%4.1f kwh  \n",(float)gids*0.075); // gg - closer to usable
+            printf("%4.1f kwh  \n",(float)gids*kWperGid); // gg - closer to usable
             
             tt.set_font((unsigned char*) SCProSB31x55);
             tt.foreground(Green);
@@ -421,7 +421,11 @@
     }*/
     if(force||gids!=lgids){
         tt.locate(10,10);
-        printf("%4d gids \n",gids);
+        if(gids>startGids){ // If not start of trip print kWh/gid too
+            printf("%4d gids  %4.3f kW/gid\n",gids,(float)(kWh_trip[0]+CCkWh_trip[0])/(gids-startGids));
+        }else{
+            printf("%4d gids \n",gids);
+        }
         lgids=gids;
     }
     if(force||SOC_x10!=lSOC){
@@ -431,7 +435,7 @@
     }
     if(force||SOH2_x100!=lSOH){
         tt.locate(10,70);
-        printf(" %4.1f%s,%4.1f%s \n",(float)SOH_x2/2,"%",(float)SOH2_x100/100,"% SOH");
+        printf(" %d%s,%3.1f%s \n",SOH_x2/2,"% SOH",(float)SOH2_x100/100," Hx");
         lSOH=SOH2_x100;
     }
     if(force||Ah_x10000!=lAh){
@@ -458,7 +462,8 @@
 
 void braking (bool force, bool showButtons, bool prdata=false){
     unsigned long targetBraking, regenBraking;
-    static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000;
+    //static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000;
+    static unsigned long maxRegen = 1000, tardivreg_x1000 = 1000;
     unsigned long temp;
     static unsigned char lastPressure[4] = {200,200,200,200};
     unsigned char i,r,t;
@@ -1144,13 +1149,13 @@
 
 void dteDisplay(bool force, bool showButtons, bool showMiles){
     unsigned short i,x,y,lx,ly,gids,radius,color,r,t;
-    unsigned char toVal;
+    unsigned char toVal,availableRegen=0;
     static unsigned short lgids=0;
     static unsigned char leff[39]={0};
     CANMessage msg;
     unsigned long targetBraking, regenBraking, temp;
     static unsigned long maxTarget = 1000, tardivreg_x1000 = 1400;
-    static unsigned char lr=0, lt=0;
+    static unsigned char lr=0, lt=0, lar=0;
 
     msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
     gids = (msg.data[0]<<2)+(msg.data[1]>>6);
@@ -1184,6 +1189,7 @@
         printf("mon\n");  
         tt.line(x,10,x,220,DarkGrey);     
         x=50+38*6;
+        lar=0;
         }
     toVal=33;
     if(force||lgids!=gids){ // update Y axis when kWh changes
@@ -1309,6 +1315,19 @@
         leff[i-1]=y;
     }
 
+    msg = lastMsg[indexLastMsg[0x260]]; //Get available regen
+    availableRegen = msg.data[1]*2;
+
+    if(availableRegen>lar){
+        tt.fillrect(264,240-availableRegen,266,239-lar,White);
+        tt.fillrect(308,240-availableRegen,310,239-lar,White);
+        lar=availableRegen;
+    }else if(availableRegen<lar){
+        tt.fillrect(264,240-lar,266,239-availableRegen,Navy);
+        tt.fillrect(308,240-lar,310,239-availableRegen,Navy);
+        lar=availableRegen;
+    }
+
     msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target total braking
     targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5);
 
@@ -1335,9 +1354,9 @@
         if (r>160) r=160;
         if (r>t) t=r;  //Should never happen
         if(lr!=r||lt!=t){
-            if (t<160) tt.fillrect(264,239-160,310,238-t,Navy);
-            if (r<t) tt.fillrect(264,239-t,310,238-r,Red);
-            if (0<r) tt.fillrect(264,239-r,310,238,Green);
+            if (t<160) tt.fillrect(268,239-160,306,238-t,Navy);
+            if (r<t) tt.fillrect(268,239-t,306,238-r,Red);
+            if (0<r) tt.fillrect(268,239-r,306,238,Green);
         }
         lt=t;
         lr=r;
@@ -1358,7 +1377,10 @@
     if(logEn){
         if(pointerSep>maxPS){maxPS=pointerSep;}
         tt.locate(10,10);
-        printf("%3d sep  %3d max\n",pointerSep,maxPS);
+        printf("%3d sep %3d max\n",pointerSep,maxPS);
+    }else{
+        tt.locate(10,10);
+        printf("%d maxT\n",maxTarget);
     }
     /*msg = lastMsg[indexLastMsg[0x5fa]];
     month = msg.data[5]>>4;
--- a/displayModes.h	Tue Dec 17 15:25:41 2013 +0000
+++ b/displayModes.h	Tue Dec 24 12:20:50 2013 +0000
@@ -18,7 +18,7 @@
 
 //extern unsigned char battData[256]; // 
 extern unsigned char battData[BatDataBufMax]; // BatDataBufMax
-
+extern unsigned long maxTarget;
 extern bool showCP;
 extern bool logEn;
 extern bool usbEn;
@@ -74,6 +74,8 @@
 extern bool clearTest;
 extern float CCkW;
 extern bool CCon;
+extern float kWperGid;
+extern unsigned short startGids;
 
 extern "C" {
     void printLast (bool force, bool showButtons);
--- a/main.cpp	Tue Dec 17 15:25:41 2013 +0000
+++ b/main.cpp	Tue Dec 24 12:20:50 2013 +0000
@@ -11,9 +11,10 @@
 // * Add climate control impact to main max/min dte and new trip display
 // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes)
 
-// rev168
-// Added trip meter including climate control impact
-// Pulled updateConfig to dedicated procedure
+// rev170
+// Added kWperGid scalar to config file.  .075 appears to be too small
+// Added CCkWh_trip to TripLog (after kWh_trip)
+// Added uncalibrated available regen bars to dte screen
 
 #include "mbed.h"
 #include "CAN.h"
@@ -23,8 +24,8 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "168"; // gg - revision string, max 6 characters
-
+char revStr[7] = "170"; // gg - revision string, max 6 characters
+unsigned long maxTarget = 1000;
 FATFS USBdrive;
 LocalFileSystem local("local");
 unsigned char wait5secs = 5;
@@ -78,6 +79,7 @@
 char writeBuffer[maxBufLen][13] __attribute__ ((section("AHBSRAM1"))); // buffer for USB write
 char indexLastMsg[0x800]={0}; // index table for last message
 CANMessage lastMsg[100]; // table to store last message of eachtype
+CANMessage msg;
 
 unsigned char battData[BatDataBufMax]={0}; // 7 * 0x3D = BatDataBufMax
 
@@ -114,6 +116,8 @@
 bool accOn = false; // Accessories on
 bool laccOn = false;
 float scale12V = 16.2; // R1:R2 ratio
+float kWperGid = 0.080;
+unsigned short startGids = 0; // Gids at start of trip
 signed long mWs_x4 = 0;
 unsigned short numWsamples = 0;
 unsigned short numSsamples = 0;
@@ -892,6 +896,8 @@
                     msgReq.attach(&sendReq,0.015);
                     lastDMode[0]=99;
                     lastDMode[1]=99;
+                    msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
+                    startGids=(msg.data[0]<<2)+(msg.data[1]>>6);
                 }
             }
 
--- a/utility.cpp	Tue Dec 17 15:25:41 2013 +0000
+++ b/utility.cpp	Tue Dec 24 12:20:50 2013 +0000
@@ -519,7 +519,7 @@
     printMsg("Saving local config file.\n");
     //wait(2);
     cfile = fopen("/local/config.txt", "w");    
-    fprintf(cfile,"format 9\r\n");
+    fprintf(cfile,"format 10\r\n");
     fprintf(cfile,"x0_off %d\r\n",tt.x0_off);
     fprintf(cfile,"y0_off %d\r\n",tt.y0_off);
     fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp);
@@ -556,6 +556,7 @@
     }
     fprintf(cfile,"modelYear %d\r\n",modelYear);
     fprintf(cfile,"autoSync %d\r\n",(autoSync?1:0));
+    fprintf(cfile,"kWperGid %4.3f\r\n",kWperGid);
     fclose(cfile);
     
     // Make copy of CONFIG.TXT
@@ -612,6 +613,7 @@
         ledLo = 0.3;
         pollInt = 60;
         scale12V = 16.2;
+        kWperGid=0.080;
         skin = ttSkin;
         fscanf(cfile, "format %d\r\n", &ff );
         fscanf(cfile, "x0_off %d\r\n", &tt.x0_off );
@@ -668,12 +670,15 @@
             fscanf(cfile, "autoSync %d\r\n", &readBool);            
             autoSync = (bool)readBool;
         }
+        if(ff>9){
+            fscanf(cfile, "kWperGid %f\r\n", &kWperGid );
+            }
         fclose(cfile);
-        if((ff>9)||(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
+        if((ff>10)||(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=9;
+            ff=10;
             tt.x0_off=5732;
             tt.y0_off=34009;
             tt.x0_pp=77;
@@ -710,6 +715,7 @@
             uMsgId[7]=0x0000;
             modelYear=2011;
             autoSync=false;
+            kWperGid=0.080;
             }
         if(ff<9){//If not latest format, save as latest format
             saveConfig();
@@ -927,10 +933,10 @@
     bfr = f_open(&bfile,"triplog.txt",FA_WRITE|FA_OPEN_ALWAYS);
     if(bfr==FR_OK) {
         f_lseek(&bfile,0xffffffff); // go to end of file to append
-        // timestamp, odometer, accV, gids, SOC, SOH2, Ah, Vbatt, Ibatt, Rest, maxCP, minCP, avgCO, maxCP-minCP, CVLI_jv, miles_trip, kWh_trip, ambient, T1raw, T1, T2raw, T2, T3raw, T3, T4raw, T4, CP1, CP2, ... , CP96
+        // timestamp, odometer, accV, gids, SOC, SOH2, Ah, Vbatt, Ibatt, Rest, maxCP, minCP, avgCO, maxCP-minCP, CVLI_jv, miles_trip, kWh_trip, CCkWh_trip, ambient, T1raw, T1, T2raw, T2, T3raw, T3, T4raw, T4, CP1, CP2, ... , CP96
         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,%4.3f,%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]);
+        sprintf(sTemp,"%d,%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%4.3f,%d,%d,%d,%d,%d,%4.1f,%4.2f,%4.2f",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],CCkWh_trip[0]);
         f_printf(&bfile,"%s,%d,",sTemp,ambient);           
         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]);
@@ -1035,7 +1041,6 @@
     FIL efile; // external usb file
     FRESULT sfr; // external file access flags
     unsigned int bytesRW;
-    char sTemp[40];
     const int bufSize = 2048;
     char buffer[bufSize];
     FILE *lfile;    
@@ -1175,4 +1180,5 @@
 usrMsgId 0000
 modelYear 2011
 autoSync 1
+kWperGid 0.080
 */
\ No newline at end of file
--- a/utility.h	Tue Dec 17 15:25:41 2013 +0000
+++ b/utility.h	Tue Dec 24 12:20:50 2013 +0000
@@ -40,7 +40,7 @@
 extern float ledHi;
 extern float ledLo;
 extern unsigned short pollInt;
-extern float scale12V;
+extern float scale12V,kWperGid;
 extern bool playbackEn;
 extern bool playbackOpen;
 extern bool step;