test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Diff: main.cpp
- Revision:
- 176:9c19f9856c76
- Parent:
- 175:0357b4159b40
- Child:
- 177:6fda79c2fda1
--- a/main.cpp Fri Feb 07 01:59:53 2014 +0000 +++ b/main.cpp Mon Feb 17 02:39:54 2014 +0000 @@ -8,13 +8,14 @@ // * 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 // * 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) #include "mbed.h" #include "CAN.h" @@ -135,9 +136,9 @@ signed long motorRPM; 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 CCkWh_trip[4]={0}; +float kWh_trip[4]={0}; +float miles_trip[4]={0}; float curEff = 0; float maxTripEff = 0; float minTripEff = 5; @@ -207,7 +208,7 @@ Resr = 0.075; // initial guess of Resr timer.start() ; RTC_Init(); // start the RTC Interrupts that sync the timer - struct tm t; // pointer to a static tm structure + struct tm t,lt; // pointer to a static tm structure NVIC_SetPriority(CAN_IRQn, 2); //set can priority just below RTC NVIC_SetPriority(TIMER3_IRQn, 3); //set ticker priority just below can @@ -835,22 +836,23 @@ 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 (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 } @@ -873,6 +875,29 @@ 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 + curEff = miles_trip[3]/kWh_trip[3]; + if (maxTripEff<curEff) { + maxTripEff=curEff; + maxTripMiles=miles_trip[3]; + maxTripkWh=kWh_trip[3]; + maxTripCCkWh=CCkWh_trip[3]; + } + if (minTripEff>curEff) { + minTripEff=curEff; + minTripMiles=miles_trip[3]; + minTripkWh=kWh_trip[3]; + minTripCCkWh=CCkWh_trip[3]; + } + } + miles_trip[3]=0; + kWh_trip[3]=0; + CCkWh_trip[3]=0; + } + lt=t; wait5secs=5; getGids=true; if (showHealth&&!playbackOpen){ @@ -974,12 +999,15 @@ miles_trip[0]+=mph[0]/3600; // per trip miles_trip[1]+=mph[0]/3600; // per charge miles_trip[2]+=mph[0]/3600; // user + miles_trip[3]+=mph[0]/3600; // user kWh_trip[0]+=kW[0]/3600; kWh_trip[1]+=kW[0]/3600; kWh_trip[2]+=kW[0]/3600; + kWh_trip[3]+=kW[0]/3600; CCkWh_trip[0]+=CCkW/3600; CCkWh_trip[1]+=CCkW/3600; CCkWh_trip[2]+=CCkW/3600; + CCkWh_trip[3]+=CCkW/3600; } else { // charging so reset per charge trip meter miles_trip[1]=0; kWh_trip[1]=0;