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.

Dependents:   AdaFruit_RGBLCD

Committer:
vtraveller
Date:
Mon Aug 11 19:10:09 2014 +0000
Revision:
8:2192f2809f59
Added helper functions for setting mbed internal clock without DS1307 device present.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 8:2192f2809f59 1 #include "mbed.h"
vtraveller 8:2192f2809f59 2 #include "time_helper.h"
vtraveller 8:2192f2809f59 3
vtraveller 8:2192f2809f59 4 void GetTime(tm & out_sTM)
vtraveller 8:2192f2809f59 5 {
vtraveller 8:2192f2809f59 6 time_t nTime = time(0);
vtraveller 8:2192f2809f59 7 tm * pTM = ::localtime(&nTime);
vtraveller 8:2192f2809f59 8 ::memcpy(&out_sTM,pTM,sizeof(out_sTM));
vtraveller 8:2192f2809f59 9 }
vtraveller 8:2192f2809f59 10
vtraveller 8:2192f2809f59 11 void SetTime(const tm & in_sTM)
vtraveller 8:2192f2809f59 12 {
vtraveller 8:2192f2809f59 13 tm sTM = { 0 };
vtraveller 8:2192f2809f59 14 memcpy(&sTM,&in_sTM,sizeof(sTM));
vtraveller 8:2192f2809f59 15
vtraveller 8:2192f2809f59 16 time_t nTime = mktime(&sTM);
vtraveller 8:2192f2809f59 17 set_time(nTime);
vtraveller 8:2192f2809f59 18 }