test fork

Dependencies:   SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary_9341 by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Mon Aug 05 03:34:06 2013 +0000
Parent:
142:c1a11d6f181c
Child:
144:b0c9d30dd346
Commit message:
added accessory volt read from battData; put a copy of the config.txt on the USB drive during firmware update;

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	Sun Aug 04 20:59:27 2013 +0000
+++ b/displayModes.cpp	Mon Aug 05 03:34:06 2013 +0000
@@ -145,7 +145,7 @@
         if(force||accV!=laccV){
             tt.locate(20,176);
             tt.foreground(Yellow);
-            printf("%3.1fV  \n",accV);
+            printf("%3.1f(%3.1f)  \n",accV,accV2);
             laccV=accV;
         }
         if(force||tireP!=ltireP){
@@ -380,10 +380,10 @@
         printf(" %4.1f%s \n",(float)SOC_x10/10,"% SOC");
         lSOC=SOC_x10;
     }
-    if(force||SOH_x100!=lSOH){
+    if(force||SOH2_x100!=lSOH){
         tt.locate(10,70);
-        printf(" %4.1f%s,%4.1f%s \n",(float)SOH_x2/2,"%",(float)SOH_x100/100,"% SOH");
-        lSOH=SOH_x100;
+        printf(" %4.1f%s,%4.1f%s \n",(float)SOH_x2/2,"%",(float)SOH2_x100/100,"% SOH");
+        lSOH=SOH2_x100;
     }
     if(force||Ah_x10000!=lAh){
         tt.locate(10,100);
--- a/displayModes.h	Sun Aug 04 20:59:27 2013 +0000
+++ b/displayModes.h	Mon Aug 05 03:34:06 2013 +0000
@@ -30,6 +30,7 @@
 extern TOUCH_TFTx2 tt;
 extern unsigned char dtMode;
 extern float accV;
+extern float accV2;
 extern bool playbackEn;
 extern bool playbackOpen;
 extern float playbackInt;
@@ -47,7 +48,7 @@
 extern float maxTemp;
 extern unsigned long Ah_x10000;
 extern unsigned long SOC_x10000;
-extern unsigned short SOH_x100;
+extern unsigned short SOH2_x100;
 extern bool metric;
 extern unsigned char tNavRow ; // gg - 4x4
 extern char revStr[7]; // gg - version
--- a/main.cpp	Sun Aug 04 20:59:27 2013 +0000
+++ b/main.cpp	Mon Aug 05 03:34:06 2013 +0000
@@ -10,9 +10,9 @@
 // * Subtract accessory power from efficiency history (add back in when displaying)
 // * Add trip history display
 
-// rev142
-// changed trip log back to jsut cp vales
-
+// rev143
+// added accessory volt read from battData
+// put a copy of the config.txt on the USB drive during firmware update
 
 #include "mbed.h"
 #include "CAN.h"
@@ -23,7 +23,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "142"; // gg - revision string, max 6 characters
+char revStr[7] = "143"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -110,6 +110,7 @@
 unsigned short numWsamples = 0;
 unsigned short numSsamples = 0;
 float accV = 0;
+float accV2 = 0;
 bool playbackEn = false;
 bool playbackOpen = false;
 //float playbackInt = 0.05; //read messages every 50 ms
@@ -140,7 +141,7 @@
 unsigned char reqMsgCnt = 99;
 unsigned long Ah_x10000 = 0;
 unsigned long SOC_x10000 = 0;
-unsigned short SOH_x100 = 0;
+unsigned short SOH2_x100 = 0;
 float maxTemp = 0;
 bool metric = false;
 bool shunt[96]={0};
@@ -470,6 +471,7 @@
                                     sMode=0;
                                 } else if (dMode[whichTouched]==configScreen) {
                                     printMsg("Saving config file.\n"); // saving config
+                                    dMode[whichTouched]=mainScreen;
                                     saveConfig();
                                     spkr.beep(2000,0.25);
                                 } else if (dMode[whichTouched]==playbackScreen) { // faster
--- a/utility.cpp	Sun Aug 04 20:59:27 2013 +0000
+++ b/utility.cpp	Mon Aug 05 03:34:06 2013 +0000
@@ -292,9 +292,10 @@
                     maxTemp+=temp_C[ii];
 
                     // Get state of health
-                    SOH_x100=battData[(BatDataBaseG1*7)+29]*0x100+battData[(BatDataBaseG1*7)+30];
+                    SOH2_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];
+                    accV2=(float)battData[(BatDataBaseG1*7)+23]/4+(float)battData[(BatDataBaseG1*7)+24]/1024;
                     
                     // Save shunt data
                     for(j=0; j<24; j++){
@@ -518,13 +519,13 @@
     fprintf(cfile,"x1_pp %d\r\n",tt.x1_pp);
     fprintf(cfile,"y1_pp %d\r\n",tt.y1_pp);
     fprintf(cfile,"x_mid %d\r\n",tt.x_mid);
-    if (dMode[0]==configScreen)
-        fprintf(cfile,"dMode0 %d\r\n",mainScreen);
-    else
+    //if (dMode[0]==configScreen)
+    //    fprintf(cfile,"dMode0 %d\r\n",mainScreen);
+    //else
         fprintf(cfile,"dMode0 %d\r\n",dMode[0]);
-    if (dMode[1]==configScreen)
-        fprintf(cfile,"dMode1 %d\r\n",mainScreen);
-    else
+    //if (dMode[1]==configScreen)
+    //    fprintf(cfile,"dMode1 %d\r\n",mainScreen);
+    //else
         fprintf(cfile,"dMode1 %d\r\n",dMode[1]);
     fprintf(cfile,"ledHi %4.3f\r\n",ledHi);
     fprintf(cfile,"ledLo %4.3f\r\n",ledLo);
@@ -782,7 +783,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)SOH_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,%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]);      
         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]);
