Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Diff: utility.cpp
- Revision:
- 140:ab3e94eb0227
- Parent:
- 138:a2f5af85ed0d
- Child:
- 141:cf13a632ddb5
--- a/utility.cpp Fri Aug 02 14:11:23 2013 +0000 +++ b/utility.cpp Sun Aug 04 14:57:40 2013 +0000 @@ -351,6 +351,17 @@ } motorRPM+=imotorRPM; numSsamples++; + }else if((mType==2)&&(canRXmsg.id==0x1ca)){ //Brake Pressure + if(brakeMon){ + if(canRXmsg.data[0]<0xff){ + if((canRXmsg.data[0]==0)||(imotorRPM==0)){ + chirpInt=0; + }else{ + chirpInt=brkMonRate/imotorRPM; + chirpInt/=canRXmsg.data[0]; + } + } + } } } } @@ -495,7 +506,7 @@ void saveConfig(){ FILE *cfile; cfile = fopen("/local/config.txt", "w"); - fprintf(cfile,"format 6\r\n"); + fprintf(cfile,"format 7\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); @@ -523,6 +534,7 @@ fprintf(cfile,"metric %d\r\n",(metric?1:0)); fprintf(cfile, "firmware %d\r\n", fwCount ); fprintf(cfile,"showHealth %d\r\n",(showHealth?1:0)); + fprintf(cfile,"brakeMon %d\r\n",(brakeMon?1:0)); fclose(cfile); } @@ -574,7 +586,7 @@ if(ff>4) { int iMetric; fscanf(cfile, "metric %d\r\n", &iMetric ); - metric = (bool)iMetric; + //metric = (bool)iMetric; fscanf(cfile, "firmware %d\r\n", &iMetric ); fwCount = iMetric; } @@ -583,8 +595,13 @@ fscanf(cfile, "showHealth %d\r\n", &ishowHealth ); showHealth = (bool)ishowHealth; } + if(ff>6){ + int iBrakeMon; + fscanf(cfile, "brakeMon %d\r\n", &iBrakeMon ); + brakeMon = (bool)iBrakeMon; + } fclose(cfile); - if(ff<6){//If not latest format, save as latest format + if(ff<7){//If not latest format, save as latest format saveConfig(); printMsg("Config file format updated.\n"); // config forat updates } @@ -652,6 +669,7 @@ short unsigned max, min, jv, i, bd; unsigned avg; unsigned short gids, SOC, packV_x2; + unsigned long odo; signed short packA_x2; time_t seconds ; @@ -662,6 +680,8 @@ msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids gids = (msg.data[0]<<2)+(msg.data[1]>>6); + msg = lastMsg[indexLastMsg[0x5c5]]; //Get odometer + odo = (msg.data[1]<16)+(msg.data[2]<<8)+msg.data[3]; msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC SOC = (msg.data[0]<<2)+(msg.data[1]>>6); msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts @@ -692,7 +712,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_x2/2,(float)packA_x2/2,max,min,avg,max-min,jv); + sprintf(sTemp,"%d,%d,%5.1f%%,%5.1f,%5.1f,%d,%d,%d,%d,%d",odo,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]); @@ -713,6 +733,7 @@ short unsigned max, min, jv, i, bd; unsigned avg; unsigned short gids, SOC, packV_x2; + unsigned long odo; signed short packA_x2; time_t seconds ; @@ -723,6 +744,8 @@ msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids gids = (msg.data[0]<<2)+(msg.data[1]>>6); + msg = lastMsg[indexLastMsg[0x5c5]]; //Get odometer + odo = (msg.data[1]<16)+(msg.data[2]<<8)+msg.data[3]; msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC SOC = (msg.data[0]<<2)+(msg.data[1]>>6); msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts @@ -753,7 +776,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,"%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%d,%d,%d,%d,%d,%4.1f,%4.1f",accV,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,miles_trip[0],kWh_trip[0]); + sprintf(sTemp,"%d,%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%d,%d,%d,%d,%d,%4.1f,%4.1f",odo,accV,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,miles_trip[0],kWh_trip[0]); 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]); @@ -881,6 +904,18 @@ return(usbEn); } +void chirp(void){ + static unsigned short counter=0; + + if(chirpInt>0){ + counter++; + if(counter>chirpInt){ + spkr.beep(500,0.01); + counter=0; + } + } +} + //Sample CONFIG.TXT /* format 5 @@ -902,7 +937,7 @@ skin 0 dtePeriod 14 DebugMode 0 -metric 0 +brakeMon 0 firmware 11 showHealth 1 */ \ No newline at end of file