mirror of https://github.com/sqfmi/Watchy.git
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 thispull/120/head
parent
3ca79867b9
commit
3a2974b997
|
@ -3,7 +3,8 @@
|
||||||
WatchyRTC::WatchyRTC()
|
WatchyRTC::WatchyRTC()
|
||||||
: rtc_ds(false) {}
|
: 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) {
|
bool WatchyRTC::_canConnectTo(int addr) {
|
||||||
byte error;
|
byte error;
|
||||||
Wire.beginTransmission(addr);
|
Wire.beginTransmission(addr);
|
||||||
|
@ -14,18 +15,18 @@ bool WatchyRTC::_canConnectTo(int addr) {
|
||||||
void WatchyRTC::init(){
|
void WatchyRTC::init(){
|
||||||
if (_canConnectTo(RTC_DS_ADDR)) {
|
if (_canConnectTo(RTC_DS_ADDR)) {
|
||||||
rtcType = DS3232_RTC_TYPE;
|
rtcType = DS3232_RTC_TYPE;
|
||||||
_rtc = DS3232();
|
_rtc = new DS3232();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_canConnectTo(RTC_PCF_ADDR)) {
|
if (_canConnectTo(RTC_PCF_ADDR)) {
|
||||||
rtcType = PCF8563_RTC_TYPE;
|
rtcType = PCF8563_RTC_TYPE;
|
||||||
_rtc = PCF8563();
|
_rtc = new PCF8563();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtcType = NO_RTC_TYPE;
|
rtcType = NO_RTC_TYPE;
|
||||||
_rtc = AbstractRTC();
|
_rtc = new AbstractRTC();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::config(String datetime){
|
void WatchyRTC::config(String datetime){
|
||||||
|
|
|
@ -63,7 +63,7 @@ class WatchyRTC {
|
||||||
int _getDayOfWeek(int d, int m, int y);
|
int _getDayOfWeek(int d, int m, int y);
|
||||||
String _getValue(String data, char separator, int index);
|
String _getValue(String data, char separator, int index);
|
||||||
bool _canConnectTo(int addr);
|
bool _canConnectTo(int addr);
|
||||||
AbstractRTC _rtc;
|
AbstractRTC* _rtc;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue