Skip to content

Commit

Permalink
Merge pull request #62 from NorthernWidget/#51
Browse files Browse the repository at this point in the history
#51 Resolving issue #51
  • Loading branch information
jnuernberg authored Aug 14, 2022
2 parents bc96520 + 27e3a0a commit aa4d16e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
14 changes: 14 additions & 0 deletions DS3231.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ void DS3231::getA1Time(byte& A1Day, byte& A1Hour, byte& A1Minute, byte& A1Second
}
}

void DS3231::getA1Time(byte& A1Day, byte& A1Hour, byte& A1Minute, byte& A1Second, byte& AlarmBits, bool& A1Dy, bool& A1h12, bool& A1PM, bool clearAlarmBits) {
if (clearAlarmBits) {
AlarmBits = 0x0;
}
getA1Time(A1Day, A1Hour, A1Minute, A1Second, AlarmBits, A1Dy, A1h12, A1PM);
}

void DS3231::getA2Time(byte& A2Day, byte& A2Hour, byte& A2Minute, byte& AlarmBits, bool& A2Dy, bool& A2h12, bool& A2PM) {
byte temp_buffer;
_Wire.beginTransmission(CLOCK_ADDRESS);
Expand Down Expand Up @@ -515,6 +522,13 @@ void DS3231::getA2Time(byte& A2Day, byte& A2Hour, byte& A2Minute, byte& AlarmBit
}
}

void DS3231::getA2Time(byte& A2Day, byte& A2Hour, byte& A2Minute, byte& AlarmBits, bool& A2Dy, bool& A2h12, bool& A2PM, bool clearAlarmBits) {
if (clearAlarmBits) {
AlarmBits = 0x0;
}
getA2Time(A2Day, A2Hour, A2Minute, AlarmBits, A2Dy, A2h12, A2PM);
}

void DS3231::setA1Time(byte A1Day, byte A1Hour, byte A1Minute, byte A1Second, byte AlarmBits, bool A1Dy, bool A1h12, bool A1PM) {
// Sets the alarm-1 date and time on the DS3231, using A1* information
byte temp_buffer;
Expand Down
9 changes: 9 additions & 0 deletions DS3231.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,18 @@ class DS3231 {
* X 1 0 0 Alarm when hours and minutes match
* 0 0 0 0 Alarm when date, hour, min match
* 1 0 0 0 Alarm when DoW, hour, min match
*
* Note: byte AlarmBits is not explicitly cleared for the getAXTime methods to
* support sequential retreival of both alarms with the same byte AlarmBits.
* Use the flag bool clearAlarmBits=True to explicitly clear byte AlarmBits on
* call to getAXTime.
*/
void getA2Time(byte& A2Day, byte& A2Hour, byte& A2Minute, byte& AlarmBits, bool& A2Dy, bool& A2h12, bool& A2PM);
// Same as getA1Time();, but A2 only goes on seconds == 00.
void getA1Time(byte& A1Day, byte& A1Hour, byte& A1Minute, byte& A1Second, byte& AlarmBits, bool& A1Dy, bool& A1h12, bool& A1PM, bool clearAlarmBits);
// Same as getA1Time();, but clears byte AlarmBits.
void getA2Time(byte& A1Day, byte& A1Hour, byte& A1Minute,byte& AlarmBits, bool& A1Dy, bool& A1h12, bool& A1PM, bool clearAlarmBits);
// Same as getA1Time();, but clears byte AlarmBits.
void setA1Time(byte A1Day, byte A1Hour, byte A1Minute, byte A1Second, byte AlarmBits, bool A1Dy, bool A1h12, bool A1PM);
// Set the details for Alarm 1
void setA2Time(byte A2Day, byte A2Hour, byte A2Minute, byte AlarmBits, bool A2Dy, bool A2h12, bool A2PM);
Expand Down
80 changes: 80 additions & 0 deletions tests/getAXTimeTest/getAXTimeTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
getAXTimeTest.ino
Jacob Nuernberg
08/22
Testing getAXTimeMethods.
Code should generate the following output every 5s on the Serial Monitor:
-> Initialize AlarmBits: 0
-> getA1Time(): 1110
-> getA2Time(): 1111110
-> getA1Time(): 1110
-> getA2Time(): 1110000
Tested on:
- Arduino nano
*/

#include <DS3231.h>
#include <Wire.h>

// Setup clock
DS3231 myRTC;


void setup() {
// Begin I2C communication
Wire.begin();

// Begin Serial communication
Serial.begin(57600);

// Setup alarm one to fire every minute
// No need to turn Alarm one on.
myRTC.turnOffAlarm(1);
myRTC.setA1Time(0, 0, 0, 0, 0b01111110, false, false, false);
myRTC.checkIfAlarm(1);

// Setup alarm two to fire every minute
// No need to turn Alarm two on.
myRTC.turnOffAlarm(2);
myRTC.setA2Time(0, 0, 0, 0b01111110, false, false, false);
myRTC.checkIfAlarm(2);
}

void loop() {
// Initialize AlarmBits
byte AlarmBits = 0x0;
Serial.print("Initialize AlarmBits: ");
Serial.println(AlarmBits, BIN);

// Initialize Others
byte ADay, AHour, AMinute, ASecond;
bool ADy, Ah12, APM;

// getA1Time (not clearing).
// Expected AlarmBits = 0x(0000)1110
myRTC.getA1Time(ADay, AHour, AMinute, ASecond, AlarmBits, ADy, Ah12, APM);
Serial.print("getA1Time(): ");
Serial.println(AlarmBits, BIN);

// getA2Time (not clearing).
// Expected AlarmBits = 0x01111110
myRTC.getA2Time(ADay, AHour, AMinute, AlarmBits, ADy, Ah12, APM);
Serial.print("getA2Time(): ");
Serial.println(AlarmBits, BIN);

// getA1Time (clearing).
// Expected AlarmBits = 0x(0000)1110
myRTC.getA1Time(ADay, AHour, AMinute, ASecond, AlarmBits, ADy, Ah12, APM, true);
Serial.print("getA1Time(): ");
Serial.println(AlarmBits, BIN);

// getA2Time (clearing).
// Expected AlarmBits = 0x01110000
myRTC.getA2Time(ADay, AHour, AMinute, AlarmBits, ADy, Ah12, APM, true);
Serial.print("getA2Time(): ");
Serial.println(AlarmBits, BIN);
delay(5000);
}

0 comments on commit aa4d16e

Please sign in to comment.