Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Revision 140:ab3e94eb0227, committed 2013-08-04
- Comitter:
- TickTock
- Date:
- Sun Aug 04 14:57:40 2013 +0000
- Parent:
- 139:ac227b203ef2
- Child:
- 141:cf13a632ddb5
- Commit message:
- Added odometer to batt and trip log; Added mi/km detection from dash; Added audible brake monitor;
Changed in this revision
--- a/common.h Fri Aug 02 14:11:23 2013 +0000 +++ b/common.h Sun Aug 04 14:57:40 2013 +0000 @@ -37,4 +37,5 @@ #define VP230Sleep 0 // Set to 0 if using VP231 (sleep disables RX) -#define minTirePressure 128 // 32psi X 4 \ No newline at end of file +#define minTirePressure 128 // 34psi X 4 +#define brkMonRate 40000 // larger = slower chirp rate \ No newline at end of file
--- a/displayModes.cpp Fri Aug 02 14:11:23 2013 +0000 +++ b/displayModes.cpp Sun Aug 04 14:57:40 2013 +0000 @@ -422,6 +422,10 @@ short steerOutBounds = 0 ; CANMessage msg; +// tt.set_font((unsigned char*) Arial12x12_prop); // select the font +// tt.locate(10,40); +// printf("%d \n",chirpInt); + //--------------- msg = lastMsg[indexLastMsg[0x180]]; //Get Throttle position throttle = msg.data[5]; @@ -968,10 +972,10 @@ } showButton(3,1,sTemp1," Debug",4,4); - if(metric) - showButton(0,2,"Imperial","",4,4); + if(brakeMon) + showButton(0,2,"Disable","BrkMon",4,4); else - showButton(0,2,"Metric","",4,4); + showButton(0,2," Enable"," BrkMon",4,4); showButton(1,2," Set"," Time",4,4); if (showHealth) {
--- a/displayModes.h Fri Aug 02 14:11:23 2013 +0000 +++ b/displayModes.h Sun Aug 04 14:57:40 2013 +0000 @@ -59,6 +59,8 @@ extern signed short Imax, Imin; extern bool showHealth; extern float maxTripEff, minTripEff; +extern bool brakeMon; +//extern unsigned short chirpInt; extern "C" { void printLast (bool force, bool showButtons);
--- a/main.cpp Fri Aug 02 14:11:23 2013 +0000 +++ b/main.cpp Sun Aug 04 14:57:40 2013 +0000 @@ -10,8 +10,10 @@ // * Subtract accessory power from efficiency history (add back in when displaying) // * Add trip history display -// rev139 -// Fixed right justify (compare to 9.5, 99.5 instead of 10, 100) +// rev140 +// Added odometer to batt and trip log +// Added mi/km detection from dash +// Added audible brake monitor #include "mbed.h" #include "CAN.h" @@ -22,8 +24,7 @@ #include "utility.h" #include "displayModes.h" #include "TOUCH_TFTx2.h" - -char revStr[7] = "139"; // gg - revision string, max 6 characters +char revStr[7] = "140"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); @@ -36,6 +37,7 @@ Ticker autoPoll; Ticker playback; Ticker msgReq; +Ticker geiger; Timer timer; DigitalOut led1(LED1); @@ -59,6 +61,8 @@ bool logOpen = false; bool yesBattLog = true; // gg - Batt Log unsigned char tNavRow = 3; // gg - 4x4 touch +bool brakeMon = false; // disable until desired value read from config +unsigned char bp; FILE *hfile; // history file FIL efile; // external usb file @@ -95,6 +99,7 @@ bool logOnce = false; bool repeatPoll = true; bool headlights = false; +bool miles_kmbar = true; bool tick = false; bool ZeroSecTick = false; float ledHi = 0.8; // Bright LED value (until config file read) @@ -145,6 +150,7 @@ bool showHealth=false; unsigned char saveDmode=99; bool moving=false; +unsigned short chirpInt; int main() { char sTemp[40]; @@ -220,6 +226,9 @@ // Read config file readConfig(); + if (brakeMon){ + geiger.attach(&chirp,0.02); + } if (repeatPoll) { // enable autopolling if enabled autoPoll.attach(&autoPollISR,pollInt); } @@ -605,9 +614,12 @@ if (dMode[whichTouched] == indexScreen) { // gg - index dMode[whichTouched] = playbackScreen ; // GoTo Playback Screen } else if (dMode[whichTouched]==configScreen) { - metric = !metric; // toggle metric/imperial display - lastDMode[0]=99;//repaint - lastDMode[1]=99;//repaint + brakeMon = !brakeMon; + if(brakeMon){ + geiger.attach(&chirp,0.02); + }else{ + geiger.detach(); + } } else { lastDMode[whichTouched]=99;//repaint to clear highlight } @@ -694,6 +706,8 @@ if(tick){ // Executes once a second tick=false; headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false; // headlight/turn signal indicator + miles_kmbar = (lastMsg[indexLastMsg[0x355]].data[4]&0x20)?true:false; // indicates selected distance units + metric = !miles_kmbar; accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th accOn=(accV>5)?true:false; moving=(mph[0]>0.1); @@ -863,9 +877,6 @@ } tock=true; } // tick - - display=display<1?display+1:0; // toggle display - updateDisplay(display); if(step){ // playback if(playbackOpen&&playbackEn){ @@ -885,5 +896,7 @@ step=false; } + display=display<1?display+1:0; // toggle display + updateDisplay(display); } //while (true) } \ No newline at end of file
--- 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
--- a/utility.h Fri Aug 02 14:11:23 2013 +0000 +++ b/utility.h Sun Aug 04 14:57:40 2013 +0000 @@ -71,6 +71,10 @@ extern bool showHealth; extern float kWh_trip[0]; extern float miles_trip[0]; +extern Beep spkr; +extern bool brakeMon; +extern Ticker geiger; +extern unsigned short chirpInt; extern "C" { void mbed_reset(); @@ -98,6 +102,7 @@ void tripLog(); // Turbo3 void updateFirmware(); // LM - Update firmware off USB bool detectUSB(); + void chirp(); } //LEAF OBD