Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Diff: displayModes.cpp
- Branch:
- Metric
- Revision:
- 99:c05abf8e1cdc
- Parent:
- 98:9f8bab96edff
- Parent:
- 97:a25940fd7b5b
- Child:
- 102:fd19f777a0b4
diff -r 9f8bab96edff -r c05abf8e1cdc displayModes.cpp --- a/displayModes.cpp Mon Jun 10 12:00:48 2013 +0000 +++ b/displayModes.cpp Sat Jun 15 18:47:38 2013 +0000 @@ -55,19 +55,20 @@ } void printLog (bool force, bool showButtons){ - static unsigned char lastDisplayLoc = 0; - if(force||displayLoc!=lastDisplayLoc){ //only update if changed + static unsigned char lastldl = 0; + unsigned char ldl=displayLoc; + if(force||ldl!=lastldl){ //only update if changed tt.foreground(Amber); tt.background(Black); tt.cls(); tt.locate(0,6); tt.set_font((unsigned char*) Arial12x12); for(int i=0; i<19; i++){ - printf("%s",displayLog[displayLoc]); - displayLoc=displayLoc>17?0:displayLoc+1; + printf("%s",displayLog[ldl]); + ldl=ldl>17?0:ldl+1; } } - lastDisplayLoc=displayLoc; + lastldl=ldl; } void mainDisplay (bool force, bool showButtons){ @@ -321,6 +322,7 @@ void cpData(bool force, bool showButtons){ short unsigned max, min, jv, i, bd; unsigned avg; + static char step=0; // counter to allow incremental update if(force){ tt.foreground(White); tt.background(Navy); @@ -340,35 +342,49 @@ } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement jv=0; } - tt.cls(); - tt.locate(0,6); - // BatDataBaseG4 * 7 = 224 - char* sTemperatureUnit = temperatureUnit(); - printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n", + + switch(step){ + case 0: + tt.cls(); + showCP=true; + break; + case 1: + tt.locate(0,6); + // BatDataBaseG4 * 7 = 224 + char* sTemperatureUnit = temperatureUnit(); + printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n", max,min,avg,jv, convertTemperature(battData[224+5]),sTemperatureUnit,convertTemperature(battData[224+8]),sTemperatureUnit, convertTemperature(battData[224+11]),sTemperatureUnit,convertTemperature(battData[224+14]),sTemperatureUnit); - tt.locate(0,36); - for(i=0; i<16; i++){ - printf("%02d-%02d : %04d %04d %04d %04d %04d %04d\n", - i*6+1,i*6+6, - (battData[i*12+3]<<8)+battData[i*12+4],(battData[i*12+5]<<8)+battData[i*12+6], - (battData[i*12+7]<<8)+battData[i*12+8],(battData[i*12+9]<<8)+battData[i*12+10], - (battData[i*12+11]<<8)+battData[i*12+12],(battData[i*12+13]<<8)+battData[i*12+14]); + //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]); + tt.rect(8+0*41,16,40+0*41,28,Green); + tt.rect(8+1*41,16,40+1*41,28,Yellow); + //tt.rect(8+2*41,16,40+2*41,28,White); + tt.rect(8+3*41,16,40+3*41,28,Red); + break; + default: + tt.locate(0,36+(step-2)*48); + for(i=(step-2)*4; i<(step-1)*4; i++){ + printf("%02d-%02d : %04d %04d %04d %04d %04d %04d\n", + i*6+1,i*6+6, + (battData[i*12+3]<<8)+battData[i*12+4],(battData[i*12+5]<<8)+battData[i*12+6], + (battData[i*12+7]<<8)+battData[i*12+8],(battData[i*12+9]<<8)+battData[i*12+10], + (battData[i*12+11]<<8)+battData[i*12+12],(battData[i*12+13]<<8)+battData[i*12+14]); + } + for(i=(step-2)*24; i<(step-1)*24; i++){ + bd=(battData[i*2+3]<<8)+battData[i*2+4]; + if(bd>0){ + if(bd==max) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Green); + //if(bd==avg) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,White); + if(bd==min) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Yellow); + if(bd<jv) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Red); + } + } } - tt.rect(8+0*41,16,40+0*41,28,Green); - tt.rect(8+1*41,16,40+1*41,28,Yellow); - //tt.rect(8+2*41,16,40+2*41,28,White); - tt.rect(8+3*41,16,40+3*41,28,Red); - for(i=0; i<96; i++){ - bd=(battData[i*2+3]<<8)+battData[i*2+4]; - if(bd>0){ - if(bd==max) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Green); - //if(bd==avg) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,White); - if(bd==min) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Yellow); - if(bd<jv) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Red); - } + step=step<5?step+1:0; + if(step==0){ + showCP=false; } - showCP=false; } if((sMode==1)&&showButtons){ tt.foreground(Yellow); @@ -816,9 +832,8 @@ tt.background(Navy); tt.foreground(Yellow); if(force){ + tt.set_font((unsigned char*) Arial12x12); tt.cls(); - toVal=33; - x=50+0*6; tt.locate(x-10,226); printf("sec\n"); @@ -843,26 +858,31 @@ //tt.locate(x-10,226); //printf("year\n"); //tt.line(x,10,x,220,DarkGrey); + toVal=33; } else { - toVal=18;// no need to constantly update the long tc values + toVal=24;// no need to constantly update the long tc values } if(force||lgids!=gids){ // update Y axis when kWh changes - tt.set_font((unsigned char*) Arial12x12); - for(i=0;i<10;i++){ - y=200-i*20; - tt.locate(10,y-8); - if (showMiles){ + //tt.set_font((unsigned char*) Arial12x12); + tt.set_font((unsigned char*) Arial24x23); + //for(i=0;i<10;i++){ + //y=200-i*20; + for(i=3;i<8;i++){ + y=200-(i-3)*40; + tt.locate(0,y-8); + if (showMiles){ printf("%3.0f\n",convertDistance(i*((float)(gids-5)*.075))); // LM - Added metric support + //printf("%2.0f \n",i*((float)(gids-5)*.075)); }else{ printf("%d.0\n",i); } - tt.line(40,y,toVal*6+56,y,DarkGrey); + tt.line(48,y,toVal*6+56,y,DarkGrey); } lgids=gids; } if(updateDTE||force){ - for(i=0;i<10;i++){ - y=200-i*20; + for(i=3;i<8;i++){ + y=200-(i-3)*40; tt.line(40,y,158,y,DarkGrey); } @@ -894,17 +914,16 @@ tt.locate(151,8); printf(" %2.1f\n",miles); } + tt.foreground(Cyan); + tt.set_font((unsigned char*) Arial24x23); + tt.locate(198,70); + printf("%3.1f \n",mpkWh[dtePeriod]); } else { - tt.locate(180,10); + tt.locate(200,10); printf("%3.1f \n",mpkWh[dtePeriod]); } lx=50; - ly=mpkWh[0]*20; - if(ly<200) { - ly=200-ly; - }else{ - ly=0; - } + ly=mpkWh[0]*40; if(dtePeriod==0){ radius=6; color=Yellow; @@ -912,17 +931,20 @@ radius=2; color=Green; } + if(ly<100){ + ly=220; + color=Red; + }else if(ly<320) { + ly=320-ly; + }else{ + ly=0; + } tt.fillcircle(lx,leff[0],radius,Navy); tt.fillcircle(lx,ly,radius,color); for(i=1;i<toVal;i++){ x=50+i*6; - y=mpkWh[i]*20; - if(y<200) { - y=200-y; - }else{ - y=0; - } + y=mpkWh[i]*40; if(i==dtePeriod){ radius=6; color=Yellow; @@ -930,6 +952,14 @@ radius=2; color=Green; } + if(y<100){ + y=220; + color=Red; + }else if(y<320) { + y=320-y; + }else{ + y=0; + } tt.fillcircle(x,leff[i],radius,Navy); tt.line(x-6,leff[i-1],x,leff[i],Navy); leff[i-1]=ly;