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

Revision:
170:7ee98e3611bc
Parent:
169:84d790ac18a2
Child:
174:cd27e80f197d
--- 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