Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Revision 174:cd27e80f197d, committed 2014-01-05
- Comitter:
- TickTock
- Date:
- Sun Jan 05 05:02:41 2014 +0000
- Parent:
- 173:9815b1467039
- Child:
- 175:0357b4159b40
- Commit message:
- // Calibrate audible brake monitor. brkMonRate is units Wh; brkMonThr is units Wh/s
Changed in this revision
--- a/displayModes.cpp Sun Dec 29 22:35:09 2013 +0000 +++ b/displayModes.cpp Sun Jan 05 05:02:41 2014 +0000 @@ -1343,8 +1343,8 @@ if(availableRegen>lar){ tt.fillrect(273,238-availableRegen,275,239-lar,White); tt.fillrect(317,238-availableRegen,319,239-lar,White); - if(availableRegen>=24){ - for(i=24;i<=availableRegen;i+=24){ + if(availableRegen>0){ + for(i=0;i<=availableRegen;i+=24){ tt.fillrect(270,238-i,272,239-i,White); } }
--- a/main.cpp Sun Dec 29 22:35:09 2013 +0000 +++ b/main.cpp Sun Jan 05 05:02:41 2014 +0000 @@ -11,8 +11,8 @@ // * Add climate control impact to main max/min dte and new trip display // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes) -// rev173 -// fixed bugs +// rev174 +// Calibrated brake monitor. brkMonRate 378947 --> 1 chirp per 4Wh #include "mbed.h" #include "CAN.h" @@ -23,7 +23,7 @@ #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "173"; +char revStr[7] = "174"; unsigned long maxTarget = 1000; FATFS USBdrive; LocalFileSystem local("local"); @@ -130,7 +130,7 @@ bool step = false; char header[5]; char data[8]; -signed long motorRPM_x2; +signed long motorRPM; unsigned char skin = ttSkin ; unsigned char dtePeriod = 14; //ten minute averaging interval float CCkWh_trip[3]={0}; @@ -921,7 +921,7 @@ // 227 would give more accurate mph for MXV4s@40psi - 11.75" distance from center of tire to pavement // but then efficiency estimation would not track miles driven as read from the odometer so // making CANary have the same error as the Leaf instrumentation - mph[0]=((float) motorRPM_x2)/numSsamples/220; + mph[0]=((float) motorRPM)/numSsamples/110; } else { mph[0]=0; } @@ -978,7 +978,7 @@ CCkWh_trip[1]=0; } - motorRPM_x2=0; + motorRPM=0; mWs_x4=0; // Compute ESR
--- a/utility.cpp Sun Dec 29 22:35:09 2013 +0000 +++ b/utility.cpp Sun Jan 05 05:02:41 2014 +0000 @@ -1,7 +1,7 @@ // utility.cpp #include "utility.h" -unsigned long brkMonRate = 400000; -unsigned short brkMonThr = 4000; +unsigned long brkMonRate = 378947; +unsigned short brkMonThr = 1895; Timeout beepOff; unsigned char bCount = 2; float bFreq[2] = { 1000, 1000 }; @@ -50,7 +50,7 @@ static unsigned char ii = 0; static unsigned char lasti = 0; // indexindex static unsigned char bdi=0; - static signed short imotorRPM_x2 = 0; + static signed short imotorRPM = 0; static unsigned short nLost = 0; // gg - overrun char sTemp[40]; @@ -348,21 +348,25 @@ incRmin=temp; } numWsamples++; - }else if((mType==1)&&(canRXmsg.id==0x1da)){ //Motor Speed - imotorRPM_x2=((canRXmsg.data[4]<<8)|(canRXmsg.data[5])); - if(imotorRPM_x2<0){ // take absolute value - imotorRPM_x2=-imotorRPM_x2; - } - motorRPM_x2+=imotorRPM_x2; + }else if((mType==2)&&(canRXmsg.id==0x176)){ //Motor Speed + imotorRPM=((canRXmsg.data[2]<<8)|(canRXmsg.data[3])); + motorRPM+=imotorRPM; numSsamples++; +// }else if((mType==1)&&(canRXmsg.id==0x1da)){ //Motor Speed +// imotorRPM_x2=((canRXmsg.data[4]<<8)|(canRXmsg.data[5])); +// if(imotorRPM_x2<0){ // take absolute value +// imotorRPM_x2=-imotorRPM_x2; +// } +// motorRPM_x2+=imotorRPM_x2; +// numSsamples++; // }else if((mType==2)&&(canRXmsg.id==0x1ca)){ //Brake Pressure }else if((mType==2)&&(canRXmsg.id==0x292)){ //Brake Pressure if(brakeMon){ if(canRXmsg.data[0]<0xff){ - if((canRXmsg.data[6]*imotorRPM_x2)<brkMonThr){ + if((canRXmsg.data[6]*imotorRPM)<brkMonThr){ // brkMonThr = 3.6/.0019 = 1895 --> squelch threshold 1Wh/sec chirpInt=0; - }else{ - chirpInt=brkMonRate/imotorRPM_x2; + }else{ // imotorRPM*data[6]*.0019=kW; 3.6/kW = seconds until 1Wh; + chirpInt=brkMonRate/imotorRPM; // brkMonRate=3.6/.0019/.02=94736.8 --> 1 chirp per Wh chirpInt/=canRXmsg.data[6]; } } @@ -516,10 +520,17 @@ const int bufSize = 2048; char buffer[bufSize]; char sTemp[16]; + + tt.set_font((unsigned char*) Arial12x12); + tt.background(Blue); + tt.foreground(Yellow); + tt.locate(0,10); + tt.cls(); + printMsg("Saving local config file.\n"); - //wait(2); + printf("Saving local config file.\n"); cfile = fopen("/local/config.txt", "w"); - fprintf(cfile,"format 10\r\n"); + fprintf(cfile,"format 11\r\n"); fprintf(cfile,"x0_off %d\r\n",tt.x0_off); fprintf(cfile,"y0_off %d\r\n",tt.y0_off); fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp); @@ -548,8 +559,8 @@ fprintf(cfile, "firmware %d\r\n", fwCount ); fprintf(cfile,"showHealth %d\r\n",(showHealth?1:0)); fprintf(cfile,"brakeMon %d\r\n",(heaterMon?4:0)+(brakeMon?2:0)+(regenMon?1:0)); - fprintf(cfile,"brkMonRate %d\r\n", brkMonRate ); - fprintf(cfile,"brkMonThr %d\r\n", brkMonThr ); + fprintf(cfile,"brkMonRate %2.1f\r\n", (float) brkMonRate/94737 ); + fprintf(cfile,"brkMonThr %2.1f\r\n", (float) brkMonThr/1895); for(char i=0;i<8;i++){ sprintf(sTemp,"usrMsgId %04x",uMsgId[i]); fprintf(cfile,"%s\r\n", sTemp ); @@ -561,11 +572,10 @@ // Make copy of CONFIG.TXT printMsg("Saving CONFIG.BAK.\n"); - //wait(2); cfile = fopen("/local/CONFIG.TXT", "r"); sfr = f_open(&efile,"CONFIG.BAK",FA_WRITE|FA_CREATE_NEW); if((cfile != NULL)&&(sfr == FR_OK)){ - printMsg("Copy config file to USB\n"); + printf("Copy config file to USB\n"); while (!feof(cfile)) { bytesRW=fread(buffer, 1, bufSize, cfile); @@ -578,11 +588,10 @@ // Make copy of ehist.cny printMsg("Saving ehist.bak.\n"); - //wait(2); cfile = fopen("/local/ehist.cny", "r"); sfr = f_open(&efile,"ehist.bak",FA_WRITE|FA_CREATE_NEW); if((cfile != NULL)&&(sfr == FR_OK)){ - printMsg("Copy ehist file to USB\n"); + printf("Copy ehist file to USB\n"); while (!feof(cfile)) { bytesRW=fread(buffer, 1, bufSize, cfile); @@ -592,13 +601,14 @@ fclose(cfile); f_close(&efile); } - //wait(2); + wait(3); } void readConfig(){ FILE *cfile; int ff,readHex,readBool; char sTemp[16]; + float readFloat; cfile = fopen("/local/config.txt", "r"); if (cfile==NULL){ // if doesn't exist --> create @@ -655,8 +665,17 @@ brakeMon = (bool)(readBool&1); regenMon = (bool)(readBool&2); heaterMon = (bool)(readBool&4); - fscanf(cfile, "brkMonRate %d\r\n", &brkMonRate ); - fscanf(cfile, "brkMonThr %d\r\n", &brkMonThr ); + if(ff>10){ + fscanf(cfile, "brkMonRate %f\r\n", &readFloat ); + brkMonRate = 94737 * readFloat; + fscanf(cfile, "brkMonThr %f\r\n", &readFloat ); + brkMonThr = 1895 * readFloat; + }else{ + fscanf(cfile, "brkMonRate %d\r\n", &brkMonRate ); + fscanf(cfile, "brkMonThr %d\r\n", &brkMonThr); + brkMonRate = 378948; + brkMonThr = 1895; + } } if(ff>7){ for(char i=0;i<8;i++){ @@ -674,11 +693,11 @@ fscanf(cfile, "kWperGid %f\r\n", &kWperGid ); } fclose(cfile); - if((ff>10)||(ff<1)||(ledHi<0.1)||(scale12V<10)||(tt.x_mid<16000)||(ledHi>1)||(ledLo>1)||(dMode[0]>maxScreens)||(dMode[1]>maxScreens)){ //Sanity check a few things + if((ff>11)||(ff<1)||(ledHi<0.1)||(scale12V<10)||(tt.x_mid<16000)||(ledHi>1)||(ledLo>1)||(dMode[0]>maxScreens)||(dMode[1]>maxScreens)){ //Sanity check a few things //Something wrong. Load defaults - printf("Invalid config file. Loading defaults.\n"); + printMsg("Invalid config file. Loading defaults.\n"); wait(3); - ff=10; + ff=11; tt.x0_off=5732; tt.y0_off=34009; tt.x0_pp=77; @@ -703,8 +722,8 @@ brakeMon=true; regenMon=true; heaterMon=true; - brkMonRate=400000; - brkMonThr=4000; + brkMonRate=378947; // 4Wh per chirp + brkMonThr=1895; // 1Wh per second uMsgId[0]=0x5103; uMsgId[1]=0x50a3; uMsgId[2]=0x54a4; @@ -717,9 +736,9 @@ autoSync=false; kWperGid=0.080; } - if(ff<9){//If not latest format, save as latest format + if(ff<11){//If not latest format, save as latest format saveConfig(); - printMsg("Config file format updated.\n"); // config forat updates + printMsg("Config file format updated.\n"); // config format updates } printMsg("Config file loaded.\n"); // config file loaded } @@ -1050,6 +1069,8 @@ tt.foreground(Yellow); tt.locate(0,10); tt.cls(); + + printMsg("Copy config file from USB\n"); // Check for config file on USB drive sfr = f_open(&efile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING); if(sfr == FR_OK){ @@ -1070,6 +1091,7 @@ } // Check for history file on USB drive + printMsg("Copy ehist file from USB\n"); sfr = f_open(&efile,"ehist.cny",FA_READ|FA_OPEN_EXISTING); if(sfr == FR_OK){ printf("Copy ehist file from USB\n"); @@ -1145,7 +1167,7 @@ //Sample CONFIG.TXT /* -format 9 +format 11 x0_off 5732 y0_off 34009 x0_pp 77 @@ -1168,8 +1190,8 @@ firmware 1 showHealth 1 brakeMon 1 -brkMonRate 400000 -brkMonThr 4000 +brkMonRate 4.0 +brkMonThr 1.0 usrMsgId 5103 usrMsgId 50a3 usrMsgId 54a4 @@ -1180,5 +1202,5 @@ usrMsgId 0000 modelYear 2011 autoSync 1 -kWperGid 0.080 +kWperGid 0.075 */ \ No newline at end of file
--- a/utility.h Sun Dec 29 22:35:09 2013 +0000 +++ b/utility.h Sun Jan 05 05:02:41 2014 +0000 @@ -47,7 +47,7 @@ extern float playbackInt; extern signed long mWs_x4; extern unsigned short numWsamples; -extern signed long motorRPM_x2; +extern signed long motorRPM; extern unsigned short numSsamples; extern unsigned char skin; extern unsigned char dtePeriod;