.

Dependencies:   SDHCFileSystem mbed

Revision:
12:7cd4e9303165
Parent:
11:d97071bf877b
Child:
13:544b15b00c2d
--- a/main.cpp	Sun Dec 09 22:40:03 2012 +0000
+++ b/main.cpp	Sat Dec 15 23:47:34 2012 +0000
@@ -109,6 +109,7 @@
 FILE *file;
 char fileName[32] = "" ;
 char writeBuffer[maxBufLen][13];
+char sTemp[35] ;
 volatile int writePointer = 0;
 volatile int secsIdle = canTimeout;
 volatile bool canIdle = true;
@@ -219,6 +220,40 @@
     timer.start() ;
     RTC_Init(); // start the RTC Interrupts that sync the timer
     wait(1.1);  // give time to sync
+ 
+    //--------------------------
+    // check for 2012 or later
+
+    struct tm t; // pointer to a static tm structure
+
+    seconds = time(NULL);
+    t = *localtime(&seconds) ;
+
+    // is it a date before 2012 ?
+    if ((t.tm_year + 1900) < 2012 ) {
+        // before 2012, so the RTC probably lost power
+        // So, set a near-recent date in 2012
+
+        // enter people-values here
+        t.tm_year = 2012 ; // 28 May 2012
+        t.tm_mon = 6 ; // 1 to 12
+        t.tm_mday = 1;
+        t.tm_hour = 12; // 12:59:56 PM (after noon)
+        t.tm_min = 59;
+        t.tm_sec = 56;
+
+        // adjust for tm structure required values
+        t.tm_year = t.tm_year - 1900;
+        t.tm_mon = t.tm_mon - 1;
+
+        // set the RTC
+        set_time(mktime(&t));
+        seconds = time(NULL);
+
+        pc.printf("Set RTC to:\n" );
+        strftime(sTemp, 32, "%a %m/%d/%Y %X", localtime(&seconds));
+        pc.printf("%s\n", sTemp); // DAY MM/DD/YYYY HH:MM:SS
+    }
 
     while (true) {
         if(CD == 1) {