test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Diff: displayModes.cpp
- Branch:
- Metric
- Revision:
- 118:02010b18efdc
- Parent:
- 113:f388b4505463
- Child:
- 119:0e2b641e98a2
--- a/displayModes.cpp Thu Jul 04 18:01:52 2013 +0000 +++ b/displayModes.cpp Fri Jul 05 15:38:40 2013 +0000 @@ -4,97 +4,6 @@ char sTemp1[40]; char sTemp2[16]; -void printLast (bool force, bool showButtons){ - CANMessage msg; - tt.locate(0,6); - tt.foreground(Red); - tt.background(Yellow); - if(force) tt.cls(); // Just clear screen if forced - always update display - tt.set_font((unsigned char*) Arial12x12_prop); // select the font - for(int i=0; i<19; i++){ - msg = lastMsg[i+indexOffset]; - printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]); - } - if((sMode==1)&&showButtons){ - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - - showButton(0,0," <up>","",4,4); - showButton(2,0,"<down>","",4,4); - } -} - -void printChanged (bool force, bool showButtons){ - CANMessage msg; - unsigned char i,j; - tt.locate(0,6); - tt.foreground(Red); - tt.background(Yellow); - if(force) tt.cls(); // Just clear screen if forced - always update display - tt.set_font((unsigned char*) Arial12x12_prop); // select the font - i=0; - j=indexOffset; - do{ - j=j<99?j+1:j; - if(msgChanged[j]>0){ - msg = lastMsg[j]; - printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]); - i++; - }// if changed - }while(i<19&&j<99); - if((sMode==1)&&showButtons){ - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - - showButton(0,0," <up>","",4,4); - showButton(2,0," <down>","",4,4); - showButton(1,0," Reset","Baseline",4,4); - } -} - -void printLog (bool force, bool showButtons){ - 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[ldl]); - ldl=ldl>17?0:ldl+1; - } - } - lastldl=ldl; -} - -void tripDisplay (bool force, bool showButtons){ - static float lkWh=0; - tt.background(White); - if(force){ - tt.cls(); - } - if(force||(int)(lkWh*100)!=(int)(kWh_trip[0]*100)){ //only update if changed - tt.foreground(Navy); - tt.set_font((unsigned char*) Arial28x28); - tt.locate(6,210); - printf("kWh : %s : Eff\n",distanceUnit()); - for(int i=0; i<3; i++){ - tt.locate(6,20+i*60); - printf("%3.2f : %3.1f : %2.1f\n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]); - } - tt.set_font((unsigned char*) Arial12x12); - tt.background(DarkCyan); - tt.foreground(Yellow); - showButton(3,1," Reset"," A",4,4); - showButton(3,2," Reset"," B",4,4); - lkWh=kWh_trip[0]; - } -} - void mainDisplay (bool force, bool showButtons){ unsigned short gids, SOC, packV; static unsigned short lgids=0, lSOC=0, lSOH=0, lpackV=0, maxPS=0; @@ -110,6 +19,7 @@ msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts packV = (msg.data[2]<<2)+(msg.data[3]>>6); + tt.background(Navy); tt.foreground(Yellow); tt.set_font((unsigned char*) Arial28x28); @@ -219,6 +129,149 @@ } } +void printLast (bool force, bool showButtons){ + CANMessage msg; + tt.locate(0,6); + tt.foreground(Red); + tt.background(Yellow); + if(force) tt.cls(); // Just clear screen if forced - always update display + tt.set_font((unsigned char*) Arial12x12_prop); // select the font + for(int i=0; i<19; i++){ + msg = lastMsg[i+indexOffset]; + printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]); + } + if((sMode==1)&&showButtons){ + tt.foreground(Yellow); + tt.background(DarkCyan); + tt.set_font((unsigned char*) Arial12x12); + + showButton(0,0," <up>","",4,4); + showButton(2,0,"<down>","",4,4); + } +} + +void printChanged (bool force, bool showButtons){ + CANMessage msg; + unsigned char i,j; + tt.locate(0,6); + tt.foreground(Red); + tt.background(Yellow); + if(force) tt.cls(); // Just clear screen if forced - always update display + tt.set_font((unsigned char*) Arial12x12_prop); // select the font + i=0; + j=indexOffset; + do{ + j=j<99?j+1:j; + if(msgChanged[j]>0){ + msg = lastMsg[j]; + printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]); + i++; + }// if changed + }while(i<19&&j<99); + if((sMode==1)&&showButtons){ + tt.foreground(Yellow); + tt.background(DarkCyan); + tt.set_font((unsigned char*) Arial12x12); + + showButton(0,0," <up>","",4,4); + showButton(2,0," <down>","",4,4); + showButton(1,0," Reset","Baseline",4,4); + } +} + +void printLog (bool force, bool showButtons){ + 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[ldl]); + ldl=ldl>17?0:ldl+1; + } + } + lastldl=ldl; +} + +void tripDisplay (bool force, bool showButtons){ + static float lkWh=0; + tt.background(White); + if(force){ + tt.cls(); + } + if(force||(int)(lkWh*100)!=(int)(kWh_trip[0]*100)){ //only update if changed + tt.foreground(Navy); + tt.set_font((unsigned char*) Arial28x28); + tt.locate(6,210); + printf("kWh : %s : Eff\n",distanceUnit()); + for(int i=0; i<3; i++){ + tt.locate(6,20+i*60); + printf("%3.2f : %3.1f : %2.1f\n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]); + } + tt.set_font((unsigned char*) Arial12x12); + tt.background(DarkCyan); + tt.foreground(Yellow); + showButton(3,1," Reset"," A",4,4); + showButton(3,2," Reset"," B",4,4); + lkWh=kWh_trip[0]; + } +} + +void healthDisplay (bool force, bool showButtons){ + unsigned short gids, SOC; + static unsigned short lgids=0, lSOC=0, lSOH=0; + static float lmaxTemp=0, lresr=0, lunlV=0; + static unsigned long lAh=0; + CANMessage msg; + + msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids + gids = (msg.data[0]<<2)+(msg.data[1]>>6); + msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC + SOC = (msg.data[0]<<2)+(msg.data[1]>>6); + + tt.background(Blue); + tt.foreground(Yellow); + tt.set_font((unsigned char*) Arial28x28); + if(force) tt.cls(); + if(force||gids!=lgids){ + tt.locate(10,10); + printf("%4d gids \n",gids); + } + if(force||SOC!=lSOC){ + tt.locate(0,40); + printf("%4.1f%s\n",(float)SOC/10,"% SOC"); + lSOC=SOC; + } + if(force||SOH_x100!=lSOH){ + tt.locate(10,70); + printf(" %3.1f%s\n",(float)SOH_x100/100,"% SOH"); + lSOH=SOH_x100; + } + if(force||Ah_x10000!=lAh){ + tt.locate(10,100); + printf("% 4.2fAh \n",(float)Ah_x10000/10000); + lAh=Ah_x10000; + } + if(force||maxTemp!=lmaxTemp){ + tt.locate(10,130); + printf("%4.1f%s max\n",convertTemperature(maxTemp),temperatureUnit()); + lmaxTemp=maxTemp; + } + if(force||unloadedV!=lunlV){ + tt.locate(10,160); + printf("%4.1fV (unloaded)\n",unloadedV); + lunlV=unloadedV; + } + if(force||Resr!=lresr){ + tt.locate(10,190); + printf("%4.1fmOhms ESR\n",Resr); + lresr=Resr; + } +} + void braking (bool force, bool showButtons, bool prdata=false){ unsigned long targetBraking, regenBraking; static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000; @@ -1114,6 +1167,9 @@ case tripScreen: tripDisplay(changed,(display==whichTouched)); break; + case healthScreen: + healthDisplay(changed,(display==whichTouched)); + break; default: if (changed){ tt.background(Black); @@ -1182,6 +1238,9 @@ case tripScreen: sprintf(sTemp2," Trip"); break; + case healthScreen: + sprintf(sTemp2,"Health"); + break; case indexScreen: // gg - index sprintf(sTemp2," Index"); break; @@ -1296,102 +1355,3 @@ return "C"; return "F"; } - -//------------- -// below is braking screen normalized to power rather than force -// 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_x1000 = 1000; - short rpm; - 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); - msg = lastMsg[indexLastMsg[0x421]]; //Get Drive Mode - if (msg.data[0]==0x18) { // In Neutral - regenBraking = 0; // No regen when in Neutral - } - msg = lastMsg[indexLastMsg[0x176]]; //Get rpms - not sure what this is but scales to mph with .0725 - rpm = ((short)msg.data[0]<<8)+msg.data[1]; - speed =rpm>0?rpm>>3:-rpm>>3; //Take absolute to get speed; div8 - if ((targetBraking>2039)||(speed>200)) { //Filter weird messages - targetBraking = 0; - regenBraking = 0; - } else { - if ((targetBraking>50)&&(regenBraking>50)){ - temp = targetBraking; - temp *= 1000; - temp /= regenBraking; - if (temp<tardivreg_x1000) tardivreg_x1000=temp; - } - targetBraking *= speed; - regenBraking *= speed; - 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_x1000; - 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_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(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; -}*/ \ No newline at end of file