diff --git a/src/Watchy.cpp b/src/Watchy.cpp index 1ab935d..2b67209 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -341,7 +341,7 @@ void Watchy::setTime(){ minute == 59 ? (minute = 0) : minute++; break; case SET_YEAR: - year == 99 ? (year = 21) : year++; + year == 99 ? (year = 0) : year++; break; case SET_MONTH: month == 12 ? (month = 1) : month++; @@ -364,7 +364,7 @@ void Watchy::setTime(){ minute == 0 ? (minute = 59) : minute--; break; case SET_YEAR: - year == 21 ? (year = 99) : year--; + year == 0 ? (year = 99) : year--; break; case SET_MONTH: month == 1 ? (month = 12) : month--; diff --git a/src/WatchyRTC.cpp b/src/WatchyRTC.cpp index 3b6e558..298c7b6 100644 --- a/src/WatchyRTC.cpp +++ b/src/WatchyRTC.cpp @@ -46,12 +46,17 @@ void WatchyRTC::read(tmElements_t &tm){ tm.Year = tm.Year - 30; //reset to offset from 2000 }else{ tm.Month = rtc_pcf.getMonth(); + if(tm.Month == 0){ //PCF8563 POR sets month = 0 for some reason + tm.Month = 1; + tm.Year = 21; + }else{ + tm.Year = rtc_pcf.getYear(); + } tm.Day = rtc_pcf.getDay(); - tm.Year = rtc_pcf.getYear(); + tm.Wday = rtc_pcf.getWeekday() + 1; tm.Hour = rtc_pcf.getHour(); tm.Minute = rtc_pcf.getMinute(); tm.Second = rtc_pcf.getSecond(); - tm.Wday = rtc_pcf.getWeekday() + 1; } } @@ -63,10 +68,7 @@ void WatchyRTC::set(tmElements_t tm){ }else{ rtc_pcf.setDate(tm.Day, _getDayOfWeek(tm.Day, tm.Month, tm.Year+YEAR_OFFSET_PCF), tm.Month, 0, tm.Year); rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second); - rtc_pcf.clearAlarm(); - int nextAlarmMinute = rtc_pcf.getMinute(); - nextAlarmMinute = (nextAlarmMinute == 59) ? 0 : (nextAlarmMinute + 1); - rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99); + clearAlarm(); } } @@ -97,25 +99,20 @@ void WatchyRTC::_DSConfig(String datetime){ } void WatchyRTC::_PCFConfig(String datetime){ - rtc_pcf.initClock(); if(datetime != ""){ tmElements_t tm; - tm.Year = _getValue(datetime, ':', 0).toInt(); - tm.Month = _getValue(datetime, ':', 1).toInt(); - tm.Day = _getValue(datetime, ':', 2).toInt(); - tm.Hour = _getValue(datetime, ':', 3).toInt(); - tm.Minute = _getValue(datetime, ':', 4).toInt(); - tm.Second = _getValue(datetime, ':', 5).toInt(); - + int Year = _getValue(datetime, ':', 0).toInt(); + int Month = _getValue(datetime, ':', 1).toInt(); + int Day = _getValue(datetime, ':', 2).toInt(); + int Hour = _getValue(datetime, ':', 3).toInt(); + int Minute = _getValue(datetime, ':', 4).toInt(); + int Second = _getValue(datetime, ':', 5).toInt(); //day, weekday, month, century(1=1900, 0=2000), year(0-99) - rtc_pcf.setDate(tm.Day, _getDayOfWeek(tm.Day, tm.Month, tm.Year), tm.Month, 0, tm.Year - YEAR_OFFSET_PCF);//offset from 2000, since year is stored in uint8_t + rtc_pcf.setDate(Day, _getDayOfWeek(Day, Month, Year), Month, 0, Year - YEAR_OFFSET_PCF);//offset from 2000 //hr, min, sec - rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second); + rtc_pcf.setTime(Hour, Minute, Second); } - rtc_pcf.clearAlarm(); - int nextAlarmMinute = rtc_pcf.getMinute(); - nextAlarmMinute = (nextAlarmMinute == 59) ? 0 : (nextAlarmMinute + 1); - rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99); + clearAlarm(); } int WatchyRTC::_getDayOfWeek(int d, int m, int y)