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:
Sun Aug 04 20:39:16 2013 +0000
Parent:
140:ab3e94eb0227
Child:
142:c1a11d6f181c
Commit message:
tweaked brakeMon sensitivity and threshold

Changed in this revision

common.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
--- a/common.h	Sun Aug 04 14:57:40 2013 +0000
+++ b/common.h	Sun Aug 04 20:39:16 2013 +0000
@@ -38,4 +38,3 @@
 #define VP230Sleep 0 // Set to 0 if using VP231 (sleep disables RX)
 
 #define minTirePressure 128 // 34psi X 4
-#define brkMonRate 40000 // larger = slower chirp rate
\ No newline at end of file
--- a/main.cpp	Sun Aug 04 14:57:40 2013 +0000
+++ b/main.cpp	Sun Aug 04 20:39:16 2013 +0000
@@ -10,10 +10,9 @@
 // * Subtract accessory power from efficiency history (add back in when displaying)
 // * Add trip history display
 
-// rev140
-// Added odometer to batt and trip log
-// Added mi/km detection from dash
-// Added audible brake monitor
+// rev141
+// tweaked brakeMon sensitivity and threshold
+
 
 #include "mbed.h"
 #include "CAN.h"
@@ -24,7 +23,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "140"; // gg - revision string, max 6 characters
+char revStr[7] = "141"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -62,7 +61,6 @@
 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
@@ -79,8 +77,8 @@
 char c;
 volatile int writePointer = 0;
 int readPointer=0;
-volatile unsigned short secsNoCarCanMsg = 0;
-volatile unsigned short secsNoEvCanMsg = 0;
+volatile unsigned short secsNoCarCanMsg = canTimeout;
+volatile unsigned short secsNoEvCanMsg = canTimeout;
 volatile unsigned short secsNoTouch = 0;
 volatile bool carCanIdle,evCanIdle,userIdle;
 bool touched=false; //flag to read touchscreen
@@ -197,9 +195,6 @@
     sprintf(sTemp,"CANary firmware rev%s\n", revStr); // gg - for Logging the revision
     printMsg(sTemp); // revision
 
-    secsNoCarCanMsg = 0;
-    secsNoEvCanMsg = 0;
-
     //read efficiency history data
     hfile = fopen("/local/ehist.cny", "r");
     if (hfile!=NULL){ // found a efficiency history file
@@ -706,8 +701,10 @@
         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;
+            if(indexLastMsg[0x355]>0){
+                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);
--- a/utility.cpp	Sun Aug 04 14:57:40 2013 +0000
+++ b/utility.cpp	Sun Aug 04 20:39:16 2013 +0000
@@ -1,5 +1,7 @@
 // utility.cpp
 #include "utility.h"
+unsigned long brkMonRate = 400000;
+unsigned short brkMonThr = 2000;
 
 void mbed_reset();
 
@@ -354,7 +356,7 @@
         }else if((mType==2)&&(canRXmsg.id==0x1ca)){ //Brake Pressure
             if(brakeMon){
                 if(canRXmsg.data[0]<0xff){
-                    if((canRXmsg.data[0]==0)||(imotorRPM==0)){
+                    if((canRXmsg.data[0]*imotorRPM)<brkMonThr){
                         chirpInt=0;
                     }else{
                         chirpInt=brkMonRate/imotorRPM;
@@ -535,6 +537,8 @@
     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,"brkMonRate %d\r\n", brkMonRate );            
+    fprintf(cfile,"brkMonThr %d\r\n", brkMonThr );            
     fclose(cfile);
 }
 
@@ -586,7 +590,7 @@
         if(ff>4) {
             int iMetric;
             fscanf(cfile, "metric %d\r\n", &iMetric );            
-            //metric = (bool)iMetric;
+            metric = (bool)iMetric; // This will get re-assigned based on dash selection
             fscanf(cfile, "firmware %d\r\n", &iMetric );
             fwCount = iMetric;
         }
@@ -599,6 +603,8 @@
             int iBrakeMon;
             fscanf(cfile, "brakeMon %d\r\n", &iBrakeMon );            
             brakeMon = (bool)iBrakeMon;
+            fscanf(cfile, "brkMonRate %d\r\n", &brkMonRate );        
+            fscanf(cfile, "brkMonThr %d\r\n", &brkMonThr );            
         }
         fclose(cfile);
         if(ff<7){//If not latest format, save as latest format
@@ -908,9 +914,8 @@
     static unsigned short counter=0;
     
     if(chirpInt>0){
-        counter++;
-        if(counter>chirpInt){
-            spkr.beep(500,0.01);
+        if(++counter>chirpInt){
+            spkr.beep(500,0.015);
             counter=0;
         }
     }
@@ -940,4 +945,7 @@
 brakeMon 0
 firmware 11
 showHealth 1
+brakeMon 1
+brkMonRate 400000
+brkMonThr 2000
 */
\ No newline at end of file