File tree Expand file tree Collapse file tree 2 files changed +11
-17
lines changed
Expand file tree Collapse file tree 2 files changed +11
-17
lines changed Original file line number Diff line number Diff line change 1- /* Copyright (c) 2020-2021 , Collab
1+ /* Copyright (c) 2020-2023 , Collab
22 * All rights reserved
33*/
44/*
55 DS3231_RealtimeClock.cpp - Read and write to a DS3231 realtime clock.
66*/
77#include " DS3231_RealtimeClock.h"
88
9- DS3231_RealtimeClock::DS3231_RealtimeClock (int scl_pin, int sda_pin, uint8_t eeprom_address) {
10- _sclPin = scl_pin;
11- _sdaPin = sda_pin;
9+ DS3231_RealtimeClock::DS3231_RealtimeClock (TwoWire* wire, uint8_t eeprom_address) {
10+ _wire = wire;
1211
1312 // storage
14- _storage = new AT24C32_EEPROM (eeprom_address);
13+ _storage = new AT24C32_EEPROM (eeprom_address, wire );
1514
1615 // rtc
1716 _rtc = new RTC_DS3231 ();
1817}
1918
20- void DS3231_RealtimeClock::begin (bool callWireBegin) {
21- // rtc
22- if (callWireBegin) {
23- Wire.begin (_sdaPin, _sclPin);
24- }
25- Wire.beginTransmission (DS3231_ADDRESS);
26- if (Wire.endTransmission () != 0 ) {
19+ void DS3231_RealtimeClock::begin () {
20+ // initializing the rtc
21+ if (!_rtc->begin (_wire)) {
2722 Log.warning (F (" Initializing DS3231... Error!" CR));
2823 }
2924
Original file line number Diff line number Diff line change 1- /* Copyright (c) 2020-2021 , Collab
1+ /* Copyright (c) 2020-2023 , Collab
22 * All rights reserved
33*/
44/*
1818class DS3231_RealtimeClock
1919{
2020 public:
21- DS3231_RealtimeClock (int scl_pin = - 1 , int sda_pin = - 1 , uint8_t eeprom_address = 0x57 );
22- void begin (bool callWireBegin = true );
21+ DS3231_RealtimeClock (TwoWire* wire , uint8_t eeprom_address = 0x57 );
22+ void begin ();
2323 DateTime now ();
2424 DateTime load (int address = 0 );
2525 void save (DateTime timestamp, int address = 0 );
@@ -34,10 +34,9 @@ class DS3231_RealtimeClock
3434 float startupTemperature;
3535
3636 private:
37+ TwoWire *_wire;
3738 RTC_DS3231 *_rtc;
3839 AT24C32_EEPROM *_storage;
39- int _sclPin;
40- int _sdaPin;
4140};
4241
4342#endif
You can’t perform that action at this time.
0 commit comments