Moving RTC time offset function to seperate function
Preparing for flexible redraw intervals, and DST
This commit is contained in:
parent
e6a8b33b37
commit
c49d17e482
2 changed files with 18 additions and 11 deletions
|
@ -22,7 +22,8 @@ void WatchyRTC::clearAlarm() {
|
|||
rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
|
||||
}
|
||||
|
||||
void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds) {
|
||||
void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds)
|
||||
{
|
||||
rtc_pcf.getDate();
|
||||
tm.Year = y2kYearToTm(rtc_pcf.getYear());
|
||||
tm.Month = rtc_pcf.getMonth();
|
||||
|
@ -32,6 +33,20 @@ void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds) {
|
|||
tm.Minute = rtc_pcf.getMinute();
|
||||
tm.Second = rtc_pcf.getSecond();
|
||||
|
||||
OffsetTime(tm, offsetInSeconds);
|
||||
}
|
||||
|
||||
void WatchyRTC::set(tmElements_t tm) {
|
||||
time_t t = makeTime(tm); // make and break to calculate tm.Wday
|
||||
breakTime(t, tm);
|
||||
// day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
||||
rtc_pcf.setDate(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year));
|
||||
rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
|
||||
clearAlarm();
|
||||
}
|
||||
|
||||
void WatchyRTC::OffsetTime(tmElements_t & tm, int offsetInSeconds)
|
||||
{
|
||||
int year = tm.Year;
|
||||
int month = tm.Month;
|
||||
int day = tm.Day;
|
||||
|
@ -94,15 +109,6 @@ void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds) {
|
|||
tm.Second = second;
|
||||
}
|
||||
|
||||
void WatchyRTC::set(tmElements_t tm) {
|
||||
time_t t = makeTime(tm); // make and break to calculate tm.Wday
|
||||
breakTime(t, tm);
|
||||
// day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
||||
rtc_pcf.setDate(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year));
|
||||
rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
|
||||
clearAlarm();
|
||||
}
|
||||
|
||||
void WatchyRTC::_PCFConfig(String datetime) { // String datetime is YYYY:MM:DD:HH:MM:SS
|
||||
if (datetime != "") {
|
||||
tmElements_t tm;
|
||||
|
|
|
@ -21,9 +21,10 @@ public:
|
|||
void read(tmElements_t & tm, int offsetInSeconds = 0);
|
||||
void set(tmElements_t tm);
|
||||
|
||||
static void OffsetTime(tmElements_t & tm, int offsetInSeconds);
|
||||
|
||||
private:
|
||||
void _PCFConfig(String datetime);
|
||||
int _getDayOfWeek(int d, int m, int y);
|
||||
String _getValue(String data, char separator, int index);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue