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

Revision:
140:ab3e94eb0227
Parent:
139:ac227b203ef2
Child:
141:cf13a632ddb5
--- a/main.cpp	Fri Aug 02 14:11:23 2013 +0000
+++ b/main.cpp	Sun Aug 04 14:57:40 2013 +0000
@@ -10,8 +10,10 @@
 // * Subtract accessory power from efficiency history (add back in when displaying)
 // * Add trip history display
 
-// rev139
-// Fixed right justify (compare to 9.5, 99.5 instead of 10, 100)
+// rev140
+// Added odometer to batt and trip log
+// Added mi/km detection from dash
+// Added audible brake monitor
 
 #include "mbed.h"
 #include "CAN.h"
@@ -22,8 +24,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-
-char revStr[7] = "139"; // gg - revision string, max 6 characters
+char revStr[7] = "140"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -36,6 +37,7 @@
 Ticker autoPoll;
 Ticker playback;
 Ticker msgReq;
+Ticker geiger;
 Timer timer;
 
 DigitalOut led1(LED1);
@@ -59,6 +61,8 @@
 bool logOpen = false; 
 bool yesBattLog = true; // gg - Batt Log
 unsigned char tNavRow = 3; // gg - 4x4 touch
+bool brakeMon = false;  // disable until desired value read from config
+unsigned char bp;
 
 FILE *hfile; // history file
 FIL efile; // external usb file
@@ -95,6 +99,7 @@
 bool logOnce = false;
 bool repeatPoll = true;
 bool headlights = false;
+bool miles_kmbar = true;
 bool tick = false;
 bool ZeroSecTick = false;
 float ledHi = 0.8; // Bright LED value (until config file read)
@@ -145,6 +150,7 @@
 bool showHealth=false;
 unsigned char saveDmode=99;
 bool moving=false;
+unsigned short chirpInt;
 
 int main() {
     char sTemp[40];
@@ -220,6 +226,9 @@
 
     // Read config file
     readConfig();
+    if (brakeMon){
+        geiger.attach(&chirp,0.02);
+    }
     if (repeatPoll) { // enable autopolling if enabled
         autoPoll.attach(&autoPollISR,pollInt);
     }
@@ -605,9 +614,12 @@
                                 if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = playbackScreen ; // GoTo Playback Screen                                    
                                 } else if (dMode[whichTouched]==configScreen) {
-                                    metric = !metric; // toggle metric/imperial display
-                                    lastDMode[0]=99;//repaint
-                                    lastDMode[1]=99;//repaint
+                                    brakeMon = !brakeMon;
+                                    if(brakeMon){
+                                        geiger.attach(&chirp,0.02);
+                                    }else{
+                                        geiger.detach();
+                                    }
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                 }            
@@ -694,6 +706,8 @@
         if(tick){ // Executes once a second
             tick=false;
             headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false;  // headlight/turn signal indicator
+            miles_kmbar = (lastMsg[indexLastMsg[0x355]].data[4]&0x20)?true:false;  // indicates selected distance units
+            metric = !miles_kmbar;
             accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th
             accOn=(accV>5)?true:false;
             moving=(mph[0]>0.1);
@@ -863,9 +877,6 @@
             }
             tock=true;
         } // tick
-
-        display=display<1?display+1:0; // toggle display
-        updateDisplay(display);
         
         if(step){ // playback
             if(playbackOpen&&playbackEn){
@@ -885,5 +896,7 @@
             step=false;
         }
 
+        display=display<1?display+1:0; // toggle display
+        updateDisplay(display);
     } //while (true)
 }
\ No newline at end of file