This is a library for managing the mbed real time clock, including functions for setting and getting the rtc in text format, getting and setting the timezone offset, and getting and setting the calibration register, both directly, and by using an adjustment API to automatically set the calibration value.

Dependents:   LAB4WEEK1 Motor

Revision:
3:524ad47afdc7
Parent:
2:cbcdd97f3a6d
Child:
5:fbbdf57675c3
diff -r cbcdd97f3a6d -r 524ad47afdc7 TimeUtilities.cpp
--- a/TimeUtilities.cpp	Wed Jun 08 11:36:11 2011 +0000
+++ b/TimeUtilities.cpp	Thu Jun 16 21:11:44 2011 +0000
@@ -16,6 +16,8 @@
 /// @author David Smart, Smartware Computing
 ///
 /// Version History
+/// 20110616
+/// \li minor documentation changes
 /// 20110601
 /// \li discovered the CCALEN flag to enable calibration
 /// 20110529
@@ -33,7 +35,7 @@
 #include <stdlib.h>
 
 #ifdef WIN32
-// Fake it out for Win32
+// Fake it out for Win32 development and testing
 struct LPC {
     unsigned long CCR;          // Clock Control register
     unsigned long GPREG0;       // General Purpose Register - Battery backed
@@ -175,88 +177,3 @@
     return success;
 }
 
-#if 0
-// GetNumber will get from the user a number using the
-/// specified number of digits.
-///
-/// They can enter a number from 0 to 10^(digits-1)
-///
-/// @param digits is the number of digits to enter
-/// @param pValue is a pointer to where to store the result
-/// @returns true if a number was entered
-/// @returns false if they entered a non-digit
-///
-int GetNumber(int digits, int * pValue) {
-    int tempValue = 0;
-    int i;
-
-    while (digits--) {
-        while (!pc.readable())
-            wdt.Service();
-        i = pc.getc();
-        if (i == ' ') i = '0';      // special case for leading blank
-        if (i >= '0' && i <= '9') {
-            pc.putc(i);
-            tempValue = tempValue * 10 + (i - '0');
-        } else
-            return false;
-    }
-    *pValue = tempValue;
-    return true;
-}
-
-/// RTC_Set will interactively set the Real Time Clock
-///
-/// It will allow you to enter the date and time information
-/// and then create a timestamp. After this, it will set
-/// the RTC to that timestamp.
-///
-void RTC_Set(void) {
-    time_t seconds = time(NULL);
-    struct tm *t = localtime(&seconds);
-
-    pc.printf("RTC Set:\r\n");
-    GetTimeString(seconds, tzOffsetHr, tzOffsetMin);
-    pc.printf("    Enter the time MM/DD/YYYY HH:MM:SS\r\n");
-    while (1) {
-        int _m, _d, _y, _H, _M, _S;
-        printf("                 > ");
-        if (GetNumber(2, &_m)) {
-            pc.putc('/');
-            if (!GetNumber(2, &_d))
-                continue;
-            pc.putc('/');
-            if (!GetNumber(4, &_y))
-                continue;
-            t->tm_mon = _m - 1;
-            t->tm_mday = _d;
-            t->tm_year = _y - 1900;
-        } else {
-            pc.printf("%02d/%02d/%04d", t->tm_mon+1, t->tm_mday, t->tm_year+1900);
-        }
-        pc.putc(' ');
-        if (GetNumber(2, &_H)) {
-            pc.putc(':');
-            if (!GetNumber(2, &_M))
-                continue;
-            pc.putc(':');
-            if (!GetNumber(2, &_S))
-                continue;
-            t->tm_hour = _H;
-            t->tm_min = _M;
-            t->tm_sec = _S;
-            pc.printf("\r\n");
-            pc.printf("%02d/%02d/%04d ", t->tm_mon+1, t->tm_mday, t->tm_year+1900);
-            pc.printf("%02d:%02d:%02d\r\n", t->tm_hour, t->tm_min, t->tm_sec);
-            // convert to timestamp and display (1256729737)
-            time_t seconds = mktime(t);
-            seconds = seconds - (time_t)(tzOffsetHr * 3600 + tzOffsetMin * 60);
-            set_time(seconds);
-            break;
-        } else {
-            pc.printf("%02d:%02d:%02d\r\n", t->tm_hour, t->tm_min, t->tm_sec);
-            break;          // they can bail here
-        }
-    }
-}
-#endif