Function to convert compiler macro __DATE__ and __TIME__ to a system time that can be used to initialize the CPU RTC. I use this to do a 1 time initialization of a RTC chip.
Dependents: xj-Init-clock-to-compile-time-if-not-already-initialized-ds1302
Parse compiler DATE and TIME into a time_t structure
I use this to initialize the system time RTC using set_time() to a value parsed from the DATE and TIME strings. I find it easier to recompile and reload the firmware than it is to manually type the time string.
Sample Use
https://developer.mbed.org/users/joeata2wh/code/xj-Init-clock-to-compile-time-if-not-alr extends the use of this library to set the DS1302 clock chip to the compile time only the first time the utility runs. After that it detects a sentinel already stored in the clock chip and used the previously saved time.
Referenced:
- http://stackoverflow.com/questions/1765014/convert-string-from-date-into-a-time-t
- https://developer.mbed.org/users/petereiso/notebook/cc-time-functions/
- http://playground.arduino.cc/Main/DS1302
Revision 2:c746c1b8671f, committed 2016-05-07
- Comitter:
- joeata2wh
- Date:
- Sat May 07 02:06:11 2016 +0000
- Parent:
- 1:3e55cf9d76e6
- Commit message:
- month was 1 digit to high
Changed in this revision
compile_time_to_system_time.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3e55cf9d76e6 -r c746c1b8671f compile_time_to_system_time.h --- a/compile_time_to_system_time.h Wed Mar 30 14:49:56 2016 +0000 +++ b/compile_time_to_system_time.h Sat May 07 02:06:11 2016 +0000 @@ -41,7 +41,7 @@ sscanf(date, "%s %d %d", s_month, &t.tm_mday, &year); sscanf(time, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); // Find where is s_month in month_names. Deduce month value. - t.tm_mon = (strstr(month_names, s_month) - month_names) / 3 + 1; + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; t.tm_year = year - 1900; return mktime(&t); }