Dual CANbus monitor and instrumentation cluster
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed
Fork of CANary by
Diff: displayModes.cpp
- Revision:
- 37:fea2c1d52c5f
- Parent:
- 36:dbd39c315258
- Child:
- 38:155ec32c5e91
diff -r dbd39c315258 -r fea2c1d52c5f displayModes.cpp --- a/displayModes.cpp Sat Mar 23 04:43:45 2013 +0000 +++ b/displayModes.cpp Sun Mar 24 15:35:45 2013 +0000 @@ -1,6 +1,6 @@ //displayModes.cpp +#include "displayModes.h" -#include "displayModes.h" char sTemp1[40]; char sTemp2[16]; @@ -104,7 +104,7 @@ tt.foreground(Yellow); tt.set_font((unsigned char*) Arial28x28); tt.locate(200,200); - printf("%4.1fV\n",(float)packV/2); + printf("%4.1fV \n",(float)packV/2); lpackV=packV; } if(force||tick){ @@ -112,6 +112,8 @@ tt.set_font((unsigned char*) Arial28x28); tt.locate(20,200); printf("%4.2fV \n",accV); + tt.locate(170,40); + printf("%4.3fkW \n",mpkWh); //kW for now } } @@ -121,9 +123,19 @@ unsigned long temp; static unsigned char lastPressure[4] = {200,200,200,200}; unsigned char i,r,t; - static unsigned char lr, lt; + static unsigned char lr=0, lt=0; + signed short steering; + unsigned short s; + static unsigned short ls; + unsigned char throttle; + static unsigned char lthrottle; CANMessage msg; + msg = lastMsg[indexLastMsg[0x180]]; //Get Throttle position + throttle = msg.data[5]; + msg = lastMsg[indexLastMsg[0x002]]; //Get Steering angle + steering = (msg.data[1]<<8)+msg.data[0]; + s= (unsigned short) ((steering/10)+160)%310; 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); @@ -149,6 +161,26 @@ lastPressure[2] = 200; lastPressure[3] = 200; } + + if (s!=ls){ + tt.fillrect(ls,5,ls+9,14, Navy); + tt.fillrect(s,5,s+9,14, White); + //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){ + tt.fillrect(280,239-lthrottle,310,239-throttle,Navy); + }else{ + tt.fillrect(280,239-throttle,310,239,Yellow); + } + lthrottle=throttle; + } + // plot bar graph for each wheel pressure for (i=0; i<4; i++){ if (msg.data[i]<239) { @@ -188,9 +220,9 @@ } 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); + 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; @@ -370,6 +402,29 @@ } } +void test(bool force){ + unsigned char left,right; + CANMessage msg; + static unsigned char lleft=0; + + msg = lastMsg[indexLastMsg[0x284]]; + right = msg.data[7]; + msg = lastMsg[indexLastMsg[0x280]]; + left = msg.data[6]; + + tt.background(Navy); + if(force) tt.cls(); + if(force||left!=lleft){ + tt.foreground(Yellow); + tt.set_font((unsigned char*) Arial28x28); + tt.locate(10,200); + printf("%d \n",left); + tt.locate(200,200); + printf("%d \n",right); + lleft=left; + } +} + void updateDisplay(char display){ bool changed; changed = dMode[display]!=lastDMode[display]; @@ -384,9 +439,9 @@ case brakeScreen: braking(changed); break; - case powerScreen: - //braking(changed, true); - //break; + case testScreen: + test(changed); + break; case monitorScreen: printLast(changed); break;