Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller

Dependencies:   SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Wed Oct 16 03:47:48 2013 +0000
Parent:
153:e94cfe3c339c
Child:
155:f31006516956
Commit message:
// Added mute button to upper right corner for quick access

Changed in this revision

displayModes.cpp Show annotated file Show diff for this revision Revisions of this file
displayModes.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
utility.cpp Show annotated file Show diff for this revision Revisions of this file
utility.h Show annotated file Show diff for this revision Revisions of this file
--- a/displayModes.cpp	Sat Oct 12 03:48:30 2013 +0000
+++ b/displayModes.cpp	Wed Oct 16 03:47:48 2013 +0000
@@ -1395,58 +1395,78 @@
                 // col 1 see below
                 showButton(2,tNavRow," Go To"," Index",4,4); // gg - index
                 showButton(3,tNavRow," Next->","",4,4); // gg - move next
-                
+                 if (enableSound) {
+                    sprintf(sTemp1," Mute");
+                } else {
+                    sprintf(sTemp1,"Un-Mute");
+                }               
                 // col 1 in Nav row                              
                 switch (dMode[display]) {
                     case offScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"  Off");
                         break;
                     case logScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"  Log");
                         break;
                     case mainScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"  Main");
                         break;
                     case brakeScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"Braking");
                         break;
                     case dteScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"  DTE");
                         break;
                     case effScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"  Eff");
                         break;
                     case monitorScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2," Monitor");
                         break;
                     case changedScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"DeltaMon");
                         break;
                     case cpScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"CP Data");
                         break;
                     case configScreen:
                         sprintf(sTemp2," Config");
                         break;          
                     case playbackScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"Playback");
                         break;
                     case dateScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"Set Time");
                         break;
                     case cpHistScreen: // gg - hist
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"CP Hist");
                         break;
                     case cpBarScreen: // gg - cpbars
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"CP Bars");
                         break;
                     case tripScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2," Trip");
                         break;
                     case healthScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2,"Health");
                         break;
                     case testScreen:
+                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2," Test");
                         break;
                     case indexScreen: // gg - index
--- a/displayModes.h	Sat Oct 12 03:48:30 2013 +0000
+++ b/displayModes.h	Wed Oct 16 03:47:48 2013 +0000
@@ -66,6 +66,7 @@
 extern bool accOn;
 extern bool autoSync;
 extern unsigned short modelYear;
+extern bool enableSound;
 
 extern "C" {
     void printLast (bool force, bool showButtons);
--- 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);
                     }
                 }
             }
--- a/utility.cpp	Sat Oct 12 03:48:30 2013 +0000
+++ b/utility.cpp	Wed Oct 16 03:47:48 2013 +0000
@@ -139,7 +139,7 @@
                     // We previously lost messages that did not get into the buffer
                     sprintf(sTemp,"-- Lost %d Messages.\n", nLost);
                     printMsg(sTemp); // write buffer overrun
-                    //spkr.beep(500,0.25);
+                    //if(enableSound) spkr.beep(500,0.25);
                     
                     nLost = 0 ;
                 }
@@ -170,7 +170,7 @@
             if (writePointer==readPointer) {
                 // Just caught up to read pointer
                 printMsg("Write buffer overrun.\n"); // write buffer overrun
-                spkr.beep(500,0.25);
+                if(enableSound) spkr.beep(500,0.25);
             }
         }
     }
@@ -1067,7 +1067,7 @@
     
     if(chirpInt>0){
         if(++counter>chirpInt){
-            spkr.beep(1600,0.015);
+            if(enableSound) spkr.beep(1600,0.015);
             counter=0;
         }
     }else{
--- a/utility.h	Sat Oct 12 03:48:30 2013 +0000
+++ b/utility.h	Wed Oct 16 03:47:48 2013 +0000
@@ -80,6 +80,7 @@
 extern unsigned short uMsgId[8];
 extern bool autoSync;
 extern unsigned short modelYear;
+extern bool enableSound;
 
 extern "C" {
     void mbed_reset();