Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Revision 131:0d926c080a65, committed 2013-07-24
- Comitter:
- TickTock
- Date:
- Wed Jul 24 11:20:08 2013 +0000
- Parent:
- 130:1a9d2a6d99ce
- Child:
- 132:08748a67280a
- Commit message:
- Added Health splash screen on ignition on/off. Added copy of CONFIG.TXT from USB if present during firmware update. Added alt SOH. Tweaked graphics.
Changed in this revision
--- a/common.h Mon Jul 22 00:02:51 2013 +0000 +++ b/common.h Wed Jul 24 11:20:08 2013 +0000 @@ -35,4 +35,4 @@ #define BatDataBaseG7 0x3A #define BatDataBufMax 0x196 // 7 x 3A bytes -#define VP230Sleep 1 // Set to 0 if using VP231 (sleep disables RX) \ No newline at end of file +#define VP230Sleep 0 // Set to 0 if using VP231 (sleep disables RX) \ No newline at end of file
--- a/displayModes.cpp Mon Jul 22 00:02:51 2013 +0000 +++ b/displayModes.cpp Wed Jul 24 11:20:08 2013 +0000 @@ -6,10 +6,10 @@ void mainDisplay (bool force, bool showButtons){ unsigned short gids, SOC_x10, packV_x2, tireP; - static unsigned short lgids=0, lSOC=0, lSOH=0, lpackV_x2=0, ltireP=0, maxPS=0; + static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0, maxPS=0; static float lmaxTemp=0; static float lkW=0, laccV=0, lmpkWh=0; - static unsigned long lAh=0; + CANMessage msg; msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids @@ -38,51 +38,30 @@ printf("%4.1f kWh \n",(float)(gids-5)*0.075); tt.set_font((unsigned char*) SCProSB31x55); tt.foreground(Green); - tt.locate(60,96); + tt.locate(60,80); printf("%4.1f %s \n",convertDistance(mpkWh[dtePeriod]*((float)(gids-5)*.075)),distanceUnit()); //LM - add metric conversion lgids=gids; lmpkWh=mpkWh[dtePeriod]; tt.foreground(Yellow); tt.set_font((unsigned char*) Arial28x28); } - if(force||tireP!=ltireP){ - tt.foreground(LightGrey); - if(msg.data[6]&0x80){ - tt.locate(40,150); - printf("%3.1f\n",(float)msg.data[2]/4); - } - if(msg.data[6]&0x40){ - tt.locate(114,150); - printf("%3.1f\n",(float)msg.data[3]/4); - } - if(msg.data[6]&0x20){ - tt.locate(40,178); - printf("%3.1f\n",(float)msg.data[4]/4); - } - if(msg.data[6]&0x10){ - tt.locate(114,178); - printf("%3.1f\n",(float)msg.data[5]/4); - } - tt.foreground(Yellow); - ltireP=tireP; - } if(force||SOC_x10!=lSOC){ tt.locate(200,10); printf("%4.1f%s\n",(float)SOC_x10/10,"% "); lSOC=SOC_x10; } if(force||packV_x2!=lpackV_x2){ - tt.locate(200,206); + tt.locate(200,176); printf("%4.1fV \n",(float)packV_x2/2); lpackV_x2=packV_x2; } if(force||maxTemp!=lmaxTemp){ - tt.locate(200,176); + tt.locate(200,146); printf("%4.1f%s\n",convertTemperature(maxTemp),temperatureUnit()); lmaxTemp=maxTemp; } if(force||accV!=laccV){ - tt.locate(20,206); + tt.locate(20,176); printf("%3.1fV \n",accV); laccV=accV; } @@ -102,16 +81,26 @@ } lkW=kW[0]; } - tt.foreground(LightGrey); - if(force||Ah_x10000!=lAh){ - tt.locate(10,70); - printf("% 4.2fAh \n",(float)Ah_x10000/10000); - lAh=Ah_x10000; - } - if(force||SOH_x100!=lSOH){ - tt.locate(206,70); - printf("%4.1f%s\n",(float)SOH_x100/100,"% "); - lSOH=SOH_x100; + if(force||tireP!=ltireP){ + tt.foreground(LightGrey); + if(msg.data[6]&0x80){ + tt.locate(10,206); + printf("%3.1f\n",(float)msg.data[2]/4); + } + if(msg.data[6]&0x40){ + tt.locate(90,206); + printf("%3.1f\n",(float)msg.data[3]/4); + } + if(msg.data[6]&0x20){ + tt.locate(170,206); + printf("%3.1f\n",(float)msg.data[4]/4); + } + if(msg.data[6]&0x10){ + tt.locate(250,206); + printf("%3.1f\n",(float)msg.data[5]/4); + } + tt.foreground(Yellow); + ltireP=tireP; } }else {//if(skin==ggSkin){ if(force||gids!=lgids){ @@ -254,7 +243,7 @@ } void healthDisplay (bool force, bool showButtons){ - unsigned short gids, SOC_x10; + unsigned short gids, SOC_x10, SOH_x2; static unsigned short lgids=0, lSOC=0, lSOH=0; static float lmaxTemp=0, lresr=0, lunlV=0; static unsigned long lAh=0; @@ -264,6 +253,8 @@ gids = (msg.data[0]<<2)+(msg.data[1]>>6); msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC SOC_x10 = (msg.data[0]<<2)+(msg.data[1]>>6); + msg = lastMsg[indexLastMsg[0x5b3]]; //Get SOH + SOH_x2 = msg.data[1]; tt.background(Blue); tt.foreground(Yellow); @@ -301,7 +292,7 @@ } if(force||SOH_x100!=lSOH){ tt.locate(10,70); - printf(" %4.1f%s \n",(float)SOH_x100/100,"% SOH"); + printf(" %4.1f,%4.1f %s \n",(float)SOH_x2/2,(float)SOH_x100/100,"% SOH"); lSOH=SOH_x100; } if(force||Ah_x10000!=lAh){ @@ -572,7 +563,7 @@ showButton(3,1," GoTo"," Config",4,4); // bottom (not Nav) row showButton(0,2," GoTo","Playback",4,4); - showButton(1,2," GoTo","Set Time",4,4); + //showButton(1,2," GoTo","Set Time",4,4); showButton(2,2," GoTo"," Log",4,4); showButton(3,2," GoTo"," Trip",4,4); @@ -844,7 +835,7 @@ //-------- top row -------- showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4 showButton(1,0," Reset","",4,4); - showButton(2,0," Save"," Config",4,4); + showButton(2,0," Save"," Config",4,4); // a button to step to the next skin unsigned int nextSkin = skin + 1 ; @@ -854,7 +845,7 @@ else if( nextSkin == ggSkin ) sprintf(sTemp1,"Skin GG"); else sprintf(sTemp1,"Skin %d",nextSkin); - showButton(3,0," Use",sTemp1,4,4); + showButton(3,0," Use",sTemp1,4,4); //------- second row ----- if (logEn&&usbEn) { @@ -881,9 +872,9 @@ // add Enable/Disable Debug - debugMode if (debugMode) { - sprintf(sTemp1,"Disable"); + sprintf(sTemp1," Disable"); } else { - sprintf(sTemp1,"Enable"); + sprintf(sTemp1," Enable"); } showButton(3,1,sTemp1," Debug",4,4); @@ -892,6 +883,13 @@ else showButton(0,2,"Metric","",4,4); + showButton(1,2," Set"," Time",4,4); + if (showHealth) { + sprintf(sTemp1," Hide"); + } else { + sprintf(sTemp1," Show"); + } + showButton(2,2,sTemp1," Health",4,4); showButton(3,2,"Update","Firmware",4,4); } @@ -959,9 +957,6 @@ case 5: sprintf(sTemp1,"Second"); break; - case 6: - sprintf(sTemp1,"Select"); - break; default: break; } @@ -1027,8 +1022,8 @@ tt.set_font((unsigned char*) Arial24x23); //for(i=0;i<10;i++){ //y=200-i*20; - for(i=3;i<8;i++){ - y=200-(i-3)*40; + for(i=2;i<7;i++){ + y=200-(i-2)*40; tt.locate(0,y-8); if (showMiles){ printf("%3.0f\n",convertDistance(i*((float)(gids-5)*.075))); // LM - Added metric support @@ -1041,8 +1036,8 @@ lgids=gids; } if(tock||force){ - for(i=3;i<8;i++){ - y=200-(i-3)*40; + for(i=2;i<7;i++){ + y=200-(i-2)*40; tt.line(40,y,158,y,DarkGrey); } @@ -1091,11 +1086,11 @@ radius=2; color=Green; } - if(ly<100){ + if(ly<60){ ly=220; color=Red; - }else if(ly<320) { - ly=320-ly; + }else if(ly<280) { + ly=280-ly; }else{ ly=0; } @@ -1112,11 +1107,11 @@ radius=2; color=Green; } - if(y<100){ + if(y<60){ y=220; color=Red; - }else if(y<320) { - y=320-y; + }else if(y<280) { + y=280-y; }else{ y=0; }
--- a/displayModes.h Mon Jul 22 00:02:51 2013 +0000 +++ b/displayModes.h Wed Jul 24 11:20:08 2013 +0000 @@ -57,6 +57,7 @@ extern bool shunt[96]; extern float unloadedV_x2,Resr,curRmax,curRmin,redRmax,redRmin,incRmax,incRmin; extern signed short Imax, Imin; +extern bool showHealth; extern "C" { void printLast (bool force, bool showButtons);
--- a/main.cpp Mon Jul 22 00:02:51 2013 +0000 +++ b/main.cpp Wed Jul 24 11:20:08 2013 +0000 @@ -4,12 +4,11 @@ // * Audible friction brake feedback // * User-configurable watchpoint // * Add 50% charge option -// * Tire Pressure Sensor display -// * Fix bug in playback while connected to canbus (hangs) // * Add coasting regen to regen/braking display // * Change semilog efficiency graph to linear with 10 minute values // * Add additional 79b bank readouts // * Add ability to transfer settings config file to/from USB +// * Subtract accessory power from efficiency history (add back in when displaying) #include "mbed.h" #include "CAN.h" @@ -21,7 +20,7 @@ #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "130"; // gg - revision string, max 6 characters +char revStr[7] = "131"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); @@ -54,7 +53,7 @@ bool debugMode = false; bool usbEn = false; -bool logEn = true; +bool logEn = false; bool logOpen = false; bool yesBattLog = true; // gg - Batt Log unsigned char tNavRow = 3; // gg - 4x4 touch @@ -74,9 +73,9 @@ char c; volatile int writePointer = 0; int readPointer=0; -volatile unsigned short secsNoMsg = 0; +volatile unsigned short secsNoCarCanMsg = 0; volatile unsigned short secsNoTouch = 0; -volatile bool canIdle; +volatile bool carCanIdle; volatile bool userIdle; bool touched=false; //flag to read touchscreen unsigned char whichTouched = 0; @@ -84,7 +83,7 @@ unsigned char dMode[2] = {mainScreen,brakeScreen}; //display mode unsigned char sMode = 0; // setup mode unsigned char lastDMode[2] = {0,0}; //last screen mode -unsigned char dtMode = 6; +unsigned char dtMode = 0; char displayLog[20][40]; unsigned char displayLoc = 0; unsigned int fwCount=1; @@ -139,6 +138,9 @@ bool metric = false; bool shunt[96]={0}; bool charging=false; +bool showHealth=false; +unsigned char saveDmode=99; +bool moving=false; int main() { //can1SleepMode.mode(OpenDrain); @@ -181,7 +183,7 @@ sprintf(sTemp,"CANary firmware rev%s\n", revStr); // gg - for Logging the revision printMsg(sTemp); // revision - secsNoMsg = 0; + secsNoCarCanMsg = 0; //read efficiency history data hfile = fopen("/local/ehist.cny", "r"); @@ -224,7 +226,7 @@ secsNoTouch=2; while (true) { if (!logOpen) { // Open new file if one is not already open - if(logEn&&usbEn){ //logging enables and USB device detected + if(logEn&&usbEn){ //logging enabled and USB device detected strftime(fileName, 32, "%m%d%H%M.alc", &t); //mmddhhmm.alc efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS); seconds = time(NULL); @@ -253,7 +255,7 @@ }//logging enabled and USB detected } else { // if (logOpen) pointerSep=(writePointer+maxBufLen-readPointer)%maxBufLen; - if (pointerSep>(maxBufLen/16)||canIdle||!logEn) { + if (pointerSep>(maxBufLen/16)||carCanIdle||!logEn) { // Dump buffer if > 1/16 full or canbus has stopped //if (&efile == NULL) { if (efr != FR_OK) { @@ -283,7 +285,7 @@ led4=false; } } // if logOpen - if (canIdle&&userIdle&&!playbackEn) { // canbus idle --> sleep to save power + if (carCanIdle&&userIdle&&!playbackEn) { // canbus idle --> sleep to save power if (repeatPoll) { // stop autopolling if enabled autoPoll.detach(); } @@ -303,7 +305,7 @@ led4=0; dled=0; // turn off display secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 - while (secsNoMsg>canTimeout && !touched) { + while (secsNoCarCanMsg>canTimeout && !touched) { //DeepPowerDown(); tt.wfi(); //enable touch interrupt //__wfi(); // freeze CPU and wait for interrupt (from canbus or touch) @@ -312,7 +314,7 @@ lastDMode[0]=99; lastDMode[1]=99; secsNoTouch=2; - canIdle=secsNoMsg>canTimeout; + carCanIdle=secsNoCarCanMsg>canTimeout; dled=0.8; // turn on display LED seconds = time(NULL); t = *localtime(&seconds) ; @@ -492,7 +494,7 @@ dMode[whichTouched] = cpScreen ; // GoTo CP Data Screen sMode=0; } else if (dMode[whichTouched]==dateScreen){ - dtMode=(dtMode<6)?dtMode+1:0; + dtMode=(dtMode<5)?dtMode+1:0; lastDMode[whichTouched]=99; } else { lastDMode[whichTouched]=99;//repaint to clear highlight @@ -514,7 +516,9 @@ } else if (dMode[whichTouched]==playbackScreen) { // Start/stop playback if(!playbackOpen){ - if(!logOpen){ + if(!carCanIdle){ + printMsg("Cannot playback while connected to canbus\n"); + }else if(!logOpen){ efr = f_open(&efile,"playback.alc",FA_READ|FA_OPEN_EXISTING); lastDMode[whichTouched]=99;//force refresh if(efr != FR_OK){ @@ -592,7 +596,7 @@ break; case 12: // left-middle col, bottom row (not nav) - if (dMode[whichTouched] == indexScreen) { // gg - index + if (dMode[whichTouched] == configScreen) { // gg - index dMode[whichTouched] = dateScreen ; // GoTo Set Date/Time Screen } else { lastDMode[whichTouched]=99;//repaint to clear highlight @@ -602,6 +606,8 @@ case 22: // right-middle col, bottom row (not nav) if (dMode[whichTouched] == indexScreen) { // gg - index dMode[whichTouched] = logScreen ; + } else if (dMode[whichTouched]==configScreen) { + showHealth = !showHealth; } else { lastDMode[whichTouched]=99;//repaint to clear highlight } @@ -673,8 +679,11 @@ headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false; // headlight/turn signal indicator accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th accOn=(accV>5)?true:false; - charging=(mph[0]<0.1)&&(kW[0]<-1); // not moving and generating energy so much be charging + moving=(mph[0]>0.1); + charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging if(laccOn&&!accOn){ // Car turned off + saveDmode=dMode[0]; + dMode[0]=healthScreen; if (repeatPoll) { // Log on shutdown if autopoll enabled tripLog(); // Write trip log on powerdown } @@ -691,10 +700,15 @@ miles_trip[0]=0; kWh_trip[0]=0; wait5secs=5; + if(showHealth){ + saveDmode=dMode[0]; + dMode[0]=healthScreen; + } } laccOn=accOn; if(!accOn&&!logEn&&userIdle&&!playbackEn){ // Car off and logging disabled and no user activity dled = 0; + dMode[0]=saveDmode; }else if(!headlights){ dled = ledHi; } else { @@ -708,6 +722,10 @@ msgReq.attach(&sendReq,0.015); } } + if(moving&&(saveDmode<99)&&(wait5secs==0)){ + dMode[0]=saveDmode; + saveDmode=99; + } //compute historic efficiency if(numSsamples>0){ // Avoid div0
--- a/utility.cpp Mon Jul 22 00:02:51 2013 +0000 +++ b/utility.cpp Wed Jul 24 11:20:08 2013 +0000 @@ -5,7 +5,7 @@ void RTC_IRQHandler() { timer.reset(); // zero ms at the-seconds-tic - canIdle=(++secsNoMsg>canTimeout)?true:false; + carCanIdle=(++secsNoCarCanMsg>canTimeout)?true:false; userIdle=(++secsNoTouch>userTimeout)?true:false; LPC_RTC->ILR |= (1<<0); // clear interrupt to prepare for next tick=true; @@ -55,7 +55,7 @@ signed long imWs_x4; unsigned short ts; - secsNoMsg=0; // reset deadman switch + secsNoCarCanMsg=0; // reset deadman switch if(debugMode||(skin==ggSkin)){ // code to insert actual number of dropped frames for overrun debug - skiped in normal mode to keep logcan short if(logOpen){ @@ -490,7 +490,7 @@ void saveConfig(){ FILE *cfile; cfile = fopen("/local/config.txt", "w"); - fprintf(cfile,"format 5\r\n"); + fprintf(cfile,"format 6\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); @@ -517,12 +517,14 @@ fprintf(cfile,"DebugMode %d\r\n",(debugMode?1:0)); 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)); fclose(cfile); } void readConfig(){ FILE *cfile; int ff; + cfile = fopen("/local/config.txt", "r"); if (cfile==NULL){ // if doesn't exist --> create printMsg("No config file found.\n"); // no config file @@ -571,8 +573,13 @@ fscanf(cfile, "firmware %d\r\n", &iMetric ); fwCount = iMetric; } + if(ff>5){ + int ishowHealth; + fscanf(cfile, "showHealth %d\r\n", &ishowHealth ); + showHealth = (bool)ishowHealth; + } fclose(cfile); - if(ff<4){//If not latest format, save as latest format + if(ff<6){//If not latest format, save as latest format saveConfig(); printMsg("Config file format updated.\n"); // config forat updates } @@ -745,14 +752,15 @@ 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]); - for(i=0; i<96; i++) { + /*for(i=0; i<96; i++) { bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4]; f_printf(&bfile,",%d",bd); - } + }*/ // temporariliy dump everything - /*for(i=0; i<BatDataBufMax; i++) { - f_printf(&bfile,",%02x",battData[i]); - }*/ + for(i=0; i<BatDataBufMax; i++) { + sprintf(sTemp,",%02x",battData[i]); + f_printf(&bfile,"%s",sTemp); + } f_printf(&bfile,"\r\n"); f_close(&bfile); @@ -767,6 +775,26 @@ FRESULT sfr; // external file access flags unsigned int bytesRW; char sTemp[40]; + const int bufSize = 2048; + char buffer[bufSize]; + FILE *destFile; + + // Check for config file on USB drive + sfr = f_open(&sfile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING); + if(sfr == FR_OK) + { + printf("Copy config file from USB\n"); + destFile = fopen("/local/CONFIG.TXT", "w"); + while (!f_eof(&sfile)) + { + sfr=f_read(&sfile,&buffer,bufSize,&bytesRW); + fwrite(buffer, 1, bytesRW, destFile); + } + fflush(destFile); + fclose(destFile); + f_close(&sfile); + } + sfr = f_open(&sfile,"firmware.bin",FA_READ|FA_OPEN_EXISTING); if(sfr != FR_OK) { @@ -811,21 +839,17 @@ printf("copying new firmware\n"); tt.cls(); //Copy the new firmware from usb->local - //The newest bin file is the one that is used by the mbed - const int bufSize = 2048; - FILE *destFile; + //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); wait(2); destFile = fopen(sTemp, "wb"); if(destFile == NULL) { - sprintf(sTemp,"Couldn't Open Destination\n"); - printf(sTemp); + printf("Couldn't Open Destination\n"); wait(3); return; } - char buffer[bufSize]; while (!f_eof(&sfile)) { @@ -852,4 +876,31 @@ f_unlink("usb.det"); } return(usbEn); + //return(true); } + +//Sample CONFIG.TXT +/* +format 5 +x0_off 5732 +y0_off 34009 +x0_pp 77 +y0_pp 106 +x1_off 33955 +y1_off 6310 +x1_pp 80 +y1_pp 104 +x_mid 31986 +dMode0 4 +dMode1 2 +ledHi 0.800 +ledLo 0.100 +pollInt 300 +scale12V 16.20 +skin 0 +dtePeriod 14 +DebugMode 0 +metric 0 +firmware 11 +showHealth 1 +*/ \ No newline at end of file
--- a/utility.h Mon Jul 22 00:02:51 2013 +0000 +++ b/utility.h Wed Jul 24 11:20:08 2013 +0000 @@ -9,9 +9,9 @@ extern Timer timer; extern Ticker msgReq; -extern volatile unsigned short secsNoMsg; +extern volatile unsigned short secsNoCarCanMsg; extern volatile unsigned short secsNoTouch; -extern volatile bool canIdle; +extern volatile bool carCanIdle; extern volatile bool userIdle; extern char displayLog[20][40]; extern unsigned char displayLoc; @@ -66,6 +66,7 @@ extern bool debugMode; extern bool shunt[96]; extern float accV; +extern bool showHealth; extern "C" { void mbed_reset();