Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: TimeUtilities.cpp
- Revision:
- 3:524ad47afdc7
- Parent:
- 2:cbcdd97f3a6d
- Child:
- 5:fbbdf57675c3
--- 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