From 06db30fab095da20761c3d6a4523ab0e15cfcad6 Mon Sep 17 00:00:00 2001 From: Jerome Briot Date: Fri, 7 Jan 2022 14:39:22 +0100 Subject: [PATCH] Add getAlarmEpoch() method (https://github.com/arduino-libraries/RTCZero/issues/60) Fix warning on compiling with oldTime.RTC_MODE2_CLOCK_Type::reg (https://github.com/arduino-libraries/RTCZero/issues/67) --- src/RTCZero.cpp | 25 +++++++++++++++++++++++-- src/RTCZero.h | 3 ++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/RTCZero.cpp b/src/RTCZero.cpp index 593a8bb..35ad14a 100644 --- a/src/RTCZero.cpp +++ b/src/RTCZero.cpp @@ -50,7 +50,7 @@ void RTCZero::begin(bool resetTime) // not due to POR or BOD, preserve the clock time // POR causes a reset anyway, BOD behaviour is? bool validTime = false; - RTC_MODE2_CLOCK_Type oldTime; + RTC_MODE2_CLOCK_Type oldTime = {.reg=0L}; if ((!resetTime) && (PM->RCAUSE.reg & (PM_RCAUSE_SYST | PM_RCAUSE_WDT | PM_RCAUSE_EXT))) { if (RTC->MODE2.CTRL.reg & RTC_MODE2_CTRL_MODE_CLOCK) { @@ -391,11 +391,32 @@ time_t RTCZero::getEpoch() return mktime(&tm); } -uint32_t RTCZero::getY2kEpoch() +time_t RTCZero::getY2kEpoch() { return (getEpoch() - EPOCH_TIME_OFF); } +time_t RTCZero::getAlarmEpoch() +{ + RTCreadRequest(); + RTC_MODE2_ALARM_Type alarmTime; + alarmTime.reg = RTC->MODE2.Mode2Alarm[0].ALARM.reg; + + struct tm tm; + + tm.tm_isdst = -1; + tm.tm_yday = 0; + tm.tm_wday = 0; + tm.tm_year = alarmTime.bit.YEAR + EPOCH_TIME_YEAR_OFF; + tm.tm_mon = alarmTime.bit.MONTH - 1; + tm.tm_mday = alarmTime.bit.DAY; + tm.tm_hour = alarmTime.bit.HOUR; + tm.tm_min = alarmTime.bit.MINUTE; + tm.tm_sec = alarmTime.bit.SECOND; + + return mktime(&tm); +} + void RTCZero::setAlarmEpoch(uint32_t ts) { if (_configured) { diff --git a/src/RTCZero.h b/src/RTCZero.h index e0bfb64..6b09f1a 100644 --- a/src/RTCZero.h +++ b/src/RTCZero.h @@ -92,7 +92,8 @@ class RTCZero { /* Epoch Functions */ time_t getEpoch(); - uint32_t getY2kEpoch(); + time_t getY2kEpoch(); + time_t getAlarmEpoch(); void setEpoch(uint32_t ts); void setY2kEpoch(uint32_t ts); void setAlarmEpoch(uint32_t ts);