test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Revision 39:eef8beac7411, committed 2013-03-25
- Comitter:
- TickTock
- Date:
- Mon Mar 25 15:13:15 2013 +0000
- Parent:
- 38:155ec32c5e91
- Child:
- 40:0e6e71a7323f
- Commit message:
- Fixed minor bug using tick to trigger refresh (changed to using change on accV)
Changed in this revision
--- a/displayModes.cpp Sun Mar 24 17:26:09 2013 +0000 +++ b/displayModes.cpp Mon Mar 25 15:13:15 2013 +0000 @@ -69,7 +69,7 @@ void printDTE (bool force){ unsigned short gids, SOC, packV; static unsigned short lgids=0, lSOC=0, lpackV=0; - static float lmpkWh=0; + static float lmpkWh=0, laccV=0;; CANMessage msg; msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids @@ -106,7 +106,7 @@ printf("%4.1fV \n",(float)packV/2); lpackV=packV; } - if(force||tick){ + if(force||accV!=laccV){ tt.locate(20,200); printf("%4.2fV \n",accV); }
--- a/displayModes.h Sun Mar 24 17:26:09 2013 +0000 +++ b/displayModes.h Mon Mar 25 15:13:15 2013 +0000 @@ -25,7 +25,6 @@ extern TOUCH_TFTx2 tt; extern unsigned char dtMode; extern float accV; -extern bool tick; extern bool playbackEn; extern bool playbackOpen; extern float playbackInt;
--- a/main.cpp Sun Mar 24 17:26:09 2013 +0000 +++ b/main.cpp Mon Mar 25 15:13:15 2013 +0000 @@ -1,6 +1,7 @@ // main.cpp //To Do: +// * Use timestamp for mWs but override with playbackInt based calc in playback // * Log file playback (to enable testing of new passive display modes without having to drive around) // * USB device detect // * Ability to update binary from the thumb-drive (requires file timestamp) @@ -75,6 +76,7 @@ unsigned char indexOffset = 1; bool showCP = false; bool pollCP = false; +bool logCP = false; //Turbo3 bool repeatPoll = false; bool headlights = false; bool tick = false; @@ -93,7 +95,7 @@ bool step = false; char header[5]; char data[8]; -unsigned short pbts; +//unsigned short pbts; int main() { int readPointer=0; @@ -446,18 +448,7 @@ lastDMode[1]=99; } } - display=display<1?display+1:0; // toggle display - updateDisplay(display); - if(pollCP){ // We do this inside main loop instead of ticker so CAN RX will not be blocked - sendCPreq(); // send cellpair data request. - wait_ms(16); - sendTreq(); //send temperature request - wait_ms(16); - showCP=true; - pollCP=false; - } - if(tick){ // Executes once a second accV=mon12V*scale12V; accOn=(accV>5)?true:false; @@ -476,9 +467,22 @@ } miles=0; mWs=0; + if(logCP) logPackVoltages(); // Turbo3 tick=false; } + display=display<1?display+1:0; // toggle display + updateDisplay(display); + + if(pollCP){ // We do this inside main loop instead of ticker so CAN RX will not be blocked + sendCPreq(); // send cellpair data request. + wait_ms(16); + sendTreq(); //send temperature request + wait_ms(16); + showCP=true; + pollCP=false; + } + if(step){ // playback if(playbackOpen&&playbackEn){ //sprintf(sTemp,"step\n"); @@ -486,7 +490,7 @@ for(i=0;i<120;i++){ if(!feof(file)){ fscanf(file,"%5c%8c",&header,&data); - pbts=(header[1]<<8)|header[2]; + //pbts=(header[1]<<8)|header[2]; logCan(header[0],CANMessage(0x7ff&((header[4]<<8)+header[3]), data, 8)); }else{ fclose(file); // restart
--- a/utility.cpp Sun Mar 24 17:26:09 2013 +0000 +++ b/utility.cpp Mon Mar 25 15:13:15 2013 +0000 @@ -351,4 +351,60 @@ set_time(mktime(&t)); } +void logPackVoltages() { // Turbo3 - routine to dump CP values to text file + char sTemp[40]; + 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; + time_t seconds ; + + CANMessage msg; + + seconds = time(NULL); // Turbo3 + t = *localtime(&seconds) ; // Turbo3 + + 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); + 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; + + max=0; + min=9999; + avg=0; + for(i=0; i<96; i++) { + bd=(battData[i*2+3]<<8)+battData[i*2+4]; + avg+=bd; + if(bd>max) max=bd; + if(bd<min) min=bd; + } + avg /= 96; + if(min<3713) { + jv=avg-(max-avg)*1.5; + } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement + jv=0; + } + + FILE *bfile; + //bfile = fopen("/local/batvolt.txt", "a"); + bfile = fopen("/usb/batvolt.txt", "a"); + if(bfile!=NULL) { + strftime(sTemp, 40, "%a %m/%d/%Y %X", &t); + fprintf(bfile,"%s,%d,%5.1f%%,%5.1f,%5.1f,%d,%d,%d,%d,%d",sTemp,gids,(float)SOC/10,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv); + fprintf(bfile,"%d,%d,%d,%d,",(battData[224+ 3]<<8)+battData[224+ 4],battData[224+ 5],(battData[224+ 6]<<8)+battData[224+ 7],battData[224+ 8]); + fprintf(bfile,"%d,%d,%d,%d", (battData[224+ 9]<<8)+battData[224+10],battData[224+11],(battData[224+12]<<8)+battData[224+13],battData[224+14]); + for(i=0; i<96; i++) { + bd=(battData[i*2+3]<<8)+battData[i*2+4]; + fprintf(bfile,",%d",bd); + } + fprintf(bfile,"\r\n"); + fclose(bfile); + } + logCP=false; +}
--- a/utility.h Sun Mar 24 17:26:09 2013 +0000 +++ b/utility.h Mon Mar 25 15:13:15 2013 +0000 @@ -14,6 +14,7 @@ extern unsigned char displayLoc; extern bool touched; extern bool logOpen; +extern bool logCP; // Turbo3 extern char writeBuffer[maxBufLen][13]; extern volatile int writePointer; extern DigitalOut led1,led2,led3,led4; @@ -60,6 +61,7 @@ void saveConfig(); void readConfig(); void upDate(unsigned char field, bool updownbar); + void logPackVoltages(); // Turbo3 } //LEAF OBD