From c2b89e077ba84a076fc3bcb88858601ff365e563 Mon Sep 17 00:00:00 2001 From: Justin Newitter Date: Tue, 20 Dec 2022 23:07:18 -0500 Subject: [PATCH] DS3231: Add support for fetching alarm enabled status This commit introduces one new method for DS3231 devices: - bool alarmEnabled(uint8_t alarm_num); Updated the DS3231_alarm example to fetch the alarm1 enabled status. Locally validated that this correctly fetches the enabled/disabled status for alarm2 as well. --- examples/DS3231_alarm/DS3231_alarm.ino | 8 ++++++-- src/RTC_DS3231.cpp | 15 +++++++++++++-- src/RTClib.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/DS3231_alarm/DS3231_alarm.ino b/examples/DS3231_alarm/DS3231_alarm.ino index f1d8b1ea..86ba39f8 100644 --- a/examples/DS3231_alarm/DS3231_alarm.ino +++ b/examples/DS3231_alarm/DS3231_alarm.ino @@ -87,8 +87,12 @@ void loop() { Serial.print("] SQW: "); Serial.print(digitalRead(CLOCK_INTERRUPT_PIN)); - // whether a alarm fired - Serial.print(" Fired: "); + // indicates if alarm 1 is enabled + Serial.print(", Enabled: "); + Serial.print(rtc.alarmEnabled(1)); + + // whether alarm 1 fired + Serial.print(", Fired: "); Serial.print(rtc.alarmFired(1)); // Serial.print(" Alarm2: "); diff --git a/src/RTC_DS3231.cpp b/src/RTC_DS3231.cpp index c24a65a2..26ce0096 100644 --- a/src/RTC_DS3231.cpp +++ b/src/RTC_DS3231.cpp @@ -340,8 +340,19 @@ void RTC_DS3231::clearAlarm(uint8_t alarm_num) { /**************************************************************************/ /*! - @brief Get status of alarm - @param alarm_num Alarm number to check status of + @brief Get enabled status of alarm + @param alarm_num Alarm number to check enabled status of + @return True if alarm is enabled otherwise false +*/ +/**************************************************************************/ +bool RTC_DS3231::alarmEnabled(uint8_t alarm_num) { + return (read_register(DS3231_CONTROL) >> (alarm_num - 1)) & 0x1; +} + +/**************************************************************************/ +/*! + @brief Get fired status of alarm + @param alarm_num Alarm number to check fired status of @return True if alarm has been fired otherwise false */ /**************************************************************************/ diff --git a/src/RTClib.h b/src/RTClib.h index 879bb3fa..79dae57e 100644 --- a/src/RTClib.h +++ b/src/RTClib.h @@ -383,6 +383,7 @@ class RTC_DS3231 : RTC_I2C { Ds3231Alarm2Mode getAlarm2Mode(); void disableAlarm(uint8_t alarm_num); void clearAlarm(uint8_t alarm_num); + bool alarmEnabled(uint8_t alarm_num); bool alarmFired(uint8_t alarm_num); void enable32K(void); void disable32K(void);