test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Diff: main.cpp
- Revision:
- 155:f31006516956
- Parent:
- 154:90ea16ca7475
- Child:
- 156:4e5d30535cf9
diff -r 90ea16ca7475 -r f31006516956 main.cpp --- 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); } } }