@@ -20,12 +20,56 @@ void LowPower::sleep(){
20
20
void LowPower::deepSleep (){
21
21
RenesasLowPowerConfig.low_power_mode = LPM_MODE_DEEP;
22
22
23
-
24
-
25
23
R_LPM_Open (&RenesasLowPowerControlBlock, &RenesasLowPowerConfig);
26
24
R_LPM_LowPowerModeEnter (&RenesasLowPowerControlBlock);
27
25
}
28
26
27
+ bool LowPower::setWakeUpAlarm (RTCTime alarmTime){
28
+ this ->enableWakeupFromRTC ();
29
+
30
+ if (!RTC.isRunning ()){
31
+ return false ;
32
+ }
33
+
34
+ RTCTime currentTime;
35
+ if (!RTC.getTime (currentTime)) {
36
+ return false ; // Failed to get current time
37
+ }
38
+
39
+ // Configure the alarm match criteria
40
+ AlarmMatch match;
41
+ match.addMatchSecond (); // Trigger the alarm when the seconds match
42
+ match.addMatchMinute (); // Trigger the alarm when the minutes match
43
+ match.addMatchHour (); // Trigger the alarm when the hours match
44
+ match.addMatchDay (); // Trigger the alarm when the days match
45
+ match.addMatchMonth (); // Trigger the alarm when the months match
46
+ match.addMatchYear (); // Trigger the alarm when the years match
47
+
48
+ return RTC.setAlarm (alarmTime, match);
49
+ }
50
+
51
+ bool LowPower::setWakeUpAlarm (uint8_t hours, uint8_t minutes, uint8_t seconds){
52
+
53
+ if (!RTC.isRunning ()){
54
+ return false ;
55
+ }
56
+
57
+ // Get the current time from the RTC
58
+ RTCTime currentTime;
59
+ if (!RTC.getTime (currentTime)) {
60
+ return false ; // Failed to get current time
61
+ }
62
+
63
+ // Convert current time to UNIX timestamp and add the desired interval
64
+ time_t currentTimestamp = currentTime.getUnixTime ();
65
+ currentTimestamp += hours * 3600 + minutes * 60 + seconds;
66
+
67
+ // Convert back to RTCTime
68
+ RTCTime alarmTime (currentTimestamp);
69
+
70
+ return this ->setWakeUpAlarm (alarmTime);
71
+ }
72
+
29
73
void LowPower::enableWakeupFromRTC (){
30
74
RenesasLowPowerConfig.deep_standby_cancel_source = LPM_DEEP_STANDBY_CANCEL_SOURCE_RTC_ALARM;
31
75
RenesasLowPowerConfig.standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM;
0 commit comments