mirror of https://github.com/sqfmi/Watchy.git
fixed setting datetime
parent
ca8e170147
commit
8fb1902cbe
|
@ -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--;
|
||||
|
|
|
@ -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();
|
||||
tm.Day = rtc_pcf.getDay();
|
||||
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.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)
|
||||
|
|
Loading…
Reference in New Issue