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:
151:3047ebb3c9a8
Parent:
150:ef46ce63345c
Child:
152:a4d66901785d
--- a/main.cpp	Fri Sep 27 04:43:41 2013 +0000
+++ b/main.cpp	Mon Sep 30 15:31:01 2013 +0000
@@ -7,16 +7,15 @@
 // * Change semilog efficiency graph to linear with 10 minute values
 // * Subtract accessory power from efficiency history (add back in when displaying)
 // * Add in-device config editor
-// * Normalize efficiency to 25C relative to ambient.  Display efficiency at current temp.
+// * Store efficiency data at different temperatures
 // * Change pack volt color when CVLI fails
 // * Add per-charge efficiency meter; add to triplop.txt
 // * 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 heater activation warning message
 // * Add trip max/min efficiency reset
 
-// rev150
-// Added user message Id's to the config file
-// Added copy of ehist.cny to USB on config save and load if present on firmware update
+// rev151
+// added per_charge trip meter
 
 #include "mbed.h"
 #include "CAN.h"
@@ -27,7 +26,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "150"; // gg - revision string, max 6 characters
+char revStr[7] = "151"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -601,11 +600,11 @@
                                     debugMode = !debugMode;                                
                                 } else if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = configScreen ; // GoTo Config Screen                                   
-                                } else if (dMode[whichTouched] == tripScreen) {
+                                /*} else if (dMode[whichTouched] == tripScreen) {
                                     miles_trip[1]=0;
                                     kWh_trip[1]=0;
                                     sMode=0;
-                                    lastDMode[whichTouched]=99;//repaint to clear highlight
+                                    lastDMode[whichTouched]=99;//repaint to clear highlight*/
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                 }                            
@@ -716,7 +715,8 @@
             accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th
             accOn=(accV>5)?true:false;
             moving=(mph[0]>0.1);
-            charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging
+            charging=(lastMsg[indexLastMsg[0x5bf]].data[2]>0)?true:false; // FF when charging
+            //charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging
             if (laccOn&&!accOn){ // Car turned off
                 if (showHealth){
                     if (saveDmode==99){
@@ -815,12 +815,15 @@
             numWsamples=0;
 
             if (!charging){
-                miles_trip[0]+=mph[0]/3600;
-                miles_trip[1]+=mph[0]/3600;
-                miles_trip[2]+=mph[0]/3600;
+                miles_trip[0]+=mph[0]/3600; // per trip
+                miles_trip[1]+=mph[0]/3600; // per charge
+                miles_trip[2]+=mph[0]/3600; // user
                 kWh_trip[0]+=kW[0]/3600;
                 kWh_trip[1]+=kW[0]/3600;
                 kWh_trip[2]+=kW[0]/3600;
+            } else {
+                miles_trip[1]=0;
+                kWh_trip[1]=0;
             }
             
             motorRPM=0;
@@ -854,10 +857,8 @@
                     mph[i]+=mph[0];
                     mpkWh[i]=average;
                     average=kW[i]/timeConstant[i];
-                    if(!charging){ //Not charging - so include in efficiency data
-                        kW[i]-=average;
-                        kW[i]+=kW[0];
-                    }
+                    kW[i]-=average;
+                    kW[i]+=kW[0];
                     mpkWh[i]/=average;
                     if (mpkWh[i]<0) {
                         mpkWh[i]=99;// negative means inf.