Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Diff: main.cpp
- Revision:
- 167:58d4edf403d4
- Parent:
- 166:ec3951ba9701
- Child:
- 168:9227024c4e3a
--- a/main.cpp Tue Dec 03 13:54:07 2013 +0000 +++ b/main.cpp Tue Dec 03 20:45:05 2013 +0000 @@ -8,10 +8,10 @@ // * Change pack volt color when CVLI fails // * Add tire pressure cal (40psi for me = FR 38, RR 38.2, FL 37.8, RL 38 - maybe 2psi error on my tire gauge?) // * Add on screen messages for heater on, etc, and use refresh feature above to clear in x seconds +// * Add climate control impact to main max/min dte and new trip display -// rev166 -// Re-formatted main and dte displays -// Fixed flicker on CC DTE +// rev167 +// Added climate control impact to best case and worst case DTE (bug fix) #include "mbed.h" #include "CAN.h" @@ -21,7 +21,7 @@ #include "utility.h" #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "166"; // gg - revision string, max 6 characters +char revStr[7] = "167"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); @@ -128,11 +128,18 @@ signed long motorRPM_x2; unsigned char skin = ttSkin ; unsigned char dtePeriod = 14; //ten minute averaging interval +float CCkWh_trip[3]={0}; float kWh_trip[3]={0}; float miles_trip[3]={0}; float curEff = 0; float maxTripEff = 0; float minTripEff = 5; +float maxTripMiles = 0; +float maxTripkWh = 1; +float maxTripCCkWh = 0; +float minTripMiles = 5; +float minTripkWh = 1; +float minTripCCkWh = 0; float mph[39]={0}; float kW[39]={0}; float mpkWh[39]={0}; @@ -228,6 +235,15 @@ if(!feof(hfile)){ fscanf(hfile,"%f\r\n",&Resr); } + if(!feof(hfile)){ + fscanf(hfile,"%f %f\r\n",&maxTripMiles,&minTripMiles); + } + if(!feof(hfile)){ + fscanf(hfile,"%f %f\r\n",&maxTripkWh,&minTripkWh); + } + if(!feof(hfile)){ + fscanf(hfile,"%f %f\r\n",&maxTripCCkWh,&minTripCCkWh); + } fclose(hfile); printMsg("History Loaded.\n"); // History loaded } else { // create initial file @@ -677,6 +693,7 @@ } else if (dMode[whichTouched]==tripScreen) { miles_trip[2]=0; kWh_trip[2]=0; + CCkWh_trip[2]=0; sMode=0; lastDMode[whichTouched]=99;//repaint to clear highlight } else if (dMode[whichTouched]==indexScreen) { @@ -757,11 +774,6 @@ lastDMode[0]=99;//force refresh lastDMode[1]=99;//force refresh } - if (miles_trip[0]>0.25) { - curEff = miles_trip[0]/kWh_trip[0]; - } else { - curEff = 0; - } headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false; // headlight/turn signal indicator if(heaterOn){ lHeaterOn=true; // Only indicate heater once per power cycle @@ -792,11 +804,18 @@ } // Keep track of max and min trip efficiency if (miles_trip[0]>5){ // Ignore short trips + curEff = miles_trip[0]/kWh_trip[0]; if (maxTripEff<curEff) { maxTripEff=curEff; + maxTripMiles=miles_trip[0]; + maxTripkWh=kWh_trip[0]; + maxTripCCkWh=CCkWh_trip[0]; } if (minTripEff>curEff) { minTripEff=curEff; + minTripMiles=miles_trip[0]; + minTripkWh=kWh_trip[0]; + minTripCCkWh=CCkWh_trip[0]; } } if (repeatPoll) { // Log on shutdown if autopoll enabled @@ -810,6 +829,9 @@ } fprintf(hfile,"%f %f\r\n",maxTripEff,minTripEff); // Save max and min fprintf(hfile,"%f \r\n",Resr); // Save series resistance + fprintf(hfile,"%f %f\r\n",maxTripMiles,minTripMiles); // Save max and min + fprintf(hfile,"%f %f\r\n",maxTripkWh,minTripkWh); // Save max and min + fprintf(hfile,"%f %f\r\n",maxTripCCkWh,minTripCCkWh); // Save max and min fclose(hfile); } } @@ -817,6 +839,7 @@ lHeaterOn=false; miles_trip[0]=0; kWh_trip[0]=0; + CCkWh_trip[0]=0; wait5secs=5; if (showHealth){ if (saveDmode==99){ @@ -909,9 +932,13 @@ kWh_trip[0]+=kW[0]/3600; kWh_trip[1]+=kW[0]/3600; kWh_trip[2]+=kW[0]/3600; + CCkWh_trip[0]+=CCkW/3600; + CCkWh_trip[1]+=CCkW/3600; + CCkWh_trip[2]+=CCkW/3600; } else { // charging so reset per charge trip meter miles_trip[1]=0; kWh_trip[1]=0; + CCkWh_trip[1]=0; } motorRPM_x2=0;