Dual CANbus monitor and instrumentation cluster
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed
Fork of CANary by
Diff: displayModes.cpp
- Revision:
- 66:b7476ce7a59e
- Parent:
- 65:821fc79cd7fe
- Child:
- 68:10f7d7dbae19
--- a/displayModes.cpp Wed Apr 10 15:08:38 2013 +0000 +++ b/displayModes.cpp Thu Apr 11 05:10:26 2013 +0000 @@ -191,7 +191,7 @@ steering = (msg.data[1]<<8)+msg.data[0]; if(skin==ttSkin){ - s= (unsigned short) ((steering/10)+160)%310; // this modulo wraps display + s= (unsigned short) ((steering/10)+155)%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 @@ -708,8 +708,7 @@ break; } tt.background(DarkCyan); - showButton(0,1,sTemp1,"",4,4); - + showButton(0,1,sTemp1,"",4,4); showButton(1,1," UP","",4,4); showButton(2,1," DOWN","",4,4); } @@ -717,10 +716,13 @@ } void dteDisplay(bool force, bool showButtons, bool showMiles){ - unsigned short i,x,y,lx,ly,gids,radius,color; + unsigned short i,x,y,lx,ly,gids,radius,color,r,t; static unsigned short lgids=0; static unsigned char leff[39]={0}; CANMessage msg; + unsigned long targetBraking, regenBraking, temp; + static unsigned long maxTarget = 1000, maxRegen = 1000, tarDivReg = 1000; + static unsigned char lr=0, lt=0; msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids gids = (msg.data[0]<<2)+(msg.data[1]>>6); @@ -743,7 +745,7 @@ }else{ printf("%d.0\n",i); } - tt.line(40,y,280,y,DarkGrey); + tt.line(40,y,254,y,DarkGrey); } x=50+0*6; @@ -767,16 +769,16 @@ printf("mon\n"); tt.line(x,10,x,220,DarkGrey); x=50+38*6; - tt.locate(x-10,226); - printf("year\n"); - tt.line(x,10,x,220,DarkGrey); + //tt.locate(x-10,226); + //printf("year\n"); + //tt.line(x,10,x,220,DarkGrey); lgids=gids; } if(force||updateDTE){ for(i=0;i<10;i++){ y=200-i*20; if (y>60){ - tt.line(40,y,280,y,DarkGrey); + tt.line(40,y,250,y,DarkGrey); } else { tt.line(40,y,150,y,DarkGrey); } @@ -789,19 +791,19 @@ x=50+18*6; tt.line(x,10,x,220,DarkGrey); x=50+25*6; - tt.line(x,180,x,220,DarkGrey); + tt.line(x,60,x,220,DarkGrey); x=50+32*6; - tt.line(x,180,x,220,DarkGrey); - x=50+38*6; - tt.line(x,180,x,220,DarkGrey); + tt.line(x,60,x,220,DarkGrey); + //x=50+38*6; + //tt.line(x,60,x,220,DarkGrey); tt.set_font((unsigned char*) SCProSB31x55); tt.foreground(Green); if (showMiles){ - tt.locate(160,10); + tt.locate(160,8); printf("%4.1f \n",mpkWh[dtePeriod]*((float)(gids-5)*.075)); } else { tt.locate(180,10); - printf("%3.1f\n",mpkWh[dtePeriod]); + printf("%3.1f \n",mpkWh[dtePeriod]); } lx=50; ly=mpkWh[0]*20; @@ -820,7 +822,7 @@ tt.fillcircle(lx,leff[0],radius,Navy); tt.fillcircle(lx,ly,radius,color); - for(i=1;i<39;i++){ + for(i=1;i<33;i++){ x=50+i*6; y=mpkWh[i]*20; if(y<200) { @@ -848,6 +850,38 @@ leff[i-1]=y; updateDTE=false; } + + 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); + if ((targetBraking>50)&&(regenBraking>50)){ + temp = targetBraking; + temp *= 1000; + temp /= regenBraking; + if (temp<tarDivReg) tarDivReg=temp; + } + if (targetBraking>maxTarget) maxTarget=targetBraking; + if (regenBraking>maxRegen) maxRegen=regenBraking; + + temp = targetBraking; + temp *=200; + temp /= maxTarget; + t = (char) temp; + if (t>175) t=175; + temp = regenBraking; + temp *= tarDivReg; + temp /= maxTarget; + temp /= 5; + r = (char) temp; + if (r>175) r=175; + if (r>t) t=r; //Should never happen + if(lr!=r||lt!=t){ + tt.fillrect(264,64,310,239-t,Navy); + tt.fillrect(264,239-t,310,239-r,Red); + tt.fillrect(264,239-r,310,239,Green); + } + lt=t; + lr=r; } void updateDisplay(char display){ @@ -911,8 +945,7 @@ tt.set_font((unsigned char*) Arial12x12); showButton(0,tNavRow," <-Prev","",4,4); // gg - 4x4 - showButton(3,tNavRow," Next->","",4,4); // gg - move next - + showButton(3,tNavRow," Next->","",4,4); // gg - move next showButton(2,tNavRow," Go To"," Main",4,4); // gg - index switch (dMode[display]) { @@ -1012,6 +1045,8 @@ tt.fillrect(x1,y1,x2,y2,White); // DarkCyan); else tt.fillrect(x1,y1,x2,y2,Green); // DarkCyan); + } else { + tt.fillrect(x1,y1,x2,y2,Green); // DarkCyan); } // paint the outer pixel as a yellow frame