Simple RTC class based on DS1307. Emphasis on simple. Allows you to run at 100k or 400k Hz (for newer DS1307 capable devices). MapTime() allows you to set the time() service to the same as the RTC. Uses struct tm throughout so you can use traditional time functions for manipulation.
Diff: time_helper.cpp
- Revision:
- 8:2192f2809f59
diff -r 3621025e7949 -r 2192f2809f59 time_helper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/time_helper.cpp Mon Aug 11 19:10:09 2014 +0000 @@ -0,0 +1,18 @@ +#include "mbed.h" +#include "time_helper.h" + +void GetTime(tm & out_sTM) +{ + time_t nTime = time(0); + tm * pTM = ::localtime(&nTime); + ::memcpy(&out_sTM,pTM,sizeof(out_sTM)); +} + +void SetTime(const tm & in_sTM) +{ + tm sTM = { 0 }; + memcpy(&sTM,&in_sTM,sizeof(sTM)); + + time_t nTime = mktime(&sTM); + set_time(nTime); +}