@@ -805,30 +806,42 @@
 //the CANary into a computer for updates.
 void updateFirmware()
 {
-    FIL sfile; // external usb file
+    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 *destFile;    
+    FILE *lfile;    
 
     // Check for config file on USB drive
-    sfr = f_open(&sfile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING);    
+    sfr = f_open(&efile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING);    
     if(sfr == FR_OK)
     {        
         printf("Copy config file from USB\n");
-        destFile = fopen("/local/CONFIG.TXT", "w");
-        while (!f_eof(&sfile))
+        lfile = fopen("/local/CONFIG.TXT", "w");
+        while (!f_eof(&efile))
         {
-            sfr=f_read(&sfile,&buffer,bufSize,&bytesRW);
-            fwrite(buffer, 1, bytesRW, destFile);
+            sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
+            fwrite(buffer, 1, bytesRW, lfile);
         }
-        fflush(destFile);
-        fclose(destFile);
-        f_close(&sfile);
-    }    
-    sfr = f_open(&sfile,"firmware.bin",FA_READ|FA_OPEN_EXISTING);    
+        fflush(lfile);
+        fclose(lfile);
+        f_close(&efile);
+    }else{ // No config file found so put one there
+        sfr = f_open(&efile,"CONFIG.TXT",FA_WRITE|FA_CREATE_NEW);    
+        printf("Copy config file to USB\n");
+        lfile = fopen("/local/CONFIG.TXT", "r");
+        while (!feof(lfile))
+        {
+            bytesRW=fread(buffer, 1, bufSize, lfile);
+            sfr=f_write(&efile,&buffer,bytesRW,&bytesRW);
+        }
+        fflush(lfile);
+        fclose(lfile);
+        f_close(&efile);
+    }
+    sfr = f_open(&efile,"firmware.bin",FA_READ|FA_OPEN_EXISTING);    
     if(sfr != FR_OK)
     {        
         printf("Couldn't find firmware.bin\n");
@@ -875,23 +888,23 @@
     sprintf(sTemp,"/local/fw%d.bin",fwCount);
     printf("Writing %s\n",sTemp);
     wait(2);
-    destFile = fopen(sTemp, "wb");
-    if(destFile == NULL)
+    lfile = fopen(sTemp, "wb");
+    if(lfile == NULL)
     {
         printf("Couldn't Open Destination\n");
         wait(3);
         return;
     }
 
-    while (!f_eof(&sfile))
+    while (!f_eof(&efile))
     {
-        sfr=f_read(&sfile,&buffer,bufSize,&bytesRW);
-        fwrite(buffer, 1, bytesRW, destFile);
+        sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
+        fwrite(buffer, 1, bytesRW, lfile);
     }
 
-    fflush(destFile);
-    fclose(destFile);
-    f_close(&sfile);
+    fflush(lfile);
+    fclose(lfile);
+    f_close(&efile);
     tt.cls();
     printf("Succesful\n\n");
     printf("Rebooting in 3 seconds\n");
--- a/utility.h	Sun Aug 04 20:59:27 2013 +0000
+++ b/utility.h	Mon Aug 05 03:34:06 2013 +0000
@@ -57,7 +57,7 @@
 extern float maxTemp;
 extern unsigned long Ah_x10000;
 extern unsigned long SOC_x10000;
-extern unsigned short SOH_x100;
+extern unsigned short SOH2_x100;
 extern bool metric;
 extern unsigned char lastDMode[2];
 extern unsigned char whichTouched;
@@ -68,6 +68,7 @@
 extern bool debugMode;
 extern bool shunt[96];
 extern float accV;
+extern float accV2;
 extern bool showHealth;
 extern float kWh_trip[0];
 extern float miles_trip[0];