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:
20:3bf176d14b14
Parent:
19:d576298c46f3
Child:
21:22bdce9efcb5
--- a/main.cpp	Thu Mar 07 04:39:23 2013 +0000
+++ b/main.cpp	Fri Mar 08 04:17:30 2013 +0000
@@ -56,8 +56,10 @@
 unsigned char msgChanged[100]; // inidcates which bytes changed
 char c;
 volatile int writePointer = 0;
-volatile int secsNoMsg = 0, secsNoTouch = 0;
-volatile bool canIdle = false, userIdle = false;
+volatile int secsNoMsg = 0;
+volatile int secsNoTouch = 0;
+volatile bool canIdle;
+volatile bool userIdle;
 bool touched=0; //flag to read touchscreen
 char counter = 0;
 unsigned char dMode[2] = {1,7}; //display mode
@@ -100,8 +102,8 @@
     NVIC_SetPriority(CAN_IRQn, 2); //higher than can (so RTC sync works)
     seconds = time(NULL);
     t = *localtime(&seconds) ;
-    strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t);
-    logMsg(sTemp);
+    secsNoMsg = 0;
+    secsNoTouch = 0;
 
     // is it a date before 2012 ?
     if ((t.tm_year + 1900) < 2012 ) {
@@ -127,6 +129,9 @@
         //    strftime(sTemp, 32, "%a %m/%d/%Y %X", localtime(&seconds));
         //    printf("%s\n", sTemp); // DAY MM/DD/YYYY HH:MM:SS
     }
+    t = *localtime(&seconds) ;
+    strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t);
+    logMsg(sTemp);
 
     // Look for new binary 
     // Can't make this work right now since USB doesn't attach the right timestamp (so new binary isn't loaded)
@@ -248,7 +253,10 @@
             if (logOpen){
                 fclose(file);
             } // if (logOpen)*/
-            sprintf(sTemp,"Putting uC to sleep.\n");
+            //sprintf(sTemp,"Putting uC to sleep.\n");
+            seconds = time(NULL);
+            t = *localtime(&seconds) ;
+            strftime(sTemp, 32, "Sleeping: %a %m/%d/%Y %X\n", &t);
             logMsg(sTemp);
             //LPC_RTC->CIIR=0x00; // block RTC interrupts
             led1=0;
@@ -265,9 +273,12 @@
                 //DeepPowerDown();
             }
             canIdle=secsNoMsg>canTimeout;
-            userIdle=userIdle>userTimeout;
+            userIdle=secsNoTouch>userTimeout;
             dled=0.8; // turn on display LED
-            sprintf(sTemp,"Waking uC.\n");
+            //sprintf(sTemp,"Waking uC.\n");
+            seconds = time(NULL);
+            t = *localtime(&seconds) ;
+            strftime(sTemp, 32, "Waking: %a %m/%d/%Y %X\n", &t);
             logMsg(sTemp);
             if (time(NULL)>(secs+1800)) {
                 logOpen = false; // Start new file if asleep for more than 30 minutes