Skip to content

Commit 4fc4c63

Browse files
committed
Add option for using callback
1 parent 7a530f7 commit 4fc4c63

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/Arduino_LowPowerPortentaC33.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ void LowPower::deepSleep(){
2424
R_LPM_LowPowerModeEnter(&RenesasLowPowerControlBlock);
2525
}
2626

27-
bool LowPower::setWakeUpAlarm(RTCTime alarmTime){
27+
bool LowPower::setWakeUpAlarm(RTCTime alarmTime, void (* const callbackFunction)(), RTClock * rtc){
2828
this->enableWakeupFromRTC();
2929

30-
if(!RTC.isRunning()){
30+
if(!rtc->isRunning()){
3131
return false;
3232
}
3333

3434
RTCTime currentTime;
35-
if (!RTC.getTime(currentTime)) {
35+
if (!rtc->getTime(currentTime)) {
3636
return false; // Failed to get current time
3737
}
3838

@@ -45,18 +45,22 @@ bool LowPower::setWakeUpAlarm(RTCTime alarmTime){
4545
match.addMatchMonth(); // Trigger the alarm when the months match
4646
match.addMatchYear(); // Trigger the alarm when the years match
4747

48-
return RTC.setAlarm(alarmTime, match);
48+
if (callbackFunction) {
49+
return rtc->setAlarmCallback(callbackFunction, alarmTime, match);
50+
} else {
51+
return rtc->setAlarm(alarmTime, match);
52+
}
4953
}
5054

51-
bool LowPower::setWakeUpAlarm(uint8_t hours, uint8_t minutes, uint8_t seconds){
55+
bool LowPower::setWakeUpAlarm(uint8_t hours, uint8_t minutes, uint8_t seconds, void (* const callbackFunction)(), RTClock * rtc){
5256

53-
if(!RTC.isRunning()){
57+
if(!rtc->isRunning()){
5458
return false;
5559
}
5660

5761
// Get the current time from the RTC
5862
RTCTime currentTime;
59-
if (!RTC.getTime(currentTime)) {
63+
if (!rtc->getTime(currentTime)) {
6064
return false; // Failed to get current time
6165
}
6266

@@ -67,7 +71,7 @@ bool LowPower::setWakeUpAlarm(uint8_t hours, uint8_t minutes, uint8_t seconds){
6771
// Convert back to RTCTime
6872
RTCTime alarmTime(currentTimestamp);
6973

70-
return this->setWakeUpAlarm(alarmTime);
74+
return this->setWakeUpAlarm(alarmTime, callbackFunction, rtc);
7175
}
7276

7377
void LowPower::enableWakeupFromRTC(){

src/Arduino_LowPowerPortentaC33.h

+25-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,31 @@ class LowPower {
4141
*/
4242
bool enableWakeupFromPin(uint8_t pin, PinStatus direction);
4343

44-
bool setWakeUpAlarm(RTCTime alarmTime);
45-
bool setWakeUpAlarm(uint8_t hours, uint8_t minutes, uint8_t seconds);
44+
/**
45+
* Enables wake-up of the device based on the Real-Time Clock (RTC).
46+
* The device will wake up at the specified time.
47+
* @param alarmTime The time at which the device will wake up.
48+
* @param callbackFunction The function to be called when the device wakes up.
49+
* Specifying it only makes sense when used with sleep() and not deepSleep() as the device will reset when it wakes up from deep sleep.
50+
* @param rtc The Real-Time Clock (RTC) to be used for setting the wake-up alarm.
51+
* If not specified, the default RTC will be used.
52+
* @return True if the wake-up alarm was set successfully, false otherwise.
53+
*/
54+
bool setWakeUpAlarm(RTCTime alarmTime, void (* const callbackFunction)() = nullptr, RTClock * rtc = &RTC);
55+
56+
/**
57+
* Enables wake-up of the device based on the Real-Time Clock (RTC).
58+
* The device will wake up at the specified time.
59+
* @param hours The hour at which the device will wake up.
60+
* @param minutes The minute at which the device will wake up.
61+
* @param seconds The second at which the device will wake up.
62+
* @param callbackFunction The function to be called when the device wakes up.
63+
* Specifying it only makes sense when used with sleep() and not deepSleep() as the device will reset when it wakes up from deep sleep.
64+
* @param rtc The Real-Time Clock (RTC) to be used for setting the wake-up alarm.
65+
* If not specified, the default RTC will be used.
66+
* @return True if the wake-up alarm was set successfully, false otherwise.
67+
*/
68+
bool setWakeUpAlarm(uint8_t hours, uint8_t minutes, uint8_t seconds, void (* const callbackFunction)() = nullptr, RTClock * rtc = &RTC);
4669

4770
private:
4871
/**

0 commit comments

Comments
 (0)