Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Revision 155:f31006516956, committed 2013-10-19
- Comitter:
- TickTock
- Date:
- Sat Oct 19 15:38:44 2013 +0000
- Parent:
- 154:90ea16ca7475
- Child:
- 156:4e5d30535cf9
- Commit message:
- // Added workaround to spkr and dled pwn not being independently controlled in hw; // Added ambient temperature to trip log; // Save Resr in history file so it doesn't reset to 75mOhms on CANary reset; // Fixed Reser formatting to %4.3f;
Changed in this revision
--- a/beep.lib Wed Oct 16 03:47:48 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
--- a/displayModes.cpp Wed Oct 16 03:47:48 2013 +0000 +++ b/displayModes.cpp Sat Oct 19 15:38:44 2013 +0000 @@ -500,8 +500,9 @@ } } - msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target and Regen + msg = lastMsg[indexLastMsg[0x1d5]]; //Get Regen regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5); + msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5); msg = lastMsg[indexLastMsg[0x421]]; //Get Drive Mode if (msg.data[0]==0x18) { // In Neutral
--- a/main.cpp Wed Oct 16 03:47:48 2013 +0000 +++ b/main.cpp Sat Oct 19 15:38:44 2013 +0000 @@ -2,7 +2,7 @@ // //To Do: // * Add 50% charge option -// * Add coasting regen to regen/braking display +// * Add coasting regen to regen/braking display; fix regen display to show actual instead of target regen (EX: on 100% charge) // * Add linear efficiency graph with 10 minute values // * Subtract accessory power from efficiency history (add back in when displaying) // * Add in-device config editor @@ -12,19 +12,22 @@ // * Add heater activation warning message // * Add trip max/min efficiency reset -// rev154 -// Added mute button to upper right corner for quick access +// rev155 +// Added workoaround to hardware limitation where changing pwm frequency for sound sometimes also deactivated the screen backlight +// Added ambient temperature to trip log +// Save Resr in history file so it doesn't reset to 75mOhms on CANary reset +// Changed regen to 1d5 message (appears to be closer to actual regen versus 1cb being target regen) +// Fixed Resr formatting in trip log so it show 3 decimal places #include "mbed.h" #include "CAN.h" -#include "beep.h" #include "ff.h" #include "PowerControl.h" #include "EthernetPowerControl.h" #include "utility.h" #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "154b"; // gg - revision string, max 6 characters +char revStr[7] = "155"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); @@ -53,7 +56,7 @@ AnalogIn mon12V(p15); TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset PwmOut dled(p23); -Beep spkr(p21); +PwmOut spkr(p21); bool debugMode = false; bool usbEn = false; @@ -62,6 +65,7 @@ bool yesBattLog = true; // gg - Batt Log unsigned char tNavRow = 3; // gg - 4x4 touch bool brakeMon = false; // disable until desired value read from config +bool regenMon = false; bool autoSync = false; // auto clock sync on powerup bool syncDone = true; @@ -178,7 +182,9 @@ } touchpad.rise(&touch_ISR); tt.wfi(); // enable interrupt on touch + dled.period(0.001); dled = ledHi; // turn on display LED 80% + spkr = 0; Resr = 0.075; // initial guess of Resr timer.start() ; RTC_Init(); // start the RTC Interrupts that sync the timer @@ -216,6 +222,9 @@ if(!feof(hfile)){ fscanf(hfile,"%f %f\r\n",&maxTripEff,&minTripEff); } + if(!feof(hfile)){ + fscanf(hfile,"%f\r\n",&Resr); + } fclose(hfile); printMsg("History Loaded.\n"); // History loaded } else { // create initial file @@ -262,9 +271,9 @@ sprintf(sTemp,"\nERR:%d Unable to open %s\n\n\n\n",efr,fileName); printMsg(sTemp); // cannot open alc file logEn=false; - if(enableSound) spkr.beep(1000,0.25); + beep(1000,0.25); wait_ms(500); - if(enableSound) spkr.beep(1000,0.25); + beep(1000,0.25); } else { logOpen = true; readPointer=writePointer; @@ -275,7 +284,7 @@ logEvent("Starting"); // Log startup msg for testing sprintf(sTemp,"Cr%s",revStr); logEvent(sTemp); // gg - log firmware version - if(enableSound) spkr.beep(2000,0.25); + beep(2000,0.25); } }//logging enabled and USB detected } else { // if (logOpen) @@ -285,12 +294,10 @@ if (efr != FR_OK) { logOpen = false; printMsg("Failed to append log file.\n"); // failed to append - if(enableSound) { - spkr.beep(3000,0.25); - spkr.beep(1500,0.25); - spkr.beep(750,0.25); - spkr.beep(375,0.25); - } + beep(3000,0.25); + beep(1500,0.25); + beep(750,0.25); + beep(375,0.25); logEn=false; } else { while (readPointer != writePointer) { @@ -482,7 +489,7 @@ } else if (dMode[whichTouched]==configScreen) { dMode[whichTouched]=mainScreen; saveConfig(); - if(enableSound) spkr.beep(2000,0.25); + beep(2000,0.25); } else if (dMode[whichTouched]==playbackScreen) { // faster if(playbackInt>.002){ playbackInt/=2; @@ -513,6 +520,7 @@ sMode=0; } else { enableSound = !enableSound; + if(!enableSound) spkr=0; } break; @@ -554,13 +562,13 @@ lastDMode[whichTouched]=99;//force refresh if(efr != FR_OK){ printMsg("Unable to open /usb/playback.alc\n"); // no playback.alc - if(enableSound) spkr.beep(1000,0.25); + beep(1000,0.25); } else { playbackOpen = true; playbackEn=true; playback.attach(&playbackISR,playbackInt); printMsg("Starting playback\n"); // start playback - if(enableSound) spkr.beep(2000,0.25); + beep(2000,0.25); can1.attach(NULL);// Stop recieving EVCAN data can2.attach(NULL);// Stop recieving CARCAN data } @@ -712,11 +720,11 @@ // Sound tone on power reversal idir=(kW[0]>0)?true:false; - if(enableSound){ + if(regenMon){ if (idir&&!lidir){ - spkr.beep(800,0.021); // Started sinking current + beep(800,0.02); // Started sinking current }else if(!idir&&lidir){ - spkr.beep(3200,0.021); // Started regen + beep(3200,0.02); // Started regen } } lidir=idir; @@ -762,6 +770,7 @@ fprintf(hfile,"%f %f\r\n",mph[i],kW[i]); } fprintf(hfile,"%f %f\r\n",maxTripEff,minTripEff); // Save max and min + fprintf(hfile,"%f \r\n",Resr); // Save series resistance fclose(hfile); } } @@ -914,7 +923,7 @@ f_close(&efile); // restart efr = f_open(&efile,"playback.alc",FA_READ|FA_OPEN_EXISTING); lastDMode[whichTouched]=99;//force refresh - if(enableSound) spkr.beep(2000,0.25); + beep(2000,0.25); } } }
--- a/utility.cpp Wed Oct 16 03:47:48 2013 +0000 +++ b/utility.cpp Sat Oct 19 15:38:44 2013 +0000 @@ -2,6 +2,7 @@ #include "utility.h" unsigned long brkMonRate = 400000; unsigned short brkMonThr = 4000; +Timeout beepOff; void mbed_reset(); @@ -139,7 +140,7 @@ // We previously lost messages that did not get into the buffer sprintf(sTemp,"-- Lost %d Messages.\n", nLost); printMsg(sTemp); // write buffer overrun - //if(enableSound) spkr.beep(500,0.25); + //beep(500,0.25); nLost = 0 ; } @@ -170,7 +171,7 @@ if (writePointer==readPointer) { // Just caught up to read pointer printMsg("Write buffer overrun.\n"); // write buffer overrun - if(enableSound) spkr.beep(500,0.25); + beep(500,0.25); } } } @@ -546,7 +547,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)); + fprintf(cfile,"brakeMon %d\r\n",(brakeMon?2:0)+(regenMon?1:0)); fprintf(cfile,"brkMonRate %d\r\n", brkMonRate ); fprintf(cfile,"brkMonThr %d\r\n", brkMonThr ); for(char i=0;i<8;i++){ @@ -580,7 +581,7 @@ 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 config file to USB\n"); + printMsg("Copy ehist file to USB\n"); while (!feof(cfile)) { bytesRW=fread(buffer, 1, bufSize, cfile); @@ -648,8 +649,9 @@ showHealth = (bool)readBool; } if(ff>6){ - fscanf(cfile, "brakeMon %d\r\n", &readBool ); - brakeMon = (bool)readBool; + fscanf(cfile, "brakeMon %d\r\n", &readBool ); + brakeMon = (bool)(readBool&1); + regenMon = (bool)(readBool&2); fscanf(cfile, "brkMonRate %d\r\n", &brkMonRate ); fscanf(cfile, "brkMonThr %d\r\n", &brkMonThr ); } @@ -693,6 +695,7 @@ fwCount=1; showHealth=true; brakeMon=true; + regenMon=true; brkMonRate=400000; brkMonThr=4000; uMsgId[0]=0x5103; @@ -866,6 +869,7 @@ void tripLog() { // Daily log char sTemp[40]; + unsigned char ambient; struct tm t; // pointer to a static tm structure short unsigned max, min, jv, i, bd; unsigned avg; @@ -879,6 +883,8 @@ seconds = time(NULL); // Turbo3 t = *localtime(&seconds) ; // Turbo3 + msg = lastMsg[indexLastMsg[0x54c]]; //Get ambient + ambient = msg.data[6]-56; msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids gids = (msg.data[0]<<2)+(msg.data[1]>>6); msg = lastMsg[indexLastMsg[0x5c5]]; //Get odometer @@ -911,10 +917,11 @@ bfr = f_open(&bfile,"triplog.txt",FA_WRITE|FA_OPEN_ALWAYS); if(bfr==FR_OK) { f_lseek(&bfile,0xffffffff); // go to end of file to append + // timestamp, odometer, accV, gids, SOC, SOH2, Ah, Vbatt, Ibatt, Rest, maxCP, minCP, avgCO, maxCP-minCP, CVLI_jv, miles_trip, kWh_trip, ambient, T1raw, T1, T2raw, T2, T3raw, T3, T4raw, T4, CP1, CP2, ... , CP96 strftime(sTemp, 40, "%a %m/%d/%Y %X", &t); f_printf(&bfile,"%s,",sTemp); - sprintf(sTemp,"%d,%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%4.1f,%d,%d,%d,%d,%d,%4.1f,%4.1f",odo,accV,gids,(float)SOC/10, (float)SOH2_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,Resr,max,min,avg,max-min,jv,miles_trip[0],kWh_trip[0]); - f_printf(&bfile,"%s,",sTemp); + sprintf(sTemp,"%d,%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%4.3f,%d,%d,%d,%d,%d,%4.1f,%4.1f",odo,accV,gids,(float)SOC/10, (float)SOH2_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,Resr,max,min,avg,max-min,jv,miles_trip[0],kWh_trip[0]); + f_printf(&bfile,"%s,%d,",sTemp,ambient); 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++) { @@ -1062,12 +1069,30 @@ return(usbEn); } +void spkrOff(void){ + spkr=0; + dled.period(.001); +} + +void beep(float freq, float time){ + if (enableSound) { + spkr.period(1.0/freq); + spkr=0.5; + if(!headlights){ + dled = ledHi; + } else { + dled = ledLo; + } + beepOff.attach(&spkrOff, time); + } +} + void chirp(void){ static unsigned short counter=0; if(chirpInt>0){ if(++counter>chirpInt){ - if(enableSound) spkr.beep(1600,0.015); + beep(1600,0.015); counter=0; } }else{
--- a/utility.h Wed Oct 16 03:47:48 2013 +0000 +++ b/utility.h Sat Oct 19 15:38:44 2013 +0000 @@ -3,7 +3,6 @@ #include "CAN.h" #include "common.h" #include "TOUCH_TFTx2.h" -#include "beep.h" #include <cctype> #include "ff.h" @@ -52,7 +51,6 @@ extern unsigned short numSsamples; extern unsigned char skin; extern unsigned char dtePeriod; -extern Beep spkr; extern unsigned char reqMsgCnt; extern float maxTemp; extern unsigned long Ah_x10000; @@ -73,8 +71,10 @@ extern bool showHealth; extern float kWh_trip[0]; extern float miles_trip[0]; -extern Beep spkr; +extern PwmOut dled; // for test +extern PwmOut spkr; extern bool brakeMon; +extern bool regenMon; extern Ticker geiger; extern unsigned short chirpInt; extern unsigned short uMsgId[8]; @@ -110,6 +110,7 @@ void updateFirmware(); // LM - Update firmware off USB bool detectUSB(); void chirp(); + void beep(float freq, float time); } //LEAF OBD