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

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Sun Mar 30 03:31:37 2014 +0000
Parent:
182:10017d74de67
Child:
184:5ca7b78297fe
Commit message:
// * Fix wrong whpg bug when charging away from home (now update and clear on each charge)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Mar 30 03:00:14 2014 +0000
+++ b/main.cpp	Sun Mar 30 03:31:37 2014 +0000
@@ -9,9 +9,9 @@
 // * 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
 // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes)
-// * Fix wrong whpg bug when charging away from home (no clearing of trip[3])
 
-// rev182
+// rev183
+// * Fix wrong whpg bug when charging away from home (now update and clear on each charge)
 
 #include "mbed.h"
 #include "CAN.h"
@@ -22,7 +22,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "182";
+char revStr[7] = "183";
 unsigned long maxTarget = 1000;
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -885,32 +885,7 @@
                 CCkWh_trip[0]=0;
                 seconds = time(NULL);
                 t = *localtime(&seconds);
-                if((t.tm_yday>lt.tm_yday)&&(t.tm_hour>effCheckTime)&&(miles_trip[1]<1)){
-                    // Check and reset daily efficiency if charged since last trip and at least 24 hours has past
-                    if (!ignoreDayData&&(miles_trip[3]>15)){ // Ignore low mileage data
-                        curEff = miles_trip[3]/kWh_trip[3]; // Get current daily efficiency
-                        if (maxTripEff<curEff) {
-                            maxTripEff=curEff;
-                            maxTripMiles=miles_trip[3];
-                            maxTripkWh=kWh_trip[3];
-                            maxTripCCkWh=CCkWh_trip[3];
-                            printMsg("New max efficiency.\n");
-                        }
-                        if (minTripEff>curEff) {
-                            minTripEff=curEff;
-                            minTripMiles=miles_trip[3];
-                            minTripkWh=kWh_trip[3];
-                            minTripCCkWh=CCkWh_trip[3];
-                            printMsg("New min efficiency.\n");
-                        }
-                    }
-                    // Clear daily efficiency data
-                    dailyGids=0;
-                    miles_trip[3]=0;
-                    kWh_trip[3]=0;
-                    CCkWh_trip[3]=0;
-                    ignoreDayData=false;
-                    lt=t; // Remember when counters were cleared (start time for new data)
+                if(miles_trip[1]<1){ // charged since last trip
                     maxWhpg=0;
                     minWh=0;
                     whOff=0;
@@ -947,7 +922,34 @@
                     for(i=0;i<300;i++){ // clear array
                         whpg[i]=0;
                     }
-                }
+                    if((t.tm_yday>lt.tm_yday)&&(t.tm_hour>effCheckTime)){
+                        // Check and reset daily efficiency if charged since last trip and at least 24 hours has past
+                        if (!ignoreDayData&&(miles_trip[3]>15)){ // Ignore low mileage data
+                            curEff = miles_trip[3]/kWh_trip[3]; // Get current daily efficiency
+                            if (maxTripEff<curEff) {
+                                maxTripEff=curEff;
+                                maxTripMiles=miles_trip[3];
+                                maxTripkWh=kWh_trip[3];
+                                maxTripCCkWh=CCkWh_trip[3];
+                                printMsg("New max efficiency.\n");
+                            }
+                            if (minTripEff>curEff) {
+                                minTripEff=curEff;
+                                minTripMiles=miles_trip[3];
+                                minTripkWh=kWh_trip[3];
+                                minTripCCkWh=CCkWh_trip[3];
+                                printMsg("New min efficiency.\n");
+                            }
+                        }
+                        // Clear daily efficiency data
+                        dailyGids=0;
+                        miles_trip[3]=0;
+                        kWh_trip[3]=0;
+                        CCkWh_trip[3]=0;
+                        ignoreDayData=false;
+                        lt=t; // Remember when counters were cleared (start time for new data)
+                    }
+                } // Charged since last trip
                 wait5secs=5;
                 if (showHealth&&!playbackOpen){
                     if (saveDmode[0]==99){
@@ -982,11 +984,8 @@
                 }
             }
             if((cgids>0)&&(cgids<300)){
-                if(cgids<lgids){
-                    whpg[cgids] = (unsigned short) (1000*kWh_trip[3]); // Save kWh for each gid since last charge
-                    lgids=cgids;
-                }else if(cgids>lgids){
-                    whpg[cgids] = (unsigned short) (1000*kWh_trip[3]); // Save kWh for each gid since last charge
+                if(cgids!=lgids){
+                    whpg[cgids] = (unsigned short) (1000*(kWh_trip[1]+CCkWh_trip[1])); // Save kWh for each gid since last charge
                     lgids=cgids;
                 }
             }
@@ -1072,9 +1071,6 @@
                 miles_trip[1]=0;
                 kWh_trip[1]=0;
                 CCkWh_trip[1]=0;
-                //if((cgids>0)&&(cgids<300)){
-                //    whpg[cgids]=0;
-                //}
             }
             
             motorRPM=0;