mirror of https://github.com/sqfmi/Watchy.git
Simplify init() a bit more
parent
bac7b4eb51
commit
b7800f0b21
|
@ -3,26 +3,26 @@
|
||||||
WatchyRTC::WatchyRTC()
|
WatchyRTC::WatchyRTC()
|
||||||
: rtc_ds(false) {}
|
: rtc_ds(false) {}
|
||||||
|
|
||||||
void WatchyRTC::init(){
|
|
||||||
|
bool WatchyRTC::_canConnectTo(int addr) {
|
||||||
byte error;
|
byte error;
|
||||||
Wire.beginTransmission(RTC_DS_ADDR);
|
Wire.beginTransmission(addr);
|
||||||
error = Wire.endTransmission();
|
error = Wire.endTransmission(addr);
|
||||||
if (error == 0) {
|
return error == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WatchyRTC::init(){
|
||||||
|
if (_canConnectTo(RTC_DS_ADDR)) {
|
||||||
rtcType = DS3232_RTC_TYPE;
|
rtcType = DS3232_RTC_TYPE;
|
||||||
_rtc = DS3232();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wire.beginTransmission(RTC_PCF_ADDR);
|
if (_canConnectTo(RTC_PCF_ADDR)) {
|
||||||
error = Wire.endTransmission();
|
|
||||||
if (error == 0) {
|
|
||||||
rtcType = PCF8563_RTC_TYPE;
|
rtcType = PCF8563_RTC_TYPE;
|
||||||
_rtc = PCF8563();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtcType = NO_RTC_TYPE;
|
rtcType = NO_RTC_TYPE;
|
||||||
_rtc = AbstractRTC();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::config(String datetime){
|
void WatchyRTC::config(String datetime){
|
||||||
|
@ -105,7 +105,6 @@ void WatchyRTC::_DSConfig(String datetime){
|
||||||
|
|
||||||
void WatchyRTC::_PCFConfig(String datetime){
|
void WatchyRTC::_PCFConfig(String datetime){
|
||||||
if(datetime != ""){
|
if(datetime != ""){
|
||||||
tmElements_t tm;
|
|
||||||
int Year = _getValue(datetime, ':', 0).toInt();
|
int Year = _getValue(datetime, ':', 0).toInt();
|
||||||
int Month = _getValue(datetime, ':', 1).toInt();
|
int Month = _getValue(datetime, ':', 1).toInt();
|
||||||
int Day = _getValue(datetime, ':', 2).toInt();
|
int Day = _getValue(datetime, ':', 2).toInt();
|
||||||
|
|
|
@ -24,11 +24,11 @@
|
||||||
|
|
||||||
class AbstractRTC {
|
class AbstractRTC {
|
||||||
public:
|
public:
|
||||||
virtual void config(String datetime);
|
virtual void config(String datetime) {}
|
||||||
virtual void clearAlarm();
|
virtual void clearAlarm() {}
|
||||||
virtual void read(tmElements_t &tm);
|
virtual void read(tmElements_t &tm) {}
|
||||||
virtual void set(tmElements_t tm);
|
virtual void set(tmElements_t tm) {}
|
||||||
virtual uint8_t temperature();
|
virtual uint8_t temperature() { return NO_TEMPERATURE_ERR; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class WatchyRTC {
|
class WatchyRTC {
|
||||||
|
@ -45,8 +45,11 @@ class WatchyRTC {
|
||||||
void set(tmElements_t tm);
|
void set(tmElements_t tm);
|
||||||
uint8_t temperature();
|
uint8_t temperature();
|
||||||
private:
|
private:
|
||||||
|
void _DSConfig(String datetime);
|
||||||
|
void _PCFConfig(String datetime);
|
||||||
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);
|
||||||
AbstractRTC _rtc;
|
AbstractRTC _rtc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue