Pseudo real-time clock using Ticker interruption, also implements time() and set_time() for platforms that don't (such as mBuino)

Fork of PseudoRTC by Shigenori Inoue

Files at this revision

API Documentation at this revision

Comitter:
maxint
Date:
Mon Aug 03 10:29:25 2015 +0000
Parent:
2:7d153bc7403f
Commit message:
bugfix; month was one off (note: tm_mon in struct tm is 0 to 11, month in PseudoRTC is 1-12!)

Changed in this revision

PseudoRTC.cpp Show annotated file Show diff for this revision Revisions of this file
PseudoRTC.h Show annotated file Show diff for this revision Revisions of this file
--- a/PseudoRTC.cpp	Mon Aug 03 09:04:48 2015 +0000
+++ b/PseudoRTC.cpp	Mon Aug 03 10:29:25 2015 +0000
@@ -59,7 +59,7 @@
     minute=ptm->tm_min;
     hour=ptm->tm_hour;
     day=ptm->tm_mday;
-    month=ptm->tm_mon;
+    month=ptm->tm_mon+1;
     year=ptm->tm_year+1900;
 }
 
@@ -125,7 +125,7 @@
     tms.tm_min=minute;
     tms.tm_hour=hour;
     tms.tm_mday=day;
-    tms.tm_mon=month;
+    tms.tm_mon=month-1;
     tms.tm_year=year-1900;
     return(mktime(&tms));
 }
--- a/PseudoRTC.h	Mon Aug 03 09:04:48 2015 +0000
+++ b/PseudoRTC.h	Mon Aug 03 10:29:25 2015 +0000
@@ -30,9 +30,17 @@
  *
  * main()
  * {
- *     // Example: September 20, 2014, 21:05:30
- *     c.setTime(2014, 09, 20, 21, 05, 30);
- * 
+ *    time_t seconds;
+ *    char buffer[32];
+ *    c.set_time(1256729737);   // Set RTC time to Wed, 28 Oct 2009 11:35:37 (NOW WORKING ON mBuino)
+ *
+ *    seconds=c.time(NULL);
+ *    printf("Time as seconds since January 1, 1970 = %d\r\n", seconds);
+ *    printf("Time as a basic string = %s\r", ctime(&seconds));   // ctime includes \n
+ *    strftime(buffer, 32, "%I:%M %p", localtime(&seconds));
+ *    printf("Time as a custom formatted string = %s\r\n", buffer);
+ *
+ *     c.setTime(2014, 09, 20, 21, 05, 30);      // Second example: September 20, 2014, 21:05:30
  *     while(true) {
  *         printf("%04d/%02d/%02d %02d:%02d:%02d\r\m", c.getYear(), c.getMonth(), c.getDay(), c.getHour(), c.getMinute(), c.getSecond());
  *         wait(1);
@@ -51,11 +59,11 @@
 
     /** Set time in the pseudo real-time clock
      * @param y Year
-     * @param mo Month
-     * @param d Day
-     * @param h Hour
-     * @param m Minute
-     * @param s Second
+     * @param mo Month (1-12)
+     * @param d Day (1-31)
+     * @param h Hour (0-23)
+     * @param m Minute (0-59)
+     * @param s Second (0-59)
      */
     void setTime(int y, int mo, int d, int h, int mi, int s);