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:
153:e94cfe3c339c
Parent:
152:a4d66901785d
Child:
154:90ea16ca7475
--- a/utility.cpp	Sun Oct 06 14:49:09 2013 +0000
+++ b/utility.cpp	Sat Oct 12 03:48:30 2013 +0000
@@ -768,22 +768,36 @@
     set_time(mktime(&t));
 }
 
-void syncDateTime(){ // doesn't work on MY2013
+bool syncDateTime(){ // doesn't work on MY2013
     struct tm t; // pointer to a static tm structure
     time_t seconds ;
     CANMessage msg;
     seconds = time(NULL);
     t = *localtime(&seconds);
-    msg = lastMsg[indexLastMsg[0x5fa]];
-    t.tm_mon = (msg.data[5]>>4)-1;
-    t.tm_mday = msg.data[2]>>3;
-    msg = lastMsg[indexLastMsg[0x5fb]];
-    //t.tm_year = msg.data[1]; // Have not figured out where the year is
-    msg = lastMsg[indexLastMsg[0x5fc]];
-    t.tm_hour = msg.data[0]>>3;
-    t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
-    t.tm_sec = msg.data[1]>>2;
-    set_time(mktime(&t));
+    if(modelYear<2013){ //MY2011,2012
+        msg = lastMsg[indexLastMsg[0x5fa]];
+        t.tm_mon = (msg.data[5]>>4)-1;
+        t.tm_mday = msg.data[2]>>3;
+        msg = lastMsg[indexLastMsg[0x5fb]];
+        //t.tm_year = msg.data[1]; // Have not figured out where the year is
+        msg = lastMsg[indexLastMsg[0x5fc]];
+        t.tm_hour = msg.data[0]>>3;
+        t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
+        t.tm_sec = msg.data[1]>>2;
+    }else{ // model year 2013 or higher
+        msg = lastMsg[indexLastMsg[0x5f9]];
+        t.tm_hour = msg.data[5]>>3;
+        t.tm_min = msg.data[4];
+        msg = lastMsg[indexLastMsg[0x509]];
+        t.tm_sec = msg.data[2]>>2;
+    }
+    if((t.tm_mon>=0)&&(t.tm_mon<12)&&(t.tm_mday>0)&&(t.tm_mday<8)&&(t.tm_hour>=0)&&(t.tm_hour<24)&&(t.tm_min>=0)&&(t.tm_min<60)&&(t.tm_sec>=0)&&(t.tm_sec<60)){ // sanity check result before using
+        set_time(mktime(&t));
+        return(true);
+    }else{
+        return(false);
+    }
+
 }
 
 void logPackVoltages() { // Turbo3 - routine to dump CP values to text file
@@ -1053,7 +1067,7 @@
     
     if(chirpInt>0){
         if(++counter>chirpInt){
-            spkr.beep(500,0.015);
+            spkr.beep(1600,0.015);
             counter=0;
         }
     }else{
@@ -1063,7 +1077,7 @@
 
 //Sample CONFIG.TXT
 /*
-format 7
+format 9
 x0_off 5732
 y0_off 34009
 x0_pp 77