Dual CANbus monitor and instrumentation cluster
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed
Fork of CANary by
Revision 40:0e6e71a7323f, committed 2013-03-31
- Comitter:
- TickTock
- Date:
- Sun Mar 31 17:45:05 2013 +0000
- Parent:
- 39:eef8beac7411
- Child:
- 41:8d4609ea7259
- Commit message:
- eliminated flicker on 12V display;
Changed in this revision
--- a/displayModes.cpp Mon Mar 25 15:13:15 2013 +0000 +++ b/displayModes.cpp Sun Mar 31 17:45:05 2013 +0000 @@ -22,9 +22,6 @@ sprintf(sTemp1,"<up>"); sprintf(sTemp2,""); showButton(0,0,sTemp1,sTemp2,3,3); - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); sprintf(sTemp1,"<down>"); showButton(2,0,sTemp1,sTemp2,3,3); } @@ -48,6 +45,18 @@ i++; }// if changed }while(i<19&&j<99); + if(sMode==1){ + tt.foreground(Yellow); + tt.background(DarkCyan); + tt.set_font((unsigned char*) Arial12x12); + sprintf(sTemp1,"<up>"); + sprintf(sTemp2,""); + showButton(0,0,sTemp1,sTemp2,3,3); + sprintf(sTemp1,"Reset"); + showButton(1,0,sTemp1,sTemp2,3,3); + sprintf(sTemp1,"<down>"); + showButton(2,0,sTemp1,sTemp2,3,3); + } } void printLog (bool force){ @@ -108,7 +117,8 @@ } if(force||accV!=laccV){ tt.locate(20,200); - printf("%4.2fV \n",accV); + printf("%3.1fV \n",accV); + laccV=accV; } if(force||mpkWh!=lmpkWh){ tt.locate(180,40); @@ -479,6 +489,7 @@ showButton(1,2,sTemp1,sTemp2,3,3); sprintf(sTemp1," Next->"); showButton(2,2,sTemp1,sTemp2,3,3); + wait_ms(100); // pause a moment to reduce flicker break; case 2: // numpad sprintf(sTemp2,"");
--- a/main.cpp Mon Mar 25 15:13:15 2013 +0000 +++ b/main.cpp Sun Mar 31 17:45:05 2013 +0000 @@ -85,7 +85,8 @@ unsigned short pollInt = 300; // polling interval=5 minutes (until config file read) bool accOn = false; // Accessories on float scale12V = 16.2; // R1:R2 ratio -signed long mWs = 0; +signed long mWs_x4 = 0; +unsigned short numWsamples = 0; unsigned long miles = 0; float mpkWh = 0; float accV = 0; @@ -95,7 +96,6 @@ bool step = false; char header[5]; char data[8]; -//unsigned short pbts; int main() { int readPointer=0; @@ -280,8 +280,12 @@ if(touched){ // call touchscreen procedure if touch interrupt detected lastTouch = tt.get_touch(); lastTouch = tt.to_pixel(lastTouch); // convert to pixel pos - if((lastTouch.x!=639)&&(lastTouch.x!=319)&&(lastTouch.y!=239)){ - secsNoTouch=0; //debounce + if((lastTouch.x!=639)&&(lastTouch.x!=319)&&(lastTouch.y!=239)){ // filter phantom touches + if (!userIdle) { + secsNoTouch=0; + } else { + secsNoTouch=2; // Ignore first touch if user idle + } } //sprintf(sTemp,"%d,%d ",lastTouch.x,lastTouch.y); //logMsg(sTemp); @@ -360,7 +364,7 @@ case 31: if (dMode[i]==config1Screen) { logEn = !logEn; - if (!logEn) repeatPoll=false; + if (!logEn) repeatPoll=false; // disable auto polling, too } else if (dMode[i]==dateScreen){ dtMode=(dtMode<6)?dtMode+1:0; lastDMode[i]=99; @@ -450,24 +454,29 @@ } if(tick){ // Executes once a second - accV=mon12V*scale12V; + accV=floor(mon12V*scale12V*10+0.5)/10; + //accV=mon12V*scale12V; accOn=(accV>5)?true:false; if(!accOn&&!logEn&&userIdle&&!playbackEn){ + //sprintf(sTemp,"Display Off %4.2f\n",accV); + //logMsg(sTemp); dled = 0; // turn off display if car off and logging disabled and no user activity }else if(!headlights){ dled = ledHi; }else{ dled = ledLo; } - //if(mWs>0){ - if(true){ - mpkWh= ((float) mWs)/1e6; // just kW for now + //if(mWs_x4>0){ + if(numWsamples>0){ + mpkWh= ((float) mWs_x4)/numWsamples/4e3; // just kW for now }else{ mpkWh=99; } miles=0; - mWs=0; - if(logCP) logPackVoltages(); // Turbo3 + mWs_x4=0; + numWsamples=0; + if(logCP) + logPackVoltages(); // Turbo3 tick=false; } @@ -478,8 +487,8 @@ sendCPreq(); // send cellpair data request. wait_ms(16); sendTreq(); //send temperature request - wait_ms(16); - showCP=true; + //wait_ms(16); + //showCP=true; pollCP=false; }
--- a/utility.cpp Mon Mar 25 15:13:15 2013 +0000 +++ b/utility.cpp Sun Mar 31 17:45:05 2013 +0000 @@ -42,12 +42,11 @@ static unsigned char ii = 0, lasti = 0; // indexindex unsigned char changed,i; static unsigned char bdi=0; - //Determined 1db messages are 10ms apart so no need to compute deltaT //unsigned short ms; //static unsigned short lms=0; - unsigned short packV; + signed short packV; signed short packA; - signed long imWs; + signed long imWs_x4; secsNoMsg=0; // reset deadman switch if(logOpen){ if(canRXmsg.id>0) { @@ -56,7 +55,7 @@ writeBuffer[writePointer][2]=(ts&0x00ff); writeBuffer[writePointer][3]=canRXmsg.id&0xff; writeBuffer[writePointer][4]=(canRXmsg.id>>8)+(canRXmsg.len<<4); - for(i=5;i<13;i++){ + for(i=5;i<13;i++){ // Is there a better way to do this? (writeBuffer[writePointer][i]=canRXmsg.data?) writeBuffer[writePointer][i]=canRXmsg.data[i-5]; } if (++writePointer >= maxBufLen) { @@ -65,10 +64,7 @@ } } } - //Determined 1db messages are 10ms apart so no need to compute deltaT - /*if(playbackOpen){ - ts=pbts; // Use ts from playback buffer - }//if logOpen*/ + if(indexLastMsg[canRXmsg.id]==0) { //Check if no entry ii=ii<99?ii+1:0; indexLastMsg[canRXmsg.id]=ii; //Create entry if first message @@ -104,8 +100,9 @@ } lasti=i; //remember the msb to detect rollover next time around i+=bdi; + if(i==22) logCP=true; //Turbo3 i*=7; - if(i<0xfa){ + if(i<0xfa){ // Is there a better way to do this? battData[i+0]=canRXmsg.data[1]; battData[i+1]=canRXmsg.data[2]; battData[i+2]=canRXmsg.data[3]; @@ -115,23 +112,19 @@ battData[i+6]=canRXmsg.data[7]; } }else if((mType==1)&&(canRXmsg.id==0x1db)){ //Battery Volts and Amps - //Determined 1db messages are 10ms apart so no need to compute deltaT + //Determined 1db messages are 10ms apart so no need to compute deltaT except to be robust against missed messages //ms=(ts&0xfc00)*1000+(ts&0x03ff); // convert from BCD(ish-ssssss:mmmmmmmmmm) to binary - //if(ms<lms){ // must've rolled over - // imWs=ms+60000; // (ms)compute elapsed time since last update including rollover - // imWs-=lms; - //}else{ - // imWs=ms-lms; // (ms) compute elapsed time since last update - //} + //imWs_x4 = (ms+60000-lms)%60000; 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; } - imWs=packV; // Volts*seconds*2 - imWs*=packA; // Watts*4 - imWs*=-10; // milliwatt*seconds*4 (1db messages are 10ms apart) - mWs+=(imWs>>2); // total mWs + //mWs_x4=-packA*4000; //test + imWs_x4 = packV; // Volts*milliSeconds*2 + imWs_x4 *= -packA; // milliWattseconds*4 + mWs_x4 += imWs_x4; // total mWs_x4 + numWsamples++; //lms=ms; } } @@ -406,5 +399,6 @@ fclose(bfile); } logCP=false; + showCP=true; }
--- a/utility.h Mon Mar 25 15:13:15 2013 +0000 +++ b/utility.h Sun Mar 31 17:45:05 2013 +0000 @@ -15,6 +15,7 @@ extern bool touched; extern bool logOpen; extern bool logCP; // Turbo3 +extern bool showCP; extern char writeBuffer[maxBufLen][13]; extern volatile int writePointer; extern DigitalOut led1,led2,led3,led4; @@ -37,8 +38,8 @@ extern bool playbackOpen; extern bool step; extern float playbackInt; -extern signed long mWs; -extern unsigned short pbts; +extern signed long mWs_x4; +extern unsigned short numWsamples; extern "C" { void mbed_reset();