Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Diff: displayModes.cpp
- Revision:
- 73:62ee8eae3a84
- Parent:
- 72:f9a6faa28873
- Child:
- 79:68f0dd8d1f19
- Child:
- 83:52b1f330a62d
--- a/displayModes.cpp Sun Apr 14 22:00:51 2013 +0000 +++ b/displayModes.cpp Mon Apr 15 03:46:03 2013 +0000 @@ -72,7 +72,7 @@ void mainDisplay (bool force, bool showButtons){ unsigned short gids, SOC, packV; - static unsigned short lgids=0, lSOC=0, lpackV=0; + static unsigned short lgids=0, lSOC=0, lpackV=0, maxPS; static float lkW=0, laccV=0, lmpkWh=0; CANMessage msg; @@ -91,6 +91,11 @@ if(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh){ tt.locate(10,10); printf("%4d gids \n",gids); + if(debugMode){ + if(pointerSep>maxPS){maxPS=pointerSep;} + tt.locate(10,70); + printf("%3d sep %3d max\n",pointerSep,maxPS); + } tt.locate(10,40); printf("%4.1f kWh \n",(float)(gids-5)*0.075); tt.set_font((unsigned char*) SCProSB31x55); @@ -169,7 +174,7 @@ void braking (bool force, bool showButtons, bool prdata=false){ unsigned long targetBraking, regenBraking; - static unsigned long maxTarget = 1000, maxRegen = 1000, tarDivReg = 1000; + static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000; unsigned long temp; static unsigned char lastPressure[4] = {200,200,200,200}; unsigned char i,r,t; @@ -201,18 +206,6 @@ } //-------------- - 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) { @@ -270,39 +263,53 @@ } } - 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); + 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<2045){ + if ((targetBraking>50)&&(regenBraking>50)){ + temp = targetBraking; + temp *= 1000; + temp /= regenBraking; + if (temp<tardivreg_x1000) tardivreg_x1000=temp; + } + if (targetBraking>maxTarget) maxTarget=targetBraking; + if (regenBraking>maxRegen) maxRegen=regenBraking; + temp = targetBraking; + temp *=200; + temp /= maxTarget; + t = (char) temp; + if (t>200) t=200; + temp = regenBraking; + temp *= tardivreg_x1000; + temp /= maxTarget; + temp /= 5; // 1000/200=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_x1000/10,(float)regenBraking*tardivreg_x1000/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(190,10,260,239-t,Navy); + tt.fillrect(190,239-t,260,239-r,Red); + tt.fillrect(190,239-r,260,239,Green); + } + lt=t; + lr=r; } - if (r>t) t=r; //Should never happen - if((lr!=r||lt!=t)&&!prdata){ - tt.fillrect(190,10,260,239-t,Navy); - tt.fillrect(190,239-t,260,239-r,Red); - tt.fillrect(190,239-r,260,239,Green); - } - lt=t; - lr=r; } void cpData(bool force, bool showButtons){ @@ -765,7 +772,7 @@ static unsigned char leff[39]={0}; CANMessage msg; unsigned long targetBraking, regenBraking, temp; - static unsigned long maxTarget = 1000, maxRegen = 1000, tarDivReg = 1000; + static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000; static unsigned char lr=0, lt=0; msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids @@ -898,34 +905,37 @@ 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)){ + + if (targetBraking<2045){ + if ((targetBraking>50)&&(regenBraking>50)){ + temp = targetBraking; + temp *= 1000; + temp /= regenBraking; + if (temp<tardivreg_x1000) tardivreg_x1000=temp; + } + if (targetBraking>maxTarget) maxTarget=targetBraking; + if (regenBraking>maxRegen) maxRegen=regenBraking; + temp = targetBraking; - temp *= 1000; - temp /= regenBraking; - if (temp<tarDivReg) tarDivReg=temp; + temp *=200; + temp /= maxTarget; + t = (char) temp; + if (t>175) t=175; + temp = regenBraking; + temp *= tardivreg_x1000; + temp /= maxTarget; + temp /= 5; // 1000/200=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; } - 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){ @@ -1128,7 +1138,7 @@ // changed to force since power had too large a dynamic range /*void braking (bool force, bool showButtons, bool prdata=false){ unsigned long targetBraking, regenBraking, speed; - static unsigned long maxTarget = 20000, maxRegen = 20000, tarDivReg = 1000; + static unsigned long maxTarget = 20000, maxRegen = 20000, tardivreg_x1000 = 1000; short rpm; unsigned long temp; static unsigned char lastPressure[4] = {200,200,200,200}; @@ -1150,7 +1160,7 @@ temp = targetBraking; temp *= 1000; temp /= regenBraking; - if (temp<tarDivReg) tarDivReg=temp; + if (temp<tardivreg_x1000) tardivreg_x1000=temp; } targetBraking *= speed; regenBraking *= speed; @@ -1189,7 +1199,7 @@ t = (char) temp; if (t>200) t=200; temp = regenBraking; - temp *= tarDivReg; + temp *= tardivreg_x1000; temp /= maxTarget; temp /= 5; r = (char) temp; @@ -1200,7 +1210,7 @@ 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,"%"); + printf("%3.1f (%3.1f%s) \n",(float)tardivreg_x1000/10,(float)regenBraking*tardivreg_x1000/targetBraking/10,"%"); } if(lt!=t&&prdata){ tt.foreground(Yellow);