Skip to content

Commit 06db30f

Browse files
committed
Add getAlarmEpoch() method (#60)
Fix warning on compiling with oldTime.RTC_MODE2_CLOCK_Type::reg (#67)
1 parent ed6772a commit 06db30f

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/RTCZero.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void RTCZero::begin(bool resetTime)
5050
// not due to POR or BOD, preserve the clock time
5151
// POR causes a reset anyway, BOD behaviour is?
5252
bool validTime = false;
53-
RTC_MODE2_CLOCK_Type oldTime;
53+
RTC_MODE2_CLOCK_Type oldTime = {.reg=0L};
5454

5555
if ((!resetTime) && (PM->RCAUSE.reg & (PM_RCAUSE_SYST | PM_RCAUSE_WDT | PM_RCAUSE_EXT))) {
5656
if (RTC->MODE2.CTRL.reg & RTC_MODE2_CTRL_MODE_CLOCK) {
@@ -391,11 +391,32 @@ time_t RTCZero::getEpoch()
391391
return mktime(&tm);
392392
}
393393

394-
uint32_t RTCZero::getY2kEpoch()
394+
time_t RTCZero::getY2kEpoch()
395395
{
396396
return (getEpoch() - EPOCH_TIME_OFF);
397397
}
398398

399+
time_t RTCZero::getAlarmEpoch()
400+
{
401+
RTCreadRequest();
402+
RTC_MODE2_ALARM_Type alarmTime;
403+
alarmTime.reg = RTC->MODE2.Mode2Alarm[0].ALARM.reg;
404+
405+
struct tm tm;
406+
407+
tm.tm_isdst = -1;
408+
tm.tm_yday = 0;
409+
tm.tm_wday = 0;
410+
tm.tm_year = alarmTime.bit.YEAR + EPOCH_TIME_YEAR_OFF;
411+
tm.tm_mon = alarmTime.bit.MONTH - 1;
412+
tm.tm_mday = alarmTime.bit.DAY;
413+
tm.tm_hour = alarmTime.bit.HOUR;
414+
tm.tm_min = alarmTime.bit.MINUTE;
415+
tm.tm_sec = alarmTime.bit.SECOND;
416+
417+
return mktime(&tm);
418+
}
419+
399420
void RTCZero::setAlarmEpoch(uint32_t ts)
400421
{
401422
if (_configured) {

src/RTCZero.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class RTCZero {
9292
/* Epoch Functions */
9393

9494
time_t getEpoch();
95-
uint32_t getY2kEpoch();
95+
time_t getY2kEpoch();
96+
time_t getAlarmEpoch();
9697
void setEpoch(uint32_t ts);
9798
void setY2kEpoch(uint32_t ts);
9899
void setAlarmEpoch(uint32_t ts);

0 commit comments

Comments
 (0)