test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Diff: displayModes.cpp
- Revision:
- 28:f24ac05645d9
- Parent:
- 27:6bd073c33977
- Child:
- 33:a277743ebdeb
diff -r 6bd073c33977 -r f24ac05645d9 displayModes.cpp --- a/displayModes.cpp Sat Mar 16 02:47:26 2013 +0000 +++ b/displayModes.cpp Sat Mar 16 03:09:37 2013 +0000 @@ -111,6 +111,87 @@ } void braking (bool force, bool prdata=false){ + unsigned long targetBraking, regenBraking; + static unsigned long maxTarget = 1000, maxRegen = 1000, tarDivReg = 1000; + unsigned long temp; + static unsigned char lastPressure[4] = {200,200,200,200}; + unsigned char i,r,t; + static unsigned char lr, lt; + CANMessage msg; + + 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; + + msg = lastMsg[indexLastMsg[0x1ca]]; //Get brake pressure + tt.background(Navy); + if (force) { + tt.cls(); + tt.rect(0,111,170,239,White); + tt.line(0,207,170,207,White); + tt.line(0,175,170,175,White); + tt.line(0,143,170,143,White); + lastPressure[0] = 200; + lastPressure[1] = 200; + lastPressure[2] = 200; + lastPressure[3] = 200; + } + // plot bar graph for each wheel pressure + for (i=0; i<4; i++){ + if (msg.data[i]<239) { + if (msg.data[i]>lastPressure[i]){ + tt.fillrect(10+40*i,239-msg.data[i],40+40*i,239,Red); + } else if (msg.data[i]<lastPressure[i]) { + tt.fillrect(10+40*i,238-lastPressure[i],40+40*i,238-msg.data[i],Navy); + } + lastPressure[i]=msg.data[i]; + } + } + + temp = targetBraking; + temp *=200; + temp /= maxTarget; + t = (char) temp; + if (t>200) t=200; + temp = regenBraking; + temp *= tarDivReg; + temp /= maxTarget; + temp /= 5; + r = (char) temp; + if (r>200) r=200; + if(lr!=r&&prdata){ + tt.foreground(Yellow); + tt.set_font((unsigned char*) Arial28x28); + tt.locate(100,40); + printf("%d %d \n",regenBraking,maxRegen); + tt.locate(100,70); + printf("%3.1f (%3.1f%s) \n",(float)tarDivReg/10,(float)regenBraking*tarDivReg/targetBraking/10,"%"); + } + if(lt!=t&&prdata){ + tt.foreground(Yellow); + tt.set_font((unsigned char*) Arial28x28); + tt.locate(100,10); + printf("%d %d \n",targetBraking,maxTarget); + } + if (r>t) t=r; //Should never happen + if((lr!=r||lt!=t)&&!prdata){ + tt.fillrect(200,10,300,239-t,Navy); + tt.fillrect(200,239-t,300,239-r,Red); + tt.fillrect(200,239-r,300,239,Green); + } + lt=t; + lr=r; +} + +/*void braking (bool force, bool prdata=false){ unsigned long targetBraking, regenBraking, speed; static unsigned long maxTarget = 20000, maxRegen = 20000, tarDivReg = 1000; short rpm; @@ -200,7 +281,7 @@ } lt=t; lr=r; -} +}*/ void cpData(bool force){ short unsigned max, min, jv, i, bd;