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 Jul 04 00:09:28 2013 +0000
Branch:
Metric
Parent:
114:3f8c59a8a2b9
Child:
116:5cd72bae7c12
Commit message:
Added delay to powerup ping (apparently BMS needs some time). Made all logging enabled by default

Changed in this revision

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/main.cpp	Tue Jul 02 02:57:36 2013 +0000
+++ b/main.cpp	Thu Jul 04 00:09:28 2013 +0000
@@ -24,11 +24,12 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "114"; // gg - revision string, max 6 characters
+char revStr[7] = "115"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
 bool waitasec = true;
+unsigned char wait5secs = 5;
 // to write to USB Flash Drives, or equivalent (SD card in Reader/Writer)
 FRESULT mfr = f_mount(0,&USBdrive);
 time_t seconds ;
@@ -57,7 +58,7 @@
 bool usbEn = false;
 bool logEn = true;
 bool logOpen = false; 
-bool yesBattLog = false; // gg - Batt Log
+bool yesBattLog = true; // gg - Batt Log
 unsigned char tNavRow = 3; // gg - 4x4 touch
 
 FILE *hfile; // history file
@@ -693,25 +694,28 @@
             if(!laccOn&&accOn){ // Car turned on
                 miles_trip[0]=0;
                 kWh_trip[0]=0;
-                if (repeatPoll) { // Poll on startup if autopoll enabled
+                wait5secs=5;
+            }
+            laccOn=accOn;
+            if(!accOn&&!logEn&&userIdle&&!playbackEn){ // Car off and logging disabled and no user activity
+                dled = 0; 
+            }else if(!headlights){
+                dled = ledHi;
+            } else {
+                dled = ledLo;
+            }
+            if(wait5secs>0){ // Wait a few seconds after poweron to give BMS time to measure CP's
+                wait5secs-=1;
+                if (repeatPoll&&(wait5secs==0)) { // Poll on startup if autopoll enabled
                     logOnce=true;
                     reqMsgCnt=0;
                     msgReq.attach(&sendReq,0.015);
                 }
             }
-            laccOn=accOn;
-            if(!accOn&&!logEn&&userIdle&&!playbackEn){             
-                dled = 0; // turn off display if car off and logging disabled and no user activity
-            }else if(!headlights){
-                dled = ledHi;
-            } else {
-                dled = ledLo;
-            }
-            
+
             //compute historic efficiency
             if(numSsamples>0){ // Avoid div0
-                //mph[0]=((float) motorRPM)/numSsamples/215; // Empirically derived - may change car to car
-                mph[0]=((float) motorRPM)/numSsamples/219; // Empirically derived - may change car to car
+                mph[0]=((float) motorRPM)/numSsamples/220; // Empirically derived with MXV4s - may change with different wheels&tires
             } else {
                 mph[0]=0;
             }
--- a/utility.cpp	Tue Jul 02 02:57:36 2013 +0000
+++ b/utility.cpp	Thu Jul 04 00:09:28 2013 +0000
@@ -209,13 +209,27 @@
         //Miscellaneous on-recieve operations below
         if((mType==1)&&(canRXmsg.id==0x7bb)){ // is battery data?  Need to store all responses
             if(canRXmsg.data[0]<0x20){
-                if(canRXmsg.data[3]==2){//Group 2 = cellpair data
+                if(canRXmsg.data[3]==1){//Group 1 data
+                    bdi=BatDataBaseG1; // index offset for Group 1 data (uses 20 - 22)
+                    if(debugMode){
+                        sprintf(sTemp,"  Getting Group 1 data\n");
+                        printMsg(sTemp);
+                    }
+                    
+                }else if(canRXmsg.data[3]==2){//Group 2 = cellpair data
                     bdi=BatDataBaseG2; // index offset for CP data (uses 00 - 1C)
                     if(debugMode){
                         sprintf(sTemp,"  Getting cell pair data\n");
                         printMsg(sTemp);
                     }
                     
+                }else if(canRXmsg.data[3]==3){//Group 3 data
+                    bdi=BatDataBaseG3; // index offset for Group 3 data (uses 20 - 22)
+                    if(debugMode){
+                        sprintf(sTemp,"  Getting Group 3 data\n");
+                        printMsg(sTemp);
+                    }
+                    
                 }else if(canRXmsg.data[3]==4){//Group 4 = temperature data
                     bdi=BatDataBaseG4; // index offset for Temperature data (uses 20 - 22)
                     if(debugMode){
@@ -223,20 +237,6 @@
                         printMsg(sTemp);
                     }
                     
-                }else if(canRXmsg.data[3]==1){//Group 1 data
-                    bdi=BatDataBaseG1; // index offset for Group 1 data (uses 20 - 22)
-                    if(debugMode){
-                        sprintf(sTemp,"  Getting Group 1 data\n");
-                        printMsg(sTemp);
-                    }
-                    
-                }else if(canRXmsg.data[3]==3){//Group 3 data
-                    bdi=BatDataBaseG3; // index offset for Group 3 data (uses 20 - 22)
-                    if(debugMode){
-                        sprintf(sTemp,"  Getting Group 3 data\n");
-                        printMsg(sTemp);
-                    }
-                    
                 }else if(canRXmsg.data[3]==5){//Group 5 data
                     bdi=BatDataBaseG5; // index offset for Group 5 data (uses 20 - 22)
                     if(debugMode){
@@ -251,7 +251,7 @@
             if(bdi<0xff){
                 i=canRXmsg.data[0]&0x0f; //lower nibble of D0 is index
                 if(lasti>i){ //detect rollover and offset index appropriately
-                    bdi=BatDataBaseG2 + 0x10; // only for CP data
+                    bdi += 0x10; // for CP data
                 }
                 lasti=i; //remember the msb to detect rollover next time around
                 i+=bdi;
@@ -264,20 +264,14 @@
                     // Find hottest temperature by finding smallest ADC value
                     k=battData[(BatDataBaseG4*7)+3]*0x100+battData[(BatDataBaseG4*7)+4];
                     j=battData[(BatDataBaseG4*7)+6]*0x100+battData[(BatDataBaseG4*7)+7];
-                    if(j<k){
-                        k=j;
-                        }
+                    if(j<k)k=j;
                     j=battData[(BatDataBaseG4*7)+9]*0x100+battData[(BatDataBaseG4*7)+10];
-                    if(j<k){
-                        k=j;
-                        }
+                    if(j<k)k=j;
                     j=battData[(BatDataBaseG4*7)+12]*0x100+battData[(BatDataBaseG4*7)+13];
-                    if(j<k){
-                        k=j;
-                        }
+                    if(j<k)k=j;
                     //interpolate from lookup table
-                    unsigned short temp_adc[7] = { 1000,  589,  487,  401,  365,  309, 000};
-                    float            temp_C[7] = {-27.0, 13.0, 23.0, 32.0, 36.0, 43.0, 76.0};
+                    unsigned short temp_adc[8] = {1000,589,487,401,365,340,309,000};
+                    float            temp_C[8] = { -27, 13, 23, 32, 36, 39, 43, 76};
                     char ii=0;
                     while(k<=temp_adc[++ii]) { } // Find section in table
                     maxTemp=(float)(k-temp_adc[ii]);
@@ -394,7 +388,7 @@
                 can1SleepMode = 1; // disable TX
                 can1.monitor(true); // set to snoop mode
                 msgReq.detach(); // stop ticker
-                    //logCP=true; //LAJ for bench test
+                //logCP=true; //LAJ for bench test
             default:
                 data[0]=0x30; //change to request next line message
                 data[1]=0x01;
@@ -712,7 +706,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,%5.1f%%,%5.1f%%, %4.2f, %5.1f,%5.1f,%d,%d,%d,%d,%d",gids,(float)SOC/10, (float)SOH_x100/100,(float)Ah_x10000/10000,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv);      
+        sprintf(sTemp,"%d,%5.1f%%,%5.1f%%, %4.2f, %5.1f,%4.1f,%d,%d,%d,%d,%d",gids,(float)SOC/10, (float)SOH_x100/100,(float)Ah_x10000/10000,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv);      
         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]);