Local Library for DS3231 RTC
Fork of ds3231 by
Revision 15:b87f3e7258bb, committed 2018-01-15
- Comitter:
- brianclaus
- Date:
- Mon Jan 15 20:24:23 2018 +0000
- Parent:
- 14:11630748e2f2
- Commit message:
- update;
Changed in this revision
ds3231.cpp | Show annotated file Show diff for this revision Revisions of this file |
ds3231.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 11630748e2f2 -r b87f3e7258bb ds3231.cpp --- a/ds3231.cpp Wed Mar 18 00:06:59 2015 +0000 +++ b/ds3231.cpp Mon Jan 15 20:24:23 2018 +0000 @@ -681,6 +681,49 @@ return(rtn_val); } +uint16_t Ds3231::set_aging(uint8_t age){ + uint16_t rtn_val = 1; + rtn_val = write(w_adrs, (const char*) age, 1); + + return(rtn_val); + + +} + +/********************************************************** +* Set RTC time and date based on epoch time +* +* return 0 on success +**********************************************************/ + +uint16_t Ds3231::set_epoch(time_t epoch_time){ + //assume success until failure + int success = 0; + + //system vars + struct tm * sys_time; + //RTC vars + ds3231_time_t rtc_time = {0,0,0,0,0}; + ds3231_calendar_t rtc_calendar = {0,0,0,0}; + + sys_time = localtime(&epoch_time); + + //localtime comes back as 24hour + rtc_time.mode = 0; + rtc_time.hours = sys_time->tm_hour; + rtc_time.minutes = sys_time->tm_min; + rtc_time.seconds = sys_time->tm_sec; + + rtc_calendar.day = sys_time->tm_wday + 1; + rtc_calendar.date = sys_time->tm_mday; + rtc_calendar.month = sys_time->tm_mon + 1; + rtc_calendar.year = sys_time->tm_year - 100; + + success += set_calendar(rtc_calendar); + success += set_time(rtc_time); + + return success; +} /**********************************************************//** * Get epoch time based on current RTC time and date.
diff -r 11630748e2f2 -r b87f3e7258bb ds3231.h --- a/ds3231.h Wed Mar 18 00:06:59 2015 +0000 +++ b/ds3231.h Mon Jan 15 20:24:23 2018 +0000 @@ -327,6 +327,7 @@ uint16_t set_calendar(ds3231_calendar_t calendar); + /**********************************************************//** * Set either Alarm1 or Alarm2 of DS3231 * @@ -521,6 +522,15 @@ uint16_t get_temperature(void); + /********************************************************** + * Set RTC time and date based on epoch time + * + * return 0 on success + **********************************************************/ + uint16_t set_epoch(time_t epoch_time); + + uint16_t set_aging(uint8_t age); + /**********************************************************//** * Get epoch time based on current RTC time and date. * DS3231 must be configured and running before this fx is