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 151:3047ebb3c9a8, committed 2013-09-30
- Comitter:
- TickTock
- Date:
- Mon Sep 30 15:31:01 2013 +0000
- Parent:
- 150:ef46ce63345c
- Child:
- 152:a4d66901785d
- Commit message:
- // added per_charge trip meter
Changed in this revision
--- a/SPI_TFTx2.lib Fri Sep 27 04:43:41 2013 +0000 +++ b/SPI_TFTx2.lib Mon Sep 30 15:31:01 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/TickTock/code/SPI_TFTx2/#4ad7de7d2220 +http://mbed.org/users/TickTock/code/SPI_TFTx2/#11d7980e7e1c
--- a/displayModes.cpp Fri Sep 27 04:43:41 2013 +0000 +++ b/displayModes.cpp Mon Sep 30 15:31:01 2013 +0000 @@ -247,10 +247,6 @@ printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]); } if(showButtons){ - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - showButton(0,0," <up>","",4,4); showButton(2,0,"<down>","",4,4); } @@ -275,9 +271,6 @@ }// if changed }while(i<19&&j<99); if(showButtons){ - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); showButton(0,0," <up>","",4,4); showButton(2,0," <down>","",4,4); showButton(1,0," Reset","Baseline",4,4); @@ -314,16 +307,24 @@ printf("kWh : %s : Eff\n",distanceUnit()); for(int i=0; i<3; i++){ tt.locate(6,20+i*60); - printf("%3.2f : %3.1f : %2.1f\n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]); + printf("%3.2f : %3.1f : %2.1f \n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]); } + tt.foreground(Navy); + tt.set_font((unsigned char*) Arial12x12); + tt.locate(274,18); + printf("per\n"); + tt.locate(274,33); + printf("trip\n"); + tt.locate(274,78); + printf("per\n"); + tt.locate(265,93); + printf("charge\n"); + tt.locate(265,145); + printf("custom\n"); + lkWh=kWh_trip[0]; } if(showButtons){ - tt.set_font((unsigned char*) Arial12x12); - tt.background(DarkCyan); - tt.foreground(Yellow); - showButton(3,1," Reset"," A",4,4); - showButton(3,2," Reset"," B",4,4); - lkWh=kWh_trip[0]; + showButton(3,2," Reset"," ",4,4); } } @@ -611,10 +612,6 @@ } } if(showButtons){ - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - showButton(1,0,"Request","CP Data",4,4); } } @@ -632,11 +629,7 @@ // add the buttons to GoTo to other screens - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - - // top row + // top row showButton(0,0," GoTo"," Main",4,4); showButton(1,0," GoTo"," Brake",4,4); showButton(2,0," GoTo"," EFF",4,4); @@ -787,10 +780,6 @@ // handle the button if(sMode==1&&showButtons){ - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - showButton(1,0,"Request","CP Data",4,4); } } @@ -899,10 +888,6 @@ // handle the button if(sMode==1&&showButtons){ - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - showButton(1,0,"Request","CP Data",4,4); } } @@ -913,10 +898,6 @@ tt.background(Black); tt.cls(); } - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - //-------- top row -------- showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4 showButton(1,0," Reset","",4,4); @@ -984,9 +965,6 @@ tt.background(Black); tt.cls(); } - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); if(playbackOpen){ showButton(0,0,"Slower"," <--",4,4); @@ -1045,7 +1023,6 @@ default: break; } - tt.background(DarkCyan); showButton(0,1,sTemp1,"",4,4); showButton(1,1," UP","",4,4); showButton(2,1," DOWN","",4,4); @@ -1350,10 +1327,6 @@ if(display==whichTouched){ switch (sMode) { case 1: // Select screens - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial12x12); - showButton(0,tNavRow," <-Prev","",4,4); // gg - 4x4 // col 1 see below showButton(2,tNavRow," Go To"," Index",4,4); // gg - index @@ -1422,25 +1395,20 @@ break; case 2: // numpad - tt.foreground(Yellow); - tt.background(DarkCyan); - tt.set_font((unsigned char*) Arial24x23); - - sprintf(sTemp2,""); - showButton(0,0," 1",sTemp2,4,4); - showButton(1,0," 2",sTemp2,4,4); - showButton(2,0," 3",sTemp2,4,4); - showButton(0,1," 4",sTemp2,4,4); - showButton(1,1," 5",sTemp2,4,4); - showButton(2,1," 6",sTemp2,4,4); - showButton(0,2," 7",sTemp2,4,4); - showButton(1,2," 8",sTemp2,4,4); - showButton(2,2," 9",sTemp2,4,4); - showButton(1,3," 0",sTemp2,4,4); + showButton(0,0," 1","",4,4); + showButton(1,0," 2","",4,4); + showButton(2,0," 3","",4,4); + showButton(0,1," 4","",4,4); + showButton(1,1," 5","",4,4); + showButton(2,1," 6","",4,4); + showButton(0,2," 7","",4,4); + showButton(1,2," 8","",4,4); + showButton(2,2," 9","",4,4); + showButton(1,3," 0","",4,4); - showButton(0,3,"<--",sTemp2,4,4); - showButton(2,3,"-->",sTemp2,4,4); - showButton(3,3,"return",sTemp2,4,4); + showButton(0,3,"<--","",4,4); + showButton(2,3,"-->","",4,4); + showButton(3,3,"return","",4,4); case 3: break; default: @@ -1487,6 +1455,10 @@ y1=row*(240/rows)+btnGap/2; y2=(row+1)*(240/rows)-btnGap/2; tt.fillrect(x1,y1,x2,y2,DarkCyan); + + tt.foreground(Yellow); + tt.background(DarkCyan); + tt.set_font((unsigned char*) Arial12x12); // adapt formatting of text to the smaller 4x4 box tt.locate(x1+btnGap/2,y1+btnGap); // gg - 4x4
--- a/main.cpp Fri Sep 27 04:43:41 2013 +0000 +++ b/main.cpp Mon Sep 30 15:31:01 2013 +0000 @@ -7,16 +7,15 @@ // * Change semilog efficiency graph to linear with 10 minute values // * Subtract accessory power from efficiency history (add back in when displaying) // * Add in-device config editor -// * Normalize efficiency to 25C relative to ambient. Display efficiency at current temp. +// * Store efficiency data at different temperatures // * Change pack volt color when CVLI fails // * Add per-charge efficiency meter; add to triplop.txt // * Add tire pressure cal (40psi for me = FR 38, RR 38.2, FL 37.8, RL 38 - maybe 2psi error on my tire gauge?) // * Add heater activation warning message // * Add trip max/min efficiency reset -// rev150 -// Added user message Id's to the config file -// Added copy of ehist.cny to USB on config save and load if present on firmware update +// rev151 +// added per_charge trip meter #include "mbed.h" #include "CAN.h" @@ -27,7 +26,7 @@ #include "utility.h" #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "150"; // gg - revision string, max 6 characters +char revStr[7] = "151"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); @@ -601,11 +600,11 @@ debugMode = !debugMode; } else if (dMode[whichTouched] == indexScreen) { // gg - index dMode[whichTouched] = configScreen ; // GoTo Config Screen - } else if (dMode[whichTouched] == tripScreen) { + /*} else if (dMode[whichTouched] == tripScreen) { miles_trip[1]=0; kWh_trip[1]=0; sMode=0; - lastDMode[whichTouched]=99;//repaint to clear highlight + lastDMode[whichTouched]=99;//repaint to clear highlight*/ } else { lastDMode[whichTouched]=99;//repaint to clear highlight } @@ -716,7 +715,8 @@ accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th accOn=(accV>5)?true:false; moving=(mph[0]>0.1); - charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging + charging=(lastMsg[indexLastMsg[0x5bf]].data[2]>0)?true:false; // FF when charging + //charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging if (laccOn&&!accOn){ // Car turned off if (showHealth){ if (saveDmode==99){ @@ -815,12 +815,15 @@ numWsamples=0; if (!charging){ - miles_trip[0]+=mph[0]/3600; - miles_trip[1]+=mph[0]/3600; - miles_trip[2]+=mph[0]/3600; + miles_trip[0]+=mph[0]/3600; // per trip + miles_trip[1]+=mph[0]/3600; // per charge + miles_trip[2]+=mph[0]/3600; // user kWh_trip[0]+=kW[0]/3600; kWh_trip[1]+=kW[0]/3600; kWh_trip[2]+=kW[0]/3600; + } else { + miles_trip[1]=0; + kWh_trip[1]=0; } motorRPM=0; @@ -854,10 +857,8 @@ mph[i]+=mph[0]; mpkWh[i]=average; average=kW[i]/timeConstant[i]; - if(!charging){ //Not charging - so include in efficiency data - kW[i]-=average; - kW[i]+=kW[0]; - } + kW[i]-=average; + kW[i]+=kW[0]; mpkWh[i]/=average; if (mpkWh[i]<0) { mpkWh[i]=99;// negative means inf.
--- a/utility.cpp Fri Sep 27 04:43:41 2013 +0000 +++ b/utility.cpp Mon Sep 30 15:31:01 2013 +0000 @@ -593,7 +593,7 @@ void readConfig(){ FILE *cfile; - int ff; + int ff,readhex; char sTemp[16]; cfile = fopen("/local/config.txt", "r"); @@ -659,7 +659,8 @@ if(ff>7){ for(char i=0;i<8;i++){ fscanf(cfile, "usrMsgId %s\r\n", &sTemp ); - sscanf(sTemp,"%4x", &uMsgId[i]); + sscanf(sTemp,"%x", &readhex); + uMsgId[i]=readhex; } } fclose(cfile); @@ -901,6 +902,10 @@ char buffer[bufSize]; FILE *lfile; + tt.background(Blue); + tt.foreground(Yellow); + tt.locate(0,10); + tt.cls(); // Check for config file on USB drive sfr = f_open(&efile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING); if(sfr == FR_OK) @@ -942,7 +947,6 @@ wait(2); } - sfr = f_open(&efile,"firmware.bin",FA_READ|FA_OPEN_EXISTING); if(sfr != FR_OK) { @@ -952,12 +956,13 @@ return; } fwCount ++; + printf("Saving config.\n"); saveConfig(); //delete all bin files in /local DIR *dir; struct dirent *ent; - printf("Starting update\n"); - printf("deleting old firmware files\n"); + printf("Starting update.\n"); + printf("Deleting old firmware files.\n"); if ((dir = opendir ("/local/")) != NULL) { // print all the files and directories within directory while ((ent = readdir (dir)) != NULL) { @@ -971,28 +976,27 @@ { sprintf(sTemp,"/local/%s",ent->d_name); int result = remove(sTemp); - printf("REMOVED: %s",ent->d_name); + printf("deleted: %s\n",ent->d_name); } } closedir (dir); } else { //could not open directory - printf("Couldnt open folder"); - wait(3); + printf("Couldn't open folder.\n"); + wait(2); return; } - printf("copying new firmware\n"); - tt.cls(); + printf("Copying new firmware.\n"); //Copy the new firmware from usb->local //The newest bin file is the one that is used by the mbed sprintf(sTemp,"/local/fw%d.bin",fwCount); - printf("Writing %s\n",sTemp); + printf("Writing %s.\n",sTemp); wait(2); lfile = fopen(sTemp, "wb"); if(lfile == NULL) { - printf("Couldn't Open Destination\n"); - wait(3); + printf("Couldn't open destination.\n"); + wait(2); return; } @@ -1005,9 +1009,8 @@ fflush(lfile); fclose(lfile); f_close(&efile); - tt.cls(); - printf("Succesful\n\n"); - printf("Rebooting in 3 seconds\n"); + printf("Succesful.\n\n"); + printf("Rebooting in 3 seconds.\n"); wait(3); //Now run new firmware mbed_reset();