@@ -47,13 +47,27 @@ namespace rtc { | |||||
RTC.writeTime(); | RTC.writeTime(); | ||||
} | } | ||||
void setAlarm(uint16_t seconds) { | |||||
tmElements_t currentTime; | |||||
tmElements_t alarmTime; | |||||
getTime(currentTime); | |||||
breakTime(makeTimestamp(currentTime) + seconds, alarmTime); | |||||
setAlarm(alarmTime); | |||||
} | |||||
void setAlarm(tmElements_t &time) { | void setAlarm(tmElements_t &time) { | ||||
tmElements_t currentTime; | tmElements_t currentTime; | ||||
getTime(currentTime); | getTime(currentTime); | ||||
Log.verbose(F("Current time : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(currentTime.Year), currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second); | Log.verbose(F("Current time : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(currentTime.Year), currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second); | ||||
Log.notice(F("Set alarm to : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second); | |||||
details::writeTimeToRegisters(time); | details::writeTimeToRegisters(time); | ||||
RTC.writeAlarm1(DS3231_ALM_DTHMS); | RTC.writeAlarm1(DS3231_ALM_DTHMS); | ||||
getTime(currentTime); | |||||
Log.notice(F("Set alarm to : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second); | |||||
RTC.control(DS3231_A1_FLAG, DS3231_OFF); //reset Alarm 1 flag | RTC.control(DS3231_A1_FLAG, DS3231_OFF); //reset Alarm 1 flag | ||||
RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON | RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON | ||||
@@ -17,11 +17,6 @@ namespace rtc { | |||||
void getTime(tmElements_t &time); | void getTime(tmElements_t &time); | ||||
void setTime(tmElements_t &time); | void setTime(tmElements_t &time); | ||||
inline void setAlarm(uint16_t seconds) { | |||||
tmElements_t time; | |||||
getTime(time); | |||||
setAlarm(makeTime(time) + seconds); | |||||
} | |||||
void setAlarm(uint16_t seconds); | |||||
void setAlarm(tmElements_t &time); | void setAlarm(tmElements_t &time); | ||||
} | } |
@@ -95,7 +95,7 @@ void breakTime(const timestamp_t timeInput, tmElements_t &tm) { | |||||
} | } | ||||
__attribute__((__optimize__("O2"))) | __attribute__((__optimize__("O2"))) | ||||
timestamp_t makeTime(const tmElements_t &tm) { | |||||
timestamp_t makeTimestamp(const tmElements_t &tm) { | |||||
// assemble time elements into timestamp_t | // assemble time elements into timestamp_t | ||||
// note year argument is offset from 1970 (see macros in time.h to convert to other formats) | // note year argument is offset from 1970 (see macros in time.h to convert to other formats) | ||||
// previous version used full four digit year (or digits since 2000),i.e. 2009 was 2009 or 9 | // previous version used full four digit year (or digits since 2000),i.e. 2009 was 2009 or 9 | ||||
@@ -24,4 +24,4 @@ typedef struct { | |||||
/* low level functions to convert to and from system time */ | /* low level functions to convert to and from system time */ | ||||
void breakTime(const timestamp_t time, tmElements_t &tm); // break timestamp_t into elements | void breakTime(const timestamp_t time, tmElements_t &tm); // break timestamp_t into elements | ||||
timestamp_t makeTime(const tmElements_t &tm); // convert time elements into timestamp_t | |||||
timestamp_t makeTimestamp(const tmElements_t &tm); // convert time elements into timestamp_t |