test fork

Dependencies:   SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary_9341 by Tick Tock

Revision:
177:6fda79c2fda1
Parent:
176:9c19f9856c76
Child:
178:bf6404312c45
--- a/main.cpp	Mon Feb 17 02:39:54 2014 +0000
+++ b/main.cpp	Thu Mar 06 15:37:40 2014 +0000
@@ -9,13 +9,13 @@
 // * 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)
-// * Base best and worse case on full round trip (per charge efficiency)
+
 
-// rev175
-// Added to the temperature lookup table
-// Fixed div0 boundary condition bug in CP histogram
-// Splash trip meter on second screen when turned off if showHealth is enabled
-// Max and min efficiency computed over 24 hour interval (to get roundtrip efficiency)
+// rev176
+// Changed effciency counter to check after charging after 3am
+// Added cancel day data button to trip display
+// Base best and worse case on full round trip (per charge efficiency)
+// Track daily wh/gid
 
 #include "mbed.h"
 #include "CAN.h"
@@ -26,7 +26,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "175";
+char revStr[7] = "176";
 unsigned long maxTarget = 1000;
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -119,6 +119,7 @@
 float scale12V = 16.2; // R1:R2 ratio
 float kWperGid = 0.080;
 unsigned short startGids = 0; // Gids at start of trip
+unsigned short dailyGids = 0; // Gids per day
 bool getGids = false;
 signed long mWs_x4 = 0;
 unsigned short numWsamples = 0;
@@ -182,6 +183,8 @@
 unsigned long tbScalar = 72464;
 unsigned long rbScalar = 8696;
 unsigned long fbScalar = 132;
+int effCheckTime = 3;
+bool ignoreDayData = true;
 
 int main() {
     char sTemp[40];
@@ -213,7 +216,8 @@
     NVIC_SetPriority(TIMER3_IRQn, 3); //set ticker priority just below can
 
     seconds = time(NULL);
-    t = *localtime(&seconds) ;
+    t = *localtime(&seconds);
+    lt = t; // initialize
     // is it a date before 2012 ?
     if ((t.tm_year + 1900) < 2012 ) {
         // before 2013 so update year to make date entry easier
@@ -666,6 +670,9 @@
                                     debugMode = !debugMode;                                
                                 } else if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = configScreen ; // GoTo Config Screen
+                                } else if (dMode[whichTouched]==tripScreen) { // Cancel day trip meter
+                                    ignoreDayData=true;
+                                    lastDMode[whichTouched]=99;//repaint to clear highlight
                                 } else if ((dMode[whichTouched]==dateScreen)&&accOn){
                                     syncDone=false; // initiate clock sync
                                     lastDMode[whichTouched]=99;
@@ -722,6 +729,7 @@
                                     logEn=false;
                                     updateFirmware();
                                 } else if (dMode[whichTouched]==tripScreen) {
+                                    // Reset custom trip meter
                                     miles_trip[2]=0;
                                     kWh_trip[2]=0;
                                     CCkWh_trip[2]=0;
@@ -824,6 +832,7 @@
             moving=(mph[0]>0.1);
             charging=(lastMsg[indexLastMsg[0x5bf]].data[2]>0)?true:false; // FF when charging
             if (laccOn&&!accOn){ // Car turned off
+                dailyGids += startGids-((lastMsg[indexLastMsg[0x5bc]].data[0]<<2)+(lastMsg[indexLastMsg[0x5bc]].data[1]>>6));
                 lHeaterOn=false;
                 if (showHealth&&!playbackOpen){
                     if (saveDmode[0]==99){
@@ -836,23 +845,6 @@
                     sMode=0;
                     userIdle=false;
                 }
-                // Move to car on clause to use 24hour efficiency
-                // 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
                     tripLog(); // Write trip log on powerdown
                 }
@@ -872,13 +864,15 @@
             }
             if (!laccOn&&accOn){ // Car turned on
                 lHeaterOn=false;
+                getGids=true;
                 miles_trip[0]=0;
                 kWh_trip[0]=0;
                 CCkWh_trip[0]=0;
                 seconds = time(NULL);
                 t = *localtime(&seconds);
-                if((t.tm_hour>=2)&&(lt.tm_hour<2)){ // Reset daily efficiency every day at 2am
-                    if (miles_trip[3]>25){ // Ignore low mileage data
+                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
+                    if (!ignoreDayData&&(miles_trip[3]>25)){ // Ignore low mileage data
                         curEff = miles_trip[3]/kWh_trip[3];
                         if (maxTripEff<curEff) {
                             maxTripEff=curEff;
@@ -893,13 +887,14 @@
                             minTripCCkWh=CCkWh_trip[3];
                         }
                     }
+                    dailyGids=0;
                     miles_trip[3]=0;
                     kWh_trip[3]=0;
                     CCkWh_trip[3]=0;
+                    ignoreDayData=false;
+                    lt=t; // Remember when counters were cleared
                 }
-                lt=t;
                 wait5secs=5;
-                getGids=true;
                 if (showHealth&&!playbackOpen){
                     if (saveDmode[0]==99){
                         saveDmode[0]=dMode[0];
@@ -907,7 +902,7 @@
                     dMode[0]=healthScreen;
                 }
                 syncDone=!autoSync; // clear syncDone flag if autoSync enabled
-            }
+            } // Car turned on
             laccOn=accOn;
             if(!accOn&&userIdle&&!playbackEn){ // Car off and no user activity - turn off screen
                 dled = 0;
@@ -926,7 +921,7 @@
             }
             if(getGids){
                 startGids=(lastMsg[indexLastMsg[0x5bc]].data[0]<<2)+(lastMsg[indexLastMsg[0x5bc]].data[1]>>6);  //Get gids
-                if((startGids>0)&&(startGids<300)){
+                if((startGids>0)&&(startGids<300)){ // Ignore bogus values at startup
                     getGids=false;
                 }
             }