arduino-libraries / ArduinoLowPower

Powersave features for SAMD boards
GNU Lesser General Public License v2.1
80 stars 57 forks source link

Add RTC time setting and getting functionality #23

Open geoffreyottoy opened 4 years ago

geoffreyottoy commented 4 years ago

Not really an issues, more of a request. I think it would be handy if we could access the underlying RTC to keep track of the time that has elapsed between e.g. two pin-interrupt wake's.

I propose two methods to achieve this:

void ArduinoLowPowerClass::setRtcTime(uint32_t time){
    // not sure if this is the best way to make sure the RTC is up and running
    if (!rtc.isConfigured()) {
        attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, 0);
    }

    rtc.setEpoch(time);
}

uint32_t ArduinoLowPowerClass::getRtcTime(void){
    return rtc.getEpoch();
}

I have tested this on SAMD and it seems to be working.