mirror of https://github.com/sqfmi/Watchy.git
Pull in a couple other methods
parent
a4ab4b0144
commit
619b80232b
|
@ -33,11 +33,7 @@ void WatchyRTC::config(String datetime){
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::clearAlarm(){
|
void WatchyRTC::clearAlarm(){
|
||||||
if (rtcType == DS3232_RTC_TYPE) {
|
_rtc->clearAlarm();
|
||||||
((DS3232*) _rtc)->rtc_ds.alarm(ALARM_2);
|
|
||||||
} else if (rtcType == PCF8563_RTC_TYPE) {
|
|
||||||
_rtc->clearAlarm();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::read(tmElements_t &tm){
|
void WatchyRTC::read(tmElements_t &tm){
|
||||||
|
@ -61,23 +57,7 @@ void WatchyRTC::read(tmElements_t &tm){
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::set(tmElements_t tm){
|
void WatchyRTC::set(tmElements_t tm){
|
||||||
if (rtcType == DS3232_RTC_TYPE) {
|
_rtc->set(tm);
|
||||||
tm.Year = tm.Year + 2000 - YEAR_OFFSET_DS3232;
|
|
||||||
time_t t = makeTime(tm);
|
|
||||||
((DS3232*) _rtc)->rtc_ds.set(t);
|
|
||||||
} else if (rtcType == PCF8563_RTC_TYPE) {
|
|
||||||
((PCF8563 *) _rtc)->rtc_pcf.setDate(tm.Day, _getDayOfWeek(tm.Day, tm.Month, tm.Year+YEAR_OFFSET_PCF), tm.Month, 0, tm.Year);
|
|
||||||
((PCF8563 *) _rtc)->rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
|
|
||||||
clearAlarm();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int WatchyRTC::_getDayOfWeek(int d, int m, int y) {
|
|
||||||
static int t[] = { 0, 3, 2, 5, 0, 3,
|
|
||||||
5, 1, 4, 6, 2, 4 };
|
|
||||||
y -= m < 3;
|
|
||||||
return ( y + y / 4 - y / 100 +
|
|
||||||
y / 400 + t[m - 1] + d) % 7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t WatchyRTC::temperature(){
|
uint8_t WatchyRTC::temperature(){
|
||||||
|
|
|
@ -56,6 +56,7 @@ class DS3232 : public AbstractRTC {
|
||||||
public:
|
public:
|
||||||
DS3232RTC rtc_ds; // TODO: We should not have public member variables
|
DS3232RTC rtc_ds; // TODO: We should not have public member variables
|
||||||
~DS3232() {}
|
~DS3232() {}
|
||||||
|
|
||||||
void config(String datetime) {
|
void config(String datetime) {
|
||||||
if (datetime != "") {
|
if (datetime != "") {
|
||||||
tmElements_t tm;
|
tmElements_t tm;
|
||||||
|
@ -75,12 +76,23 @@ public:
|
||||||
rtc_ds.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 0); //alarm wakes up Watchy every minute
|
rtc_ds.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 0); //alarm wakes up Watchy every minute
|
||||||
rtc_ds.alarmInterrupt(ALARM_2, true); //enable alarm interrupt
|
rtc_ds.alarmInterrupt(ALARM_2, true); //enable alarm interrupt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearAlarm() {
|
||||||
|
rtc_ds.alarm(ALARM_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(tmElements_t tm) {
|
||||||
|
tm.Year = tm.Year + 2000 - YEAR_OFFSET_DS3232;
|
||||||
|
time_t t = makeTime(tm);
|
||||||
|
rtc_ds.set(t);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PCF8563 : public AbstractRTC {
|
class PCF8563 : public AbstractRTC {
|
||||||
public:
|
public:
|
||||||
Rtc_Pcf8563 rtc_pcf; // TODO: We should not have public member variables
|
Rtc_Pcf8563 rtc_pcf; // TODO: We should not have public member variables
|
||||||
~PCF8563() {}
|
~PCF8563() {}
|
||||||
|
|
||||||
void config(String datetime) {
|
void config(String datetime) {
|
||||||
if (datetime != "") {
|
if (datetime != "") {
|
||||||
int Year = getValue(datetime, ':', 0).toInt();
|
int Year = getValue(datetime, ':', 0).toInt();
|
||||||
|
@ -90,13 +102,17 @@ public:
|
||||||
int Minute = getValue(datetime, ':', 4).toInt();
|
int Minute = getValue(datetime, ':', 4).toInt();
|
||||||
int Second = getValue(datetime, ':', 5).toInt();
|
int Second = getValue(datetime, ':', 5).toInt();
|
||||||
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
||||||
rtc_pcf.setDate(Day, getDayOfWeek(Day, Month, Year), Month, 0, Year - YEAR_OFFSET_PCF);//offset from 2000
|
int dayOfWeek = getDayOfWeek(Day, Month, Year);
|
||||||
|
|
||||||
|
// offset from 2000
|
||||||
|
rtc_pcf.setDate(Day, dayOfWeek, Month, 0, Year - YEAR_OFFSET_PCF);
|
||||||
//hr, min, sec
|
//hr, min, sec
|
||||||
rtc_pcf.setTime(Hour, Minute, Second);
|
rtc_pcf.setTime(Hour, Minute, Second);
|
||||||
}
|
}
|
||||||
|
|
||||||
clearAlarm();
|
clearAlarm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearAlarm() {
|
void clearAlarm() {
|
||||||
int nextAlarmMinute = 0;
|
int nextAlarmMinute = 0;
|
||||||
rtc_pcf.clearAlarm(); // resets the alarm flag in the RTC
|
rtc_pcf.clearAlarm(); // resets the alarm flag in the RTC
|
||||||
|
@ -104,6 +120,13 @@ public:
|
||||||
nextAlarmMinute = (nextAlarmMinute == 59) ? 0 : (nextAlarmMinute + 1); //set alarm to trigger 1 minute from now
|
nextAlarmMinute = (nextAlarmMinute == 59) ? 0 : (nextAlarmMinute + 1); //set alarm to trigger 1 minute from now
|
||||||
rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
|
rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set(tmElements_t tm) {
|
||||||
|
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.setTime(tm.Hour, tm.Minute, tm.Second);
|
||||||
|
clearAlarm();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
int getDayOfWeek(int d, int m, int y) {
|
int getDayOfWeek(int d, int m, int y) {
|
||||||
static int t[] = { 0, 3, 2, 5, 0, 3,
|
static int t[] = { 0, 3, 2, 5, 0, 3,
|
||||||
|
@ -127,7 +150,6 @@ class WatchyRTC {
|
||||||
uint8_t temperature();
|
uint8_t temperature();
|
||||||
private:
|
private:
|
||||||
bool _canConnectTo(int addr);
|
bool _canConnectTo(int addr);
|
||||||
int _getDayOfWeek(int d, int m, int y);
|
|
||||||
AbstractRTC* _rtc;
|
AbstractRTC* _rtc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue