Crossing the Rubicon

* We are now going to make _rtc a pointer, and use that
  process of polymorphism as part of the refactors. Again,
  I worry about memory management, but there does not seem
  to be a very clear way around this
pull/120/head
Andre LaFleur 2021-12-18 11:22:30 -07:00
parent 3ca79867b9
commit 3a2974b997
2 changed files with 6 additions and 5 deletions

View File

@ -3,7 +3,8 @@
WatchyRTC::WatchyRTC()
: rtc_ds(false) {}
// TODO: We can probably put all of this logic into AbstractRTC as a class
// function. It would simplify this class even more, which would be nice
bool WatchyRTC::_canConnectTo(int addr) {
byte error;
Wire.beginTransmission(addr);
@ -14,18 +15,18 @@ bool WatchyRTC::_canConnectTo(int addr) {
void WatchyRTC::init(){
if (_canConnectTo(RTC_DS_ADDR)) {
rtcType = DS3232_RTC_TYPE;
_rtc = DS3232();
_rtc = new DS3232();
return;
}
if (_canConnectTo(RTC_PCF_ADDR)) {
rtcType = PCF8563_RTC_TYPE;
_rtc = PCF8563();
_rtc = new PCF8563();
return;
}
rtcType = NO_RTC_TYPE;
_rtc = AbstractRTC();
_rtc = new AbstractRTC();
}
void WatchyRTC::config(String datetime){

View File

@ -63,7 +63,7 @@ class WatchyRTC {
int _getDayOfWeek(int d, int m, int y);
String _getValue(String data, char separator, int index);
bool _canConnectTo(int addr);
AbstractRTC _rtc;
AbstractRTC* _rtc;
};
#endif