Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Revision 180:5fdeeb86f3a3, committed 2014-03-24
- Comitter:
- TickTock
- Date:
- Mon Mar 24 01:18:05 2014 +0000
- Parent:
- 179:e4094e55f079
- Child:
- 181:396fdcceefd2
- Commit message:
- // added wh lookup table with correction from whpg real use
Changed in this revision
--- a/common.h Sun Mar 23 22:04:44 2014 +0000 +++ b/common.h Mon Mar 24 01:18:05 2014 +0000 @@ -19,7 +19,8 @@ #define healthScreen 18 #define testScreen 19 #define whpgScreen 20 -#define maxScreens 20 +#define whScreen 21 +#define maxScreens 21 #define btnGap 10 #define ttSkin 0
--- a/displayModes.cpp Sun Mar 23 22:04:44 2014 +0000 +++ b/displayModes.cpp Mon Mar 24 01:18:05 2014 +0000 @@ -1423,7 +1423,7 @@ showButton(3,0,"Reset","flags",4,4); } -void whpgDisplay(bool force, bool showButtons){ +void whpgDisplay(bool force, bool showButtons, bool showWh){ unsigned short maxVal, minVal, maxGid, minGid, i, j, y; float avg; static unsigned short lmg; @@ -1443,14 +1443,27 @@ } // find max/min/avg - for(i=0; i<300; i++){ - if(whpg[i]>0){ - j=(whpg[i]-whpg[i+1]); - avg+=j; - if(j>maxVal) maxVal=j; - if(j<minVal) minVal=j; - if(i>maxGid) maxGid=i; - if(i<minGid) minGid=i; + if(showWh){ + for(i=0; i<300; i++){ + if(wh[i]>0){ + j=(wh[i]-wh[i+1]); + avg+=j; + if(j>maxVal) maxVal=j; + if(j<minVal) minVal=j; + if(i>maxGid) maxGid=i; + if(i<minGid) minGid=i; + } + } + }else{ + for(i=0; i<300; i++){ + if(whpg[i]>0){ + j=(whpg[i]-whpg[i+1]); + avg+=j; + if(j>maxVal) maxVal=j; + if(j<minVal) minVal=j; + if(i>maxGid) maxGid=i; + if(i<minGid) minGid=i; + } } } avg /= (maxGid-minGid+1); @@ -1479,13 +1492,18 @@ tt.locate( 2, yWinMax-avg+2); printf("avg\n"); for( i=4; i<=286; i++) { - if((whpg[i-4]>0)&&(whpg[i+4]>0)){ - y = (whpg[i-4]-whpg[i+4])/4; + if(showWh){ + y = wh[i]-wh[i-1]; + tt.fillcircle(i+xWinMin,yWinMax-y,2,Green); }else{ - y = whpg[i]; - } - if( (y>20) && (y<180) && whpg[i]>0){ - tt.fillcircle(i+xWinMin,yWinMax-y,2,Green); + if((whpg[i-4]>0)&&(whpg[i+4]>0)){ + y = (whpg[i-4]-whpg[i+4])/4; + }else{ + y = whpg[i]; + } + if( (y>20) && (y<180) && whpg[i]>0){ + tt.fillcircle(i+xWinMin,yWinMax-y,2,Yellow); + } } if(i%40 == 0){ // label the x axis each 40 @@ -1569,7 +1587,10 @@ testDisplay(changed,showButtons); break; case whpgScreen: - whpgDisplay(changed,showButtons); + whpgDisplay(changed,showButtons,false); + break; + case whScreen: + whpgDisplay(changed,showButtons,true); break; default: if (changed){ @@ -1669,6 +1690,9 @@ case whpgScreen: // gg - index sprintf(sTemp2," WHPG"); break; + case whScreen: // gg - index + sprintf(sTemp2," WH"); + break; } showButton(1,tNavRow," Select",sTemp2,4,4);
--- a/displayModes.h Sun Mar 23 22:04:44 2014 +0000 +++ b/displayModes.h Mon Mar 24 01:18:05 2014 +0000 @@ -16,8 +16,7 @@ extern unsigned char displayLoc; extern char indexLastMsg[0x800]; extern unsigned short whpg[300]; - -//extern unsigned char battData[256]; // +extern float wh[300]; extern unsigned char battData[BatDataBufMax]; // BatDataBufMax extern unsigned long maxTarget; extern bool showCP;
--- a/main.cpp Sun Mar 23 22:04:44 2014 +0000 +++ b/main.cpp Mon Mar 24 01:18:05 2014 +0000 @@ -11,7 +11,8 @@ // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes) -// rev179 +// rev180 +// added wh lookup table with correction from whpg real use #include "mbed.h" #include "CAN.h" @@ -22,7 +23,7 @@ #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "179"; +char revStr[7] = "180"; unsigned long maxTarget = 1000; FATFS USBdrive; LocalFileSystem local("local"); @@ -183,7 +184,8 @@ bool ignoreDayData = true; unsigned short cgids,lgids=0; unsigned short whpg[300]={0}; -unsigned short wh[300]={0}; +float wh[300]; +float maxWhpg,minWh,whOff; int main() { char sTemp[40]; @@ -263,10 +265,9 @@ if(!feof(hfile)){ fscanf(hfile,"%f %f\r\n",&maxTripCCkWh,&minTripCCkWh); } - if(!feof(hfile)){ - for(i=0;i<300;i++){ - fscanf(hfile,"%d\r\n",&wh[i]); - } + for(i=0;i<300;i++){ + if(feof(hfile)) break; + fscanf(hfile,"%f\r\n",&wh[i]); } fclose(hfile); printMsg("History Loaded.\n"); // History loaded @@ -549,6 +550,9 @@ fprintf(hfile,"%f %f\r\n",maxTripMiles,minTripMiles); // Save max and min fprintf(hfile,"%f %f\r\n",maxTripkWh,minTripkWh); // Save max and min fprintf(hfile,"%f %f\r\n",maxTripCCkWh,minTripCCkWh); // Save max and min + for(i=0;i<300;i++){ + fprintf(hfile,"%f\r\n",wh[i]); + } fclose(hfile); } beep(2000,0.25); @@ -868,6 +872,9 @@ fprintf(hfile,"%f %f\r\n",maxTripMiles,minTripMiles); // Save max and min fprintf(hfile,"%f %f\r\n",maxTripkWh,minTripkWh); // Save max and min fprintf(hfile,"%f %f\r\n",maxTripCCkWh,minTripCCkWh); // Save max and min + for(i=0;i<300;i++){ + fprintf(hfile,"%f\r\n",wh[i]); + } fclose(hfile); } } @@ -902,7 +909,27 @@ CCkWh_trip[3]=0; ignoreDayData=false; lt=t; // Remember when counters were cleared - for(i=0;i<300;i++){ // Clear whpg array + maxWhpg=0; + minWh=0; + whOff=0; + // Adjust wh lookup with whpg data weighted 20% and clear array + for(i=1;i<300;i++){ + if(whpg[i]>maxWhpg){ + maxWhpg=whpg[i]; + minWh=wh[i]; + } + if(minWh>0){ + if((whpg[i]==0)&&(whpg[i-1]>0)){ //Remember the offset at the end of the measured range + whOff = minWh+maxWhpg-wh[i]; + } + wh[i] *= 4; + if(whOff>0){ // Apply offset to all level above measured range + wh[i] += wh[i]+whOff; + }else{ // Apply adjustment to measured range + wh[i] += minWh+maxWhpg-whpg[i]; + } + wh[i] /=5; + } whpg[i]=0; } }