From c49d17e482c7d8afbc955d6dc422d0a0455b766d Mon Sep 17 00:00:00 2001 From: Lewis Jackson <> Date: Mon, 29 May 2023 14:51:39 +0300 Subject: [PATCH] Moving RTC time offset function to seperate function Preparing for flexible redraw intervals, and DST --- src/WatchyRTC.cpp | 26 ++++++++++++++++---------- src/WatchyRTC.h | 3 ++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/WatchyRTC.cpp b/src/WatchyRTC.cpp index 3511f6e..a77a847 100644 --- a/src/WatchyRTC.cpp +++ b/src/WatchyRTC.cpp @@ -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; diff --git a/src/WatchyRTC.h b/src/WatchyRTC.h index 238d99e..7f3ede7 100644 --- a/src/WatchyRTC.h +++ b/src/WatchyRTC.h @@ -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); };