test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Revision 177:6fda79c2fda1, committed 2014-03-06
- Comitter:
- TickTock
- Date:
- Thu Mar 06 15:37:40 2014 +0000
- Parent:
- 176:9c19f9856c76
- Child:
- 178:bf6404312c45
- Commit message:
- // 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
Changed in this revision
--- a/displayModes.cpp Mon Feb 17 02:39:54 2014 +0000 +++ b/displayModes.cpp Thu Mar 06 15:37:40 2014 +0000 @@ -80,15 +80,16 @@ // worst-case DTE // Compute DTE based on worst saved trip efficiency (without climate control) and adding the impact // of the current climate control power relative to the last 10 minutes of driving - dte=convertDistance((minTripEff-mpkWh_noCC+mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion - tt.foreground(Green); - tt.locate(10,84); - if(dte>=9.5){ - printf("%2.0f \n",dte); - }else{ - printf("%2.1f \n",dte); + if(maxTripEff>0){// Skip if no data available + dte=convertDistance((minTripEff-mpkWh_noCC+mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion + tt.foreground(Green); + tt.locate(10,84); + if(dte>=9.5){ + printf("%2.0f \n",dte); + }else{ + printf("%2.1f \n",dte); + } } - // 10-minute DTE tt.set_font((unsigned char*) SCProSB31x55); tt.foreground(Yellow); @@ -133,17 +134,19 @@ tt.set_font((unsigned char*) Arial28x28); // Compute DTE based on best saved trip efficiency (without climate control) and adding the impact // of the current climate control power relative to the last 10 minutes of driving - dte=convertDistance((maxTripEff-mpkWh_noCC+mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion - tt.foreground(Orange); - if(dte>=99.5){ - tt.locate(255,84); - printf("%3.0f \n",dte); - }else if(dte>=9.5){ - tt.locate(270,84); - printf("%2.0f \n",dte); - }else{ - tt.locate(265,84); - printf("%2.1f \n",dte); + if(maxTripEff>0){// Skip if no data available + dte=convertDistance((maxTripEff-mpkWh_noCC+mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion + tt.foreground(Orange); + if(dte>=99.5){ + tt.locate(255,84); + printf("%3.0f \n",dte); + }else if(dte>=9.5){ + tt.locate(270,84); + printf("%2.0f \n",dte); + }else{ + tt.locate(265,84); + printf("%2.1f \n",dte); + } } lmpkWh=mpkWh[dtePeriod]; } //!(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh) @@ -377,7 +380,8 @@ lkWh=(int)(kWh_trip[0]*100); } if(showButtons){ - showButton(3,2," Reset"," ",4,4); + showButton(3,1," Cancel"," Day",4,4); + showButton(3,2," Reset","Custom",4,4); } } @@ -421,8 +425,8 @@ }*/ if(force||gids!=lgids){ tt.locate(10,10); - if((gids+5)<startGids){ // Wh/gid, too, if trip long enough - printf("%d gids (%0.0f)\n",gids,1000*(kWh_trip[0]+CCkWh_trip[0])/(startGids-gids)); + if(dailyGids>5){ // Wh/gid, too + printf("%d gids (%0.0f)\n",gids,1000*(kWh_trip[3]+CCkWh_trip[3])/dailyGids); }else{ printf("%d gids \n",gids); }
--- a/displayModes.h Mon Feb 17 02:39:54 2014 +0000 +++ b/displayModes.h Thu Mar 06 15:37:40 2014 +0000 @@ -75,7 +75,7 @@ extern float CCkW; extern bool CCon; extern float kWperGid; -extern unsigned short startGids; +extern unsigned short dailyGids; extern unsigned long tbScalar; extern unsigned long rbScalar; extern unsigned long fbScalar;
--- 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; } }