Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Diff: displayModes.cpp
- Revision:
- 48:d1ce92104a1f
- Parent:
- 47:9cc7d876dd6d
- Child:
- 49:a3d2c5bb3cfa
--- a/displayModes.cpp Tue Apr 02 07:23:46 2013 +0000 +++ b/displayModes.cpp Sat Apr 06 04:18:49 2013 +0000 @@ -93,38 +93,81 @@ tt.foreground(Yellow); tt.set_font((unsigned char*) Arial28x28); if(force) tt.cls(); - if(force||gids!=lgids){ - tt.locate(10,10); - printf("%4d gids \n",gids); - tt.locate(20,40); - printf("%4.1f kWh \n",(float)gids*0.08); - tt.set_font((unsigned char*) SCProSB31x55); - tt.foreground(Green); - tt.locate(60,96); - printf("%4.1f mi \n",(float)(gids-5)*0.31); // Approx for now - lgids=gids; - tt.foreground(Yellow); - tt.set_font((unsigned char*) Arial28x28); - } - if(force||SOC!=lSOC){ - tt.locate(200,10); - printf("%4.1f%s\n",(float)SOC/10,"% "); - lSOC=SOC; - } - if(force||packV!=lpackV){ - tt.locate(200,200); - printf("%4.1fV \n",(float)packV/2); - lpackV=packV; - } - if(force||accV!=laccV){ - tt.locate(20,200); - printf("%3.1fV \n",accV); - laccV=accV; - } - if(force||kW!=lkW){ - tt.locate(180,40); - printf("%3.2fkW \n",kW); - lkW=kW; + if(skin==ttSkin){ + if(force||gids!=lgids){ + tt.locate(10,10); + printf("%4d gids \n",gids); + tt.locate(20,40); + printf("%4.1f kWh \n",(float)gids*0.08); + tt.set_font((unsigned char*) SCProSB31x55); + tt.foreground(Green); + tt.locate(60,96); + printf("%4.1f mi \n",(float)(gids-5)*0.31); // Approx for now + lgids=gids; + tt.foreground(Yellow); + tt.set_font((unsigned char*) Arial28x28); + } + if(force||SOC!=lSOC){ + tt.locate(200,10); + printf("%4.1f%s\n",(float)SOC/10,"% "); + lSOC=SOC; + } + if(force||packV!=lpackV){ + tt.locate(200,200); + printf("%4.1fV \n",(float)packV/2); + lpackV=packV; + } + if(force||accV!=laccV){ + tt.locate(20,200); + printf("%3.1fV \n",accV); + laccV=accV; + } + if(force||kW!=lkW){ + tt.locate(180,40); + printf("%3.2fkW \n",kW); + lkW=kW; + } + }else {//if(skin==ggSkin){ + if(force||gids!=lgids){ + tt.locate(10,10); + printf("%4d GIDs \n",gids); + + tt.locate(40,40); // gg - add GIDs Percent of 281 + printf("%4.1f%s \n", (float)gids*0.355872, "% ") ; + tt.locate(20,70); + //printf("%4.1f kWh \n",(float)gids*0.08); // is input, not usable + printf("%4.1f kwh \n",(float)gids*0.075); // gg - closer to usable + + tt.set_font((unsigned char*) SCProSB31x55); + tt.foreground(Green); + //tt.locate(60,96); + tt.locate(60,116); // gg - move down a little + printf("%4.1f mi \n",(float)(gids-5)*0.31); // Approx for now + lgids=gids; + tt.foreground(Yellow); + tt.set_font((unsigned char*) Arial28x28); + } + + if(force||SOC!=lSOC){ + tt.locate(200,10); + printf("%4.1f%s\n",(float)SOC/10,"% "); + lSOC=SOC; + } + if(force||packV!=lpackV){ + tt.locate(200,200); + printf("%4.1fV \n",(float)packV/2); + lpackV=packV; + } + if(force||accV!=laccV){ + tt.locate(20,200); + printf("%3.1fV \n",accV); + laccV=accV; + } + if(force||kW!=lkW){ + tt.locate(160,40); // gg - move left to keep from wrap + printf("%3.2fkw \n",kW); // use small w to save space + lkW=kW; + } } } @@ -140,13 +183,28 @@ static unsigned short ls; unsigned char throttle; static unsigned char lthrottle; + short steerOutBounds = 0 ; CANMessage msg; + //--------------- msg = lastMsg[indexLastMsg[0x180]]; //Get Throttle position throttle = msg.data[5]; + + // ---- steering ---- msg = lastMsg[indexLastMsg[0x002]]; //Get Steering angle steering = (msg.data[1]<<8)+msg.data[0]; - s= (unsigned short) ((steering/10)+160)%310; + + if(skin==ttSkin){ + s= (unsigned short) ((steering/10)+160)%310; // this modulo wraps display + }else{// if(skin==ggSkin){ + // do not go off screen left or right. gg - steering + short ss = (short) ((steering/15)+160); // less gain 10 -> 15 + if(ss<0) { ss=0; steerOutBounds = 1; } + if(ss>310) { ss=310; steerOutBounds = 1; } + s = (unsigned short) ss; + } + + //-------------- msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target and Regen regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5); targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5); @@ -172,16 +230,28 @@ lastPressure[2] = 200; lastPressure[3] = 200; } - + + // display the steering position small square if (s!=ls){ - tt.fillrect(ls,5,ls+9,14, Navy); - tt.fillrect(s,5,s+9,14, White); + // steering position has moved + //tt.fillrect(ls,5,ls+9,14, Navy); // blank old position + + //---- gg - steering red + // box is blanked by top of Braking bar, so move up 5 + tt.fillrect(ls,0,ls+9,9, Navy); // blank old position + if( steerOutBounds != 0 ) // draw out-of-bounds as a red box + tt.fillrect(s,0,s+9,9, Red); // draw out-of-bounds position + else + tt.fillrect(s,0,s+9,9, White); // draw new in-bounds position + + //---- //tt.foreground(Yellow); //tt.set_font((unsigned char*) Arial28x28); //tt.locate(10,40); //printf("%d %d \n",s,ls); ls=s; } + if (throttle!=lthrottle){ if (throttle>239) throttle=239; if(throttle<lthrottle){ @@ -294,6 +364,132 @@ } //---------------- +// gg - cpbars +void cpBarPlot(bool force, bool showButtons){ + short unsigned max, min, jv, i, bd; + unsigned avg; + short unsigned nBar[96] ; // bar height over min + + if(force){ + tt.foreground(White); + tt.background(Navy); + tt.set_font((unsigned char*) Arial12x12_prop); // select the font + max=0; + min=9999; + avg=0; + + // calc each cell-pair voltage, find max and min + for(i=0; i<96; i++){ + bd=(battData[i*2+3]<<8)+battData[i*2+4]; + nBar[i] = bd; // init to bar height + avg+=bd; + if(bd>max) max=bd; + if(bd<min) min=bd; + } + avg /= 96; + + if(min<3713) { + jv=avg-(max-avg)*1.5; + } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement + jv=0; + } + + //------------------ + 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 = max - min ; // zero to N + + //---------------- + if( iBarValMax == 0 ) { + // for testing + min = 3501 ; + //max = min + 95*2 ; // for tall values + max = min + 95/4 ; // for small values + avg = ( max + min ) / 2; + iBarValMax = max - min ; // zero to N + for(int i=0; i<96; i++) { + //nBar[i] = i*2 + min ; // test tall values + nBar[i] = i/4 + min ; // test small values + } + } + //--------------- + float nBarScale = float(height) / iBarValMax ; + if( nBarScale < 0.1 ) nBarScale = 0.1 ; + + // do the Bar-height scaling + for(int i=0; i<96; i++){ + nBar[i] -= min ; // now, 0 to N = iBinValMax + nBar[i] *= nBarScale ; // scale, as needed + } + + // values, for now + tt.locate( 0, yWinMax+40 ); + printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n", + max,min,avg,jv, + battData[224+5],battData[224+8], + battData[224+11],battData[224+14]); + + // label the X axis (approximate) + tt.locate( 2, yWinMax+5); printf("%04d", min ); + //tt.locate( 2, yWinMin-14 ); printf("%04d = %04d from %1.4f", max, int( height / nBarScale ) + min, nBarScale ); + tt.locate( 2, yWinMin-14 ); printf("%04d = (%d) mv range.", max , max - min ); + + //--------------- + // show the bars + int nBarWidth = 2 ; + int nBarSpace = 1 ; // 1 for testing + + int xPos = xWinMin + 2 ; // start one from the left + + for( int i=0; i<96; i++) { + height = nBar[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 y axis each 5 + if(i%5 == 4){ + 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.rect( xPos,yWinMax+2, xPos+1,yWinMax+5, White); // a white 2-wide tick mark is SLOW + } + // label the y axis each 10 + if(i%10 == 9){ + tt.locate( xPos-6, yWinMax+8 ); + printf("%02d\n", i+1 ); + } + + // step to the next bar position + xPos += nBarWidth + nBarSpace ; + } + + showCP=false; + } + + // handle the button + if(sMode==1&&showButtons){ + tt.foreground(Yellow); + tt.background(DarkCyan); + tt.set_font((unsigned char*) Arial12x12); + sprintf(sTemp1," Request"); + sprintf(sTemp2," CP data"); + showButton(1,0,sTemp1,sTemp2,3,3); + } +} + +//---------------- // gg - hist void cpHistogram(bool force, bool showButtons){ short unsigned max, min, jv, i, bd; @@ -330,9 +526,6 @@ tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red); tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green); - tt.locate( 0, yWinMax+10 ); - printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",max,min,avg,jv,battData[224+5],battData[224+8],battData[224+11],battData[224+14]); - // binning short nBin[301] ; // bins to count Min values in nBin[0], etc. int height ; @@ -365,6 +558,10 @@ } } + // the values, for now + tt.locate( 0, yWinMax+40 ); + printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",max,min,avg,jv,battData[224+5],battData[224+8],battData[224+11],battData[224+14]); + //--------------- // show the bars int nBarWidth = 3 ; @@ -399,6 +596,7 @@ } } +//--------------- void config1(bool force, bool showButtons){ if (force) { tt.background(Black); @@ -416,6 +614,8 @@ sprintf(sTemp1," Save"); sprintf(sTemp2," Config"); showButton(2,0,sTemp1,sTemp2,3,3); + + //------- second row ----- if (logEn) { sprintf(sTemp1," Disable"); } else { @@ -423,6 +623,7 @@ } sprintf(sTemp2," Logging"); showButton(0,1,sTemp1,sTemp2,3,3); + if (repeatPoll) { sprintf(sTemp1," Disable"); } else { @@ -430,6 +631,15 @@ } sprintf(sTemp2," Auto CP"); showButton(1,1,sTemp1,sTemp2,3,3); + + // add Enable/Disable Batt Log gg - yesBattLog + if (yesBattLog) { + sprintf(sTemp1," Disable"); + } else { + sprintf(sTemp1," Enable"); + } + sprintf(sTemp2," Batt Log"); + showButton(2,1,sTemp1,sTemp2,3,3); } void pbScreen(bool force, bool showButtons){ @@ -570,6 +780,9 @@ case cpHistScreen: // gg - hist cpHistogram(changed||showCP,(display==whichTouched)); break; + case cpBarScreen: // gg - cpbars + cpBarPlot(changed||showCP,(display==whichTouched)); + break; default: if (changed){ tt.background(Black); @@ -628,6 +841,9 @@ case cpHistScreen: // gg - hist sprintf(sTemp2," CP Hist"); break; + case cpBarScreen: // gg - cpbars + sprintf(sTemp2," CP Bars"); + break; } showButton(1,2,sTemp1,sTemp2,3,3); wait_ms(100); // pause a moment to reduce flicker