Dual CANbus monitor and instrumentation cluster

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed

Fork of CANary by Tick Tock

Branch:
Metric
Revision:
115:549410af477d
Parent:
114:3f8c59a8a2b9
Child:
116:5cd72bae7c12
--- a/main.cpp	Tue Jul 02 02:57:36 2013 +0000
+++ b/main.cpp	Thu Jul 04 00:09:28 2013 +0000
@@ -24,11 +24,12 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "114"; // gg - revision string, max 6 characters
+char revStr[7] = "115"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
 bool waitasec = true;
+unsigned char wait5secs = 5;
 // to write to USB Flash Drives, or equivalent (SD card in Reader/Writer)
 FRESULT mfr = f_mount(0,&USBdrive);
 time_t seconds ;
@@ -57,7 +58,7 @@
 bool usbEn = false;
 bool logEn = true;
 bool logOpen = false; 
-bool yesBattLog = false; // gg - Batt Log
+bool yesBattLog = true; // gg - Batt Log
 unsigned char tNavRow = 3; // gg - 4x4 touch
 
 FILE *hfile; // history file
@@ -693,25 +694,28 @@
             if(!laccOn&&accOn){ // Car turned on
                 miles_trip[0]=0;
                 kWh_trip[0]=0;
-                if (repeatPoll) { // Poll on startup if autopoll enabled
+                wait5secs=5;
+            }
+            laccOn=accOn;
+            if(!accOn&&!logEn&&userIdle&&!playbackEn){ // Car off and logging disabled and no user activity
+                dled = 0; 
+            }else if(!headlights){
+                dled = ledHi;
+            } else {
+                dled = ledLo;
+            }
+            if(wait5secs>0){ // Wait a few seconds after poweron to give BMS time to measure CP's
+                wait5secs-=1;
+                if (repeatPoll&&(wait5secs==0)) { // Poll on startup if autopoll enabled
                     logOnce=true;
                     reqMsgCnt=0;
                     msgReq.attach(&sendReq,0.015);
                 }
             }
-            laccOn=accOn;
-            if(!accOn&&!logEn&&userIdle&&!playbackEn){             
-                dled = 0; // turn off display if car off and logging disabled and no user activity
-            }else if(!headlights){
-                dled = ledHi;
-            } else {
-                dled = ledLo;
-            }
-            
+
             //compute historic efficiency
             if(numSsamples>0){ // Avoid div0
-                //mph[0]=((float) motorRPM)/numSsamples/215; // Empirically derived - may change car to car
-                mph[0]=((float) motorRPM)/numSsamples/219; // Empirically derived - may change car to car
+                mph[0]=((float) motorRPM)/numSsamples/220; // Empirically derived with MXV4s - may change with different wheels&tires
             } else {
                 mph[0]=0;
             }