test fork

Dependencies:   SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary_9341 by Tick Tock

Revision:
149:e9739523109f
Parent:
148:6e3b9135fad2
Child:
150:ef46ce63345c
--- a/main.cpp	Thu Sep 12 14:42:22 2013 +0000
+++ b/main.cpp	Wed Sep 25 03:33:18 2013 +0000
@@ -5,20 +5,18 @@
 // * Add 50% charge option
 // * Add coasting regen to regen/braking display
 // * Change semilog efficiency graph to linear with 10 minute values
-// * Add additional 79b bank readouts
 // * Subtract accessory power from efficiency history (add back in when displaying)
-// * Add trip history display
 // * Add in-device config editor
-// * Add temperature to efficiency lookup table
-// * Add debug screen
+// * Normalize efficiency to 25C relative to ambient.  Display efficiency at current temp.
+// * 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 efficiency reset
 
-// rev148
-// No longer save config after firmware update
-// Added config health check after read
-// Added debugScreen
-// Switched friction monitor to msgId:292 so MY2013 will work
-// Added ambient to main display
-// Added Resr to trip log
+
+// rev149
+// Added temperature compensation for efficiency/DTE computation
 
 #include "mbed.h"
 #include "CAN.h"
@@ -29,7 +27,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "148"; // gg - revision string, max 6 characters
+char revStr[7] = "149"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -135,6 +133,7 @@
 float mph[39]={0};
 float kW[39]={0};
 float mpkWh[39]={0};
+float ambient_F;
 float unloadedV_x2,Resr,curRmax,curRmin,redRmax,redRmin,incRmax,incRmin;
 signed short Imax, Imin;
 // Logarithmic division scale (roughly - snapped to common units of time)
@@ -158,6 +157,7 @@
 bool moving=false;
 unsigned short chirpInt;
 unsigned short uMsgId[8] = {0x5103, 0x50a3, 0x54a4, 0x54b4, 0x54c0, 0x55b4, 0x0000, 0x0000}; // messages to display on debug screen msgId:byte
+float nomDrag;
 
 int main() {
     char sTemp[40];
@@ -205,7 +205,9 @@
     printMsg(sTemp); // revision
 
     //read efficiency history data
-    hfile = fopen("/local/ehist.cny", "r");
+    if(!tt.is_touched()){  //skip if screen touched (reset efficiency)
+        hfile = fopen("/local/ehist.cny", "r");
+    }
     if (hfile!=NULL){ // found a efficiency history file
         for(i=0;i<39;i++){
             if(!feof(hfile)){
@@ -227,6 +229,8 @@
             mpkWh[i]=4;
         }
     }
+    
+    nomDrag = airDrag(77); // Compute drag coefficient for 25C
 
     // Read config file
     readConfig();
@@ -709,6 +713,7 @@
 
         if(tick){ // Executes once a second
             tick=false;
+            ambient_F = lastMsg[indexLastMsg[0x54c]].data[6]-56;
             curEff = miles_trip[0]/kWh_trip[0];
             headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false;  // headlight/turn signal indicator
             if(accOn&&indexLastMsg[0x355]>0){
@@ -805,7 +810,7 @@
 
             if(numWsamples>0){ // Avoid div0
                 mpkWh[0]=mph[0];
-                kW[0]=((float) mWs_x4)/numWsamples/4e3;     
+                kW[0]=((float) mWs_x4)/numWsamples/4e3;
                 mpkWh[0]/=kW[0];
                 if (mpkWh[0]<0) {
                     mpkWh[0]=99;// negative means inf.
@@ -814,6 +819,8 @@
                 kW[0]=0;
                 mpkWh[0]=0;
             }
+            // TOTest: Normalize kW[0] to 25C (after computing mpkWh[0])
+            kW[0]=kW[0]/airDrag(ambient_F)*nomDrag;
             numWsamples=0;
 
             if (!charging){