Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Revision 119:0e2b641e98a2, committed 2013-07-05
- Comitter:
- TickTock
- Date:
- Fri Jul 05 16:55:04 2013 +0000
- Branch:
- Metric
- Parent:
- 118:02010b18efdc
- Child:
- 120:041edeec08f5
- Commit message:
- fixed bugs in health screen
Changed in this revision
--- a/displayModes.cpp Fri Jul 05 15:38:40 2013 +0000 +++ b/displayModes.cpp Fri Jul 05 16:55:04 2013 +0000 @@ -5,8 +5,8 @@ char sTemp2[16]; void mainDisplay (bool force, bool showButtons){ - unsigned short gids, SOC, packV; - static unsigned short lgids=0, lSOC=0, lSOH=0, lpackV=0, maxPS=0; + unsigned short gids, SOC, packV_x2; + static unsigned short lgids=0, lSOC=0, lSOH=0, lpackV_x2=0, maxPS=0; static float lmaxTemp=0; static float lkW=0, laccV=0, lmpkWh=0; static unsigned long lAh=0; @@ -17,7 +17,7 @@ msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC SOC = (msg.data[0]<<2)+(msg.data[1]>>6); msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts - packV = (msg.data[2]<<2)+(msg.data[3]>>6); + packV_x2 = (msg.data[2]<<2)+(msg.data[3]>>6); tt.background(Navy); @@ -49,10 +49,10 @@ printf("%4.1f%s\n",(float)SOC/10,"% "); lSOC=SOC; } - if(force||packV!=lpackV){ + if(force||packV_x2!=lpackV_x2){ tt.locate(200,200); - printf("%4.1fV \n",(float)packV/2); - lpackV=packV; + printf("%4.1fV \n",(float)packV_x2/2); + lpackV_x2=packV_x2; } if(force||maxTemp!=lmaxTemp){ tt.locate(200,170); @@ -106,10 +106,10 @@ printf("%4.1f%s\n",(float)SOC/10,"% "); lSOC=SOC; } - if(force||packV!=lpackV){ + if(force||packV_x2!=lpackV_x2){ tt.locate(200,200); - printf("%4.1fV \n",(float)packV/2); - lpackV=packV; + printf("%4.1fV \n",(float)packV_x2/2); + lpackV_x2=packV_x2; } if(force||accV!=laccV){ tt.locate(20,200); @@ -239,35 +239,36 @@ if(force||gids!=lgids){ tt.locate(10,10); printf("%4d gids \n",gids); + lgids=gids; } if(force||SOC!=lSOC){ - tt.locate(0,40); - printf("%4.1f%s\n",(float)SOC/10,"% SOC"); + tt.locate(10,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"); + printf(" %4.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); + 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()); + printf(" %4.1f%s max temp \n",convertTemperature(maxTemp),temperatureUnit()); lmaxTemp=maxTemp; } - if(force||unloadedV!=lunlV){ + if(force||unloadedV_x2!=lunlV){ tt.locate(10,160); - printf("%4.1fV (unloaded)\n",unloadedV); - lunlV=unloadedV; + printf(" %4.1fV \n",unloadedV_x2/2); + lunlV=unloadedV_x2; } if(force||Resr!=lresr){ tt.locate(10,190); - printf("%4.1fmOhms ESR\n",Resr); + printf(" %4.1fmOhms ESR \n",Resr*1000); lresr=Resr; } }
--- a/displayModes.h Fri Jul 05 15:38:40 2013 +0000 +++ b/displayModes.h Fri Jul 05 16:55:04 2013 +0000 @@ -52,7 +52,7 @@ extern unsigned char tNavRow ; // gg - 4x4 extern char revStr[7]; // gg - version extern bool debugMode; -extern float unloadedV; +extern float unloadedV_x2; extern float Resr; extern "C" {
--- a/main.cpp Fri Jul 05 15:38:40 2013 +0000 +++ b/main.cpp Fri Jul 05 16:55:04 2013 +0000 @@ -23,13 +23,14 @@ #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "118"; // gg - revision string, max 6 characters +char revStr[7] = "119"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); bool waitasec = true; unsigned char wait5secs = 5; // to write to USB Flash Drives, or equivalent (SD card in Reader/Writer) +// class10 SDcard in Reader/Writer recommended FRESULT mfr = f_mount(0,&USBdrive); time_t seconds ; @@ -122,7 +123,7 @@ float mph[39]={0}; float kW[39]={0}; float mpkWh[39]={0}; -float unloadedVavg,unloadedV,Resr,Rlms,redRlms,incRlms; +float unloadedVavg_x2,unloadedV_x2,Resr,Rlms,redRlms,incRlms; // Logarithmic division scale (roughly - snapped to common units of time) float timeConstant[39] = {1, 1.58, 2.51, 3.98, 6.31, 10, 15.8, 25.1, 39.8, 60, // 1 minute 60*1.58, 60*2.51, 60*3.98, 60*6.31, 60*10, 60*15.8, 60*25.1, 60*39.8, 60*60, // 1 hour @@ -724,7 +725,7 @@ if (mpkWh[0]<0) { mpkWh[0]=99;// negative means inf. } - unloadedV = unloadedVavg/numWsamples; + unloadedV_x2 = unloadedVavg_x2/numWsamples; //Rlms /= numWsamples; //unecessary //redRlms /= numWsamples; //incRlms /= numWsamples; @@ -736,10 +737,6 @@ } else { kW[0]=0; mpkWh[0]=0; - unloadedVavg=0; - Rlms=0; - redRlms=0; - incRlms=0; } kWh_trip[0]+=kW[0]/3600; kWh_trip[1]+=kW[0]/3600; @@ -747,6 +744,10 @@ motorRPM=0; numSsamples=0; mWs_x4=0; + unloadedVavg_x2=0; + Rlms=0; + redRlms=0; + incRlms=0; numWsamples=0; if(accOn||playbackEn){ for(i=1;i<39;i++){
--- a/utility.cpp Fri Jul 05 15:38:40 2013 +0000 +++ b/utility.cpp Fri Jul 05 16:55:04 2013 +0000 @@ -50,8 +50,8 @@ char sTemp[40]; unsigned char changed; unsigned short i,j,k; - signed short packV; - signed short packA; + signed short packV_x2; + signed short packA_x2; signed long imWs_x4; unsigned short ts; @@ -289,19 +289,19 @@ } } }else if((mType==1)&&(canRXmsg.id==0x1db)){ //Battery Volts and Amps - packV=((canRXmsg.data[2]<<2)|(canRXmsg.data[3]>>6)); // 1 LSB = 0.5V - packA=((canRXmsg.data[0]<<3)|(canRXmsg.data[1]>>5)); // 1 LSB = 0.5A - if(packA>0x03ff){ - packA|=0xf800;//extend sign; + packV_x2=((canRXmsg.data[2]<<2)|(canRXmsg.data[3]>>6)); // 1 LSB = 0.5V + packA_x2=((canRXmsg.data[0]<<3)|(canRXmsg.data[1]>>5)); // 1 LSB = 0.5A + if(packA_x2>0x03ff){ + packA_x2|=0xf800;//extend sign; } - packA -= 1; //Slight correction to value required (unique to my Leaf?) - imWs_x4 = packV; // Volts*milliSeconds*2 - imWs_x4 *= -packA; // milliWattseconds*4 + packA_x2 -= 1; //Slight correction to value required (unique to my Leaf?) + imWs_x4 = packV_x2; // Volts*milliSeconds*2 + imWs_x4 *= -packA_x2; // milliWattseconds*4 mWs_x4 += imWs_x4; // total mWs_x4 - unloadedVavg += packV-Resr*packA; - Rlms += (packV-Resr*packA-unloadedV)*(packV-Resr*packA-unloadedV); - redRlms += (packV-(Resr-0.001)*packA-unloadedV)*(packV-(Resr-0.001)*packA-unloadedV); - incRlms += (packV-(Resr+0.001)*packA-unloadedV)*(packV-(Resr+0.001)*packA-unloadedV); + unloadedVavg_x2 += packV_x2-Resr*packA_x2; + Rlms += (packV_x2-Resr*packA_x2-unloadedV_x2)*(packV_x2-Resr*packA_x2-unloadedV_x2); + redRlms += (packV_x2-(Resr-0.001)*packA_x2-unloadedV_x2)*(packV_x2-(Resr-0.001)*packA_x2-unloadedV_x2); + incRlms += (packV_x2-(Resr+0.001)*packA_x2-unloadedV_x2)*(packV_x2-(Resr+0.001)*packA_x2-unloadedV_x2); numWsamples++; }else if((mType==1)&&(canRXmsg.id==0x1da)){ //Motor Speed imotorRPM=((canRXmsg.data[4]<<8)|(canRXmsg.data[5])); @@ -596,8 +596,8 @@ struct tm t; // pointer to a static tm structure short unsigned max, min, jv, i, bd; unsigned avg; - unsigned short gids, SOC, packV; - signed short packA; + unsigned short gids, SOC, packV_x2; + signed short packA_x2; time_t seconds ; CANMessage msg; @@ -610,9 +610,9 @@ msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC SOC = (msg.data[0]<<2)+(msg.data[1]>>6); msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts - packV = (msg.data[2]<<2)+(msg.data[3]>>6); - packA = (msg.data[0]<<3)+(msg.data[1]>>5); - if (packA & 0x400) packA |= 0xf800; + packV_x2 = (msg.data[2]<<2)+(msg.data[3]>>6); + packA_x2 = (msg.data[0]<<3)+(msg.data[1]>>5); + if (packA_x2 & 0x400) packA_x2 |= 0xf800; max=0; min=9999; @@ -637,7 +637,7 @@ f_lseek(&bfile,0xffffffff); // go to end of file to append strftime(sTemp, 40, "%a %m/%d/%Y %X", &t); f_printf(&bfile,"%s,",sTemp); - sprintf(sTemp,"%d,%5.1f%%,%5.1f,%5.1f,%d,%d,%d,%d,%d",gids,(float)SOC/10,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv); + sprintf(sTemp,"%d,%5.1f%%,%5.1f,%5.1f,%d,%d,%d,%d,%d",gids,(float)SOC/10,(float)packV_x2/2,(float)packA_x2/2,max,min,avg,max-min,jv); f_printf(&bfile,"%s,",sTemp); f_printf(&bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]); f_printf(&bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]); @@ -657,8 +657,8 @@ struct tm t; // pointer to a static tm structure short unsigned max, min, jv, i, bd; unsigned avg; - unsigned short gids, SOC, packV; - signed short packA; + unsigned short gids, SOC, packV_x2; + signed short packA_x2; time_t seconds ; CANMessage msg; @@ -671,9 +671,9 @@ msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC SOC = (msg.data[0]<<2)+(msg.data[1]>>6); msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts - packV = (msg.data[2]<<2)+(msg.data[3]>>6); - packA = (msg.data[0]<<3)+(msg.data[1]>>5); - if (packA & 0x400) packA |= 0xf800; + packV_x2 = (msg.data[2]<<2)+(msg.data[3]>>6); + packA_x2 = (msg.data[0]<<3)+(msg.data[1]>>5); + if (packA_x2 & 0x400) packA_x2 |= 0xf800; max=0; min=9999; @@ -698,7 +698,7 @@ f_lseek(&bfile,0xffffffff); // go to end of file to append strftime(sTemp, 40, "%a %m/%d/%Y %X", &t); f_printf(&bfile,"%s,",sTemp); - sprintf(sTemp,"%d,%5.1f%%,%5.1f%%, %4.2f, %5.1f,%4.1f,%d,%d,%d,%d,%d",gids,(float)SOC/10, (float)SOH_x100/100,(float)Ah_x10000/10000,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv); + sprintf(sTemp,"%d,%5.1f%%,%5.1f%%, %4.2f, %5.1f,%4.1f,%d,%d,%d,%d,%d",gids,(float)SOC/10, (float)SOH_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,max,min,avg,max-min,jv); f_printf(&bfile,"%s,",sTemp); f_printf(&bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]); f_printf(&bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]);
--- a/utility.h Fri Jul 05 15:38:40 2013 +0000 +++ b/utility.h Fri Jul 05 16:55:04 2013 +0000 @@ -63,7 +63,7 @@ extern bool metric; extern unsigned char lastDMode[2]; extern unsigned char whichTouched; -extern float unloadedVavg,unloadedV,Resr,Rlms,redRlms,incRlms; +extern float unloadedVavg_x2,unloadedV_x2,Resr,Rlms,redRlms,incRlms; extern unsigned char tNavRow ; // gg - 4x4 extern char revStr[7]; // gg - version extern bool debugMode;