test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Diff: main.cpp
- Revision:
- 154:90ea16ca7475
- Parent:
- 153:e94cfe3c339c
- Child:
- 155:f31006516956
diff -r e94cfe3c339c -r 90ea16ca7475 main.cpp --- a/main.cpp Sat Oct 12 03:48:30 2013 +0000 +++ b/main.cpp Wed Oct 16 03:47:48 2013 +0000 @@ -12,9 +12,8 @@ // * Add heater activation warning message // * Add trip max/min efficiency reset -// rev153 -// Added current reversal tone -// Added MY2013 autoSync support (just time - no date) +// rev154 +// Added mute button to upper right corner for quick access #include "mbed.h" #include "CAN.h" @@ -25,7 +24,7 @@ #include "utility.h" #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "153"; // gg - revision string, max 6 characters +char revStr[7] = "154b"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); @@ -158,6 +157,7 @@ unsigned short uMsgId[8] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}; // messages to display on debug screen msgId:byte unsigned short modelYear = 2011; bool idir, lidir; +bool enableSound=false; int main() { char sTemp[40]; @@ -178,7 +178,7 @@ } touchpad.rise(&touch_ISR); tt.wfi(); // enable interrupt on touch - dled = 0.8; // turn on display LED 80% + dled = ledHi; // turn on display LED 80% Resr = 0.075; // initial guess of Resr timer.start() ; RTC_Init(); // start the RTC Interrupts that sync the timer @@ -262,9 +262,9 @@ sprintf(sTemp,"\nERR:%d Unable to open %s\n\n\n\n",efr,fileName); printMsg(sTemp); // cannot open alc file logEn=false; - spkr.beep(1000,0.25); + if(enableSound) spkr.beep(1000,0.25); wait_ms(500); - spkr.beep(1000,0.25); + if(enableSound) spkr.beep(1000,0.25); } else { logOpen = true; readPointer=writePointer; @@ -275,7 +275,7 @@ logEvent("Starting"); // Log startup msg for testing sprintf(sTemp,"Cr%s",revStr); logEvent(sTemp); // gg - log firmware version - spkr.beep(2000,0.25); + if(enableSound) spkr.beep(2000,0.25); } }//logging enabled and USB detected } else { // if (logOpen) @@ -285,10 +285,12 @@ if (efr != FR_OK) { logOpen = false; printMsg("Failed to append log file.\n"); // failed to append - spkr.beep(3000,0.25); - spkr.beep(1500,0.25); - spkr.beep(750,0.25); - spkr.beep(375,0.25); + if(enableSound) { + spkr.beep(3000,0.25); + spkr.beep(1500,0.25); + spkr.beep(750,0.25); + spkr.beep(375,0.25); + } logEn=false; } else { while (readPointer != writePointer) { @@ -343,7 +345,7 @@ secsNoTouch=2; carCanIdle=secsNoCarCanMsg>canTimeout; evCanIdle=secsNoEvCanMsg>canTimeout; - dled=0.8; // turn on display LED + dled=ledHi; // turn on display LED seconds = time(NULL); t = *localtime(&seconds) ; strftime(sTemp, 40, "Waking: %a %m/%d/%Y %X\n", &t); @@ -480,7 +482,7 @@ } else if (dMode[whichTouched]==configScreen) { dMode[whichTouched]=mainScreen; saveConfig(); - spkr.beep(2000,0.25); + if(enableSound) spkr.beep(2000,0.25); } else if (dMode[whichTouched]==playbackScreen) { // faster if(playbackInt>.002){ playbackInt/=2; @@ -510,7 +512,7 @@ dMode[whichTouched] = healthScreen ; // Goto health screen sMode=0; } else { - lastDMode[whichTouched]=99;//repaint to clear highlight + enableSound = !enableSound; } break; @@ -552,13 +554,13 @@ lastDMode[whichTouched]=99;//force refresh if(efr != FR_OK){ printMsg("Unable to open /usb/playback.alc\n"); // no playback.alc - spkr.beep(1000,0.25); + if(enableSound) spkr.beep(1000,0.25); } else { playbackOpen = true; playbackEn=true; playback.attach(&playbackISR,playbackInt); printMsg("Starting playback\n"); // start playback - spkr.beep(2000,0.25); + if(enableSound) spkr.beep(2000,0.25); can1.attach(NULL);// Stop recieving EVCAN data can2.attach(NULL);// Stop recieving CARCAN data } @@ -710,14 +712,14 @@ // Sound tone on power reversal idir=(kW[0]>0)?true:false; - if(brakeMon){ + if(enableSound){ if (idir&&!lidir){ - spkr.beep(3200,0.03); // Started sinking current + spkr.beep(800,0.021); // Started sinking current }else if(!idir&&lidir){ - spkr.beep(800,0.03); // Started regen + spkr.beep(3200,0.021); // Started regen } - lidir=idir; } + lidir=idir; if(tick){ // Executes once a second tick=false; @@ -847,13 +849,13 @@ // Compute ESR if((Imax-Imin)<40){ // do nothing - insufficient delta_I to measure unloadedV_x2 = (curRmax+curRmin)/2; - }else if ((redRmax-redRmin)<(curRmax-curRmin)) { + }else if ((redRmax-redRmin)<(curRmax-curRmin)) { // less variation on reduced Resr Resr-=0.001; unloadedV_x2 = (redRmax+redRmin)/2; - } else if ((incRmax-incRmin)<(curRmax-curRmin)) { + } else if ((incRmax-incRmin)<(curRmax-curRmin)) { // less variation on increased Resr Resr+=0.001; unloadedV_x2 = (incRmax+incRmin)/2; - } else { + } else { // current Resr is still best answer unloadedV_x2 = (curRmax+curRmin)/2; } curRmin=1000; @@ -912,7 +914,7 @@ f_close(&efile); // restart efr = f_open(&efile,"playback.alc",FA_READ|FA_OPEN_EXISTING); lastDMode[whichTouched]=99;//force refresh - spkr.beep(2000,0.25); + if(enableSound) spkr.beep(2000,0.25); } } }