Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Diff: displayModes.cpp
- Revision:
- 179:e4094e55f079
- Parent:
- 178:bf6404312c45
- Child:
- 180:5fdeeb86f3a3
--- a/displayModes.cpp Wed Mar 19 14:08:56 2014 +0000 +++ b/displayModes.cpp Sun Mar 23 22:04:44 2014 +0000 @@ -1194,7 +1194,7 @@ tt.line(x,10,x,220,DarkGrey); x=50+38*6; lar=0; - } + } toVal=33; if(force||lgids!=gids){ // update Y axis when kWh changes tt.set_font((unsigned char*) Arial24x23); @@ -1424,81 +1424,82 @@ } void whpgDisplay(bool force, bool showButtons){ - unsigned short maxVal, minVal, maxGid, minGid, avg, i, j; + unsigned short maxVal, minVal, maxGid, minGid, i, j, y; + float avg; + static unsigned short lmg; + + tt.foreground(White); + tt.background(Navy); + tt.set_font((unsigned char*) Arial12x12_prop); // select the font + + maxVal=0; + minVal=9999; + maxGid=0; + minGid=9999; + avg=0; if(force){ - tt.foreground(White); - tt.background(Navy); - tt.set_font((unsigned char*) Arial12x12_prop); // select the font - maxVal=0; - minVal=9999; - maxGid=0; - minGid=9999; - avg=0; - - // find max/min/avg - for(i=0; i<300; i++){ - j=whpg[i]; - if(j<255){ - avg+=j; - if(j>maxVal) maxVal=j; - if(j<minVal) minVal=j; - if(i>maxGid) maxGid=i; - if(i<minGid) minGid=i; - } + lmg=281; + } + + // 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; } - avg /= (maxGid-minGid+1); + } + avg /= (maxGid-minGid+1); + if (minGid<lmg){ //update if new data + lmg = minGid; //------------------ tt.cls(); // show as vertical bar plot int xWinMin = 26; int xWinMax = 316; - int yWinMin = 50; - int yWinMax = 150; - // draw the Bar Graph Frame, 2 pixels wide - tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red); - tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green); - - // bar heights - int height = yWinMax - yWinMin ; - int iBarValMax = maxVal - minVal ; // zero to N + int yWinMin = 20; + int yWinMax = 200; + // draw the Frame, 2 pixels wide + tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1, Red); + tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2, Green); //---------------- - if( iBarValMax > 0 ) { + if( maxVal > minVal ) { // label the Y axis - tt.locate( 2, yWinMin-14 ); printf("%02d\n", maxVal ); - tt.locate( 2, yWinMax+5); printf("%02d\n", minVal ); - tt.locate( 2, (yWinMax+yWinMin)/2); printf("%02d avg\n", avg ); - - //--------------- - // show the bars - int nBarWidth = 1 ; - int nBarSpace = 0 ; // 1 for testing - - int xPos = xWinMin + 2 ; // start one from the left - - for( int i=minGid; i<=maxGid; i++) { - height = whpg[i] ; - if( height > 100 ) height = 100 ; // clip tops - - // draw the bar, is always inside x-window - tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green); - // tic mark the x axis each 10 - if(i%10 == 9){ - tt.line( xPos,yWinMax+2, xPos,yWinMax+5, White); // a white tick mark - tt.line( xPos+1,yWinMax+2, xPos+1,yWinMax+5, White); // a white tick mark, to widen + tt.locate( 2, yWinMin-14); printf("200\n"); + tt.locate( 2, yWinMax+5); printf("0\n"); + tt.locate( 2, yWinMax-avg-18); printf("%3.1f\n", avg ); + 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; + }else{ + y = whpg[i]; + } + if( (y>20) && (y<180) && whpg[i]>0){ + tt.fillcircle(i+xWinMin,yWinMax-y,2,Green); } - // label the x axis each 20 - if(i%20 == 19){ - tt.locate( xPos-6, yWinMax+8 ); - printf("%02d\n", i+1 ); + if(i%40 == 0){ + // label the x axis each 40 + tt.line( i+xWinMin,yWinMax+2, i+xWinMin,yWinMax+8, White ); // a white tick mark + if(i<10){ + tt.locate( i+xWinMin-12, yWinMax+8 ); + }else{ + tt.locate( i+xWinMin-20, yWinMax+8 ); + } + printf("%d\n", i ); + } else if(i%10 == 0){ + // tic mark the x axis each 10 + tt.line( i+xWinMin,yWinMax+2, i+xWinMin,yWinMax+4, White ); // a white tick mark } - - // step to the next bar position - xPos += nBarWidth + nBarSpace ; } } }