@@ -1077,6 +1077,60 @@ time_t STM32RTC::getY2kEpoch(void)
10771077 return (getEpoch () - EPOCH_TIME_OFF);
10781078}
10791079
1080+ /* *
1081+ * @brief get alarm epoch time
1082+ * @param name: ALARM_A or ALARM_B if exists
1083+ * @retval epoch time in seconds
1084+ */
1085+ time_t STM32RTC::getAlarmEpoch (Alarm name)
1086+ {
1087+ return getAlarmEpoch (nullptr , name);
1088+ }
1089+
1090+ /* *
1091+ * @brief get alarm epoch time
1092+ * @param subSeconds: optional pointer to where to store subseconds of the epoch in ms
1093+ * @param name: optional (default: ALARM_A)
1094+ * ALARM_A or ALARM_B if exists
1095+ * @retval epoch time in seconds
1096+ */
1097+ time_t STM32RTC::getAlarmEpoch (uint32_t *subSeconds, Alarm name)
1098+ {
1099+ struct tm tm;
1100+
1101+ tm.tm_isdst = -1 ;
1102+ /*
1103+ * mktime ignores the values supplied by the caller in the
1104+ * tm_wday and tm_yday fields
1105+ */
1106+ tm.tm_yday = 0 ;
1107+ tm.tm_wday = 0 ;
1108+ tm.tm_year = _year + EPOCH_TIME_YEAR_OFF;
1109+ tm.tm_mon = _month - 1 ;
1110+ syncAlarmTime (name);
1111+ #ifdef RTC_ALARM_B
1112+ if (name == ALARM_B) {
1113+ tm.tm_mday = _alarmBDay;
1114+ tm.tm_hour = _alarmBHours;
1115+ tm.tm_min = _alarmBMinutes;
1116+ tm.tm_sec = _alarmBSeconds;
1117+ if (subSeconds != nullptr ) {
1118+ *subSeconds = _alarmBSubSeconds;
1119+ }
1120+ } else
1121+ #endif
1122+ {
1123+ tm.tm_mday = _alarmDay;
1124+ tm.tm_hour = _alarmHours;
1125+ tm.tm_min = _alarmMinutes;
1126+ tm.tm_sec = _alarmSeconds;
1127+ if (subSeconds != nullptr ) {
1128+ *subSeconds = _alarmSubSeconds;
1129+ }
1130+ }
1131+ return mktime (&tm);
1132+ }
1133+
10801134/* *
10811135 * @brief set RTC alarm from epoch time
10821136 * @param epoch time in seconds
0 commit comments