mirror of https://github.com/sqfmi/Watchy.git
Finish getting things out to subclasses
parent
619b80232b
commit
811e209436
|
@ -37,23 +37,7 @@ void WatchyRTC::clearAlarm(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::read(tmElements_t &tm){
|
void WatchyRTC::read(tmElements_t &tm){
|
||||||
if (rtcType == DS3232_RTC_TYPE) {
|
_rtc->read(tm);
|
||||||
((DS3232*) _rtc)->rtc_ds.read(tm);
|
|
||||||
tm.Year = tm.Year - 30; //reset to offset from 2000
|
|
||||||
} else if (rtcType == PCF8563_RTC_TYPE) {
|
|
||||||
tm.Month = ((PCF8563 *) _rtc)->rtc_pcf.getMonth();
|
|
||||||
if(tm.Month == 0){ //PCF8563 POR sets month = 0 for some reason
|
|
||||||
tm.Month = 1;
|
|
||||||
tm.Year = 21;
|
|
||||||
}else{
|
|
||||||
tm.Year = ((PCF8563 *) _rtc)->rtc_pcf.getYear();
|
|
||||||
}
|
|
||||||
tm.Day = ((PCF8563 *) _rtc)->rtc_pcf.getDay();
|
|
||||||
tm.Wday = ((PCF8563 *) _rtc)->rtc_pcf.getWeekday() + 1;
|
|
||||||
tm.Hour = ((PCF8563 *) _rtc)->rtc_pcf.getHour();
|
|
||||||
tm.Minute = ((PCF8563 *) _rtc)->rtc_pcf.getMinute();
|
|
||||||
tm.Second = ((PCF8563 *) _rtc)->rtc_pcf.getSecond();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::set(tmElements_t tm){
|
void WatchyRTC::set(tmElements_t tm){
|
||||||
|
@ -61,9 +45,5 @@ void WatchyRTC::set(tmElements_t tm){
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t WatchyRTC::temperature(){
|
uint8_t WatchyRTC::temperature(){
|
||||||
if (rtcType == DS3232_RTC_TYPE) {
|
return _rtc->temperature();
|
||||||
return ((DS3232*) _rtc)->rtc_ds.temperature();
|
|
||||||
}
|
|
||||||
|
|
||||||
return NO_TEMPERATURE_ERR;
|
|
||||||
}
|
}
|
|
@ -81,11 +81,20 @@ public:
|
||||||
rtc_ds.alarm(ALARM_2);
|
rtc_ds.alarm(ALARM_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void read(tmElements_t &tm) {
|
||||||
|
rtc_ds.read(tm);
|
||||||
|
tm.Year = tm.Year - 30; //reset to offset from 2000
|
||||||
|
}
|
||||||
|
|
||||||
void set(tmElements_t tm) {
|
void set(tmElements_t tm) {
|
||||||
tm.Year = tm.Year + 2000 - YEAR_OFFSET_DS3232;
|
tm.Year = tm.Year + 2000 - YEAR_OFFSET_DS3232;
|
||||||
time_t t = makeTime(tm);
|
time_t t = makeTime(tm);
|
||||||
rtc_ds.set(t);
|
rtc_ds.set(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t temperature() {
|
||||||
|
return rtc_ds.temperature();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PCF8563 : public AbstractRTC {
|
class PCF8563 : public AbstractRTC {
|
||||||
|
@ -121,6 +130,21 @@ public:
|
||||||
rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
|
rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void read(tmElements_t &tm) {
|
||||||
|
tm.Month = rtc_pcf.getMonth();
|
||||||
|
if (tm.Month == 0){ //PCF8563 POR sets month = 0 for some reason
|
||||||
|
tm.Month = 1;
|
||||||
|
tm.Year = 21; // TODO: I feel nervous about this--it's only 21 for a year, right?
|
||||||
|
} else {
|
||||||
|
tm.Year = rtc_pcf.getYear();
|
||||||
|
}
|
||||||
|
tm.Day = rtc_pcf.getDay();
|
||||||
|
tm.Wday = rtc_pcf.getWeekday() + 1;
|
||||||
|
tm.Hour = rtc_pcf.getHour();
|
||||||
|
tm.Minute = rtc_pcf.getMinute();
|
||||||
|
tm.Second = rtc_pcf.getSecond();
|
||||||
|
}
|
||||||
|
|
||||||
void set(tmElements_t tm) {
|
void set(tmElements_t tm) {
|
||||||
int dayOfWeek = getDayOfWeek(tm.Day, tm.Month, tm.Year + YEAR_OFFSET_PCF);
|
int dayOfWeek = getDayOfWeek(tm.Day, tm.Month, tm.Year + YEAR_OFFSET_PCF);
|
||||||
rtc_pcf.setDate(tm.Day, dayOfWeek, tm.Month, 0, tm.Year);
|
rtc_pcf.setDate(tm.Day, dayOfWeek, tm.Month, 0, tm.Year);
|
||||||
|
|
Loading…
Reference in New Issue