From 752a59c6b867588cf5d07fdcdfac8ef74a170da0 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Sun, 25 Nov 2018 19:40:43 +1300 Subject: [PATCH] Using patched MD_DS3231 instead of uDS3231 --- src/Debug.cpp | 2 +- src/Gps.cpp | 4 +-- src/Rtc.cpp | 4 +-- src/RtcAbstraction.cpp | 40 +++++++++++++-------------- src/RtcAbstraction.h | 63 +++++++++++++++++------------------------- src/Time2.h | 2 ++ src/config/System.h | 2 +- 7 files changed, 53 insertions(+), 64 deletions(-) diff --git a/src/Debug.cpp b/src/Debug.cpp index 009091a..9254119 100644 --- a/src/Debug.cpp +++ b/src/Debug.cpp @@ -197,7 +197,7 @@ namespace debug { tmElements_t time; rtc::getTime(time); - NOTICE_FORMAT("getAndDisplayRtcTime", "%d/%d/%d %d:%d:%d %t %d", tmYearToCalendar(time.year), time.month, time.day, time.hour, time.minute, time.second, rtc::isAccurate(), rtc::getTemperature()); + NOTICE_FORMAT("getAndDisplayRtcTime", "%d/%d/%d %d:%d:%d %t %d", time.year, time.month, time.day, time.hour, time.minute, time.second, rtc::isAccurate(), rtc::getTemperature()); } void setRtcTime() { diff --git a/src/Gps.cpp b/src/Gps.cpp index 6902165..9bb23af 100644 --- a/src/Gps.cpp +++ b/src/Gps.cpp @@ -105,13 +105,13 @@ namespace gps { VERBOSE_FORMAT("getTime", "%s", timeStr); - time.year = calendarYrToTm(details::parseSubstring(buffer, timeStr + TIME_YEAR_OFFSET, 4)); + time.year = details::parseSubstring(buffer, timeStr + TIME_YEAR_OFFSET, 4); time.month = details::parseSubstring(buffer, timeStr + TIME_MONTH_OFFSET, 2); time.day = details::parseSubstring(buffer, timeStr + TIME_DAY_OFFSET, 2); time.hour = details::parseSubstring(buffer, timeStr + TIME_HOUR_OFFSET, 2); time.minute = details::parseSubstring(buffer, timeStr + TIME_MINUTE_OFFSET, 2); time.second = details::parseSubstring(buffer, timeStr + TIME_SECOND_OFFSET, 2); - NOTICE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.year), time.month, time.day, time.hour, time.minute, time.second); + NOTICE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); } } \ No newline at end of file diff --git a/src/Rtc.cpp b/src/Rtc.cpp index 0f9e5d8..508411e 100644 --- a/src/Rtc.cpp +++ b/src/Rtc.cpp @@ -48,11 +48,11 @@ namespace rtc { RTC_A.readTime(time); hardware::i2c::powerOff(); - VERBOSE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.year), time.month, time.day, time.hour, time.minute, time.second); + VERBOSE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); } void setTime(const tmElements_t &time) { - VERBOSE_FORMAT("setTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.year), time.month, time.day, time.hour, time.minute, time.second); + VERBOSE_FORMAT("setTime", "%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); hardware::i2c::powerOn(); RTC_A.writeTime(time); diff --git a/src/RtcAbstraction.cpp b/src/RtcAbstraction.cpp index b7feca7..b3ece36 100644 --- a/src/RtcAbstraction.cpp +++ b/src/RtcAbstraction.cpp @@ -1,49 +1,47 @@ #include "RtcAbstraction.h" #ifndef USE_UDS3231 -#ifdef STOCK_MD_DS3231 - -void MDS3231_Ext::unpack(tmElements_t &time) { - time.second = s; - time.minute = m; - time.hour = h; - time.day = dd; - time.month = mm; - time.year = yyyy; + +void MD_DS3231_Ext::unpack(tmElements_t &time) { + time.second = MD_DS3231::s; + time.minute = MD_DS3231::m; + time.hour = MD_DS3231::h; + time.day = MD_DS3231::dd; + time.month = MD_DS3231::mm; + time.year = MD_DS3231::yyyy; } -void MDS3231_Ext::pack(const tmElements_t &time) { - s = time.second; - m = time.minute; - h = time.hour; - dd = time.day; - mm = time.month; - yyyy = time.year; +void MD_DS3231_Ext::pack(const tmElements_t &time) { + MD_DS3231::s = time.second; + MD_DS3231::m = time.minute; + MD_DS3231::h = time.hour; + MD_DS3231::dd = time.day; + MD_DS3231::mm = time.month; + MD_DS3231::yyyy = time.year; } -boolean MDS3231_Ext::readTime(tmElements_t &time) { +boolean MD_DS3231_Ext::readTime(tmElements_t &time) { bool result = MD_DS3231::readTime(); unpack(time); return result; } -boolean MDS3231_Ext::writeTime(const tmElements_t &time) { +boolean MD_DS3231_Ext::writeTime(const tmElements_t &time) { pack(time); return MD_DS3231::writeTime(); } -boolean MDS3231_Ext::readAlarm1(alm1Type_t &almType, tmElements_t &time) { +boolean MD_DS3231_Ext::readAlarm1(almType_t &almType, tmElements_t &time) { almType = MD_DS3231::getAlarm1Type(); bool result = MD_DS3231::readAlarm1(); return result; } -boolean MDS3231_Ext::writeAlarm1(alm1Type_t almType, const tmElements_t &time) { +boolean MD_DS3231_Ext::writeAlarm1(almType_t almType, const tmElements_t &time) { pack(time); return MD_DS3231::writeAlarm1(almType); } -#endif #endif \ No newline at end of file diff --git a/src/RtcAbstraction.h b/src/RtcAbstraction.h index 28c9dfb..ff5a6e1 100644 --- a/src/RtcAbstraction.h +++ b/src/RtcAbstraction.h @@ -6,7 +6,6 @@ * the stock MD_DS3231 one. */ // #define USE_UDS3231 -//#define STOCK_MD_DS3231 #ifdef USE_UDS3231 #include @@ -14,40 +13,30 @@ #define RTC_A_CLASS uDS3231 #define WRITE_ALARM_1(t) RTC_A.writeAlarm1(DS3231_ALM_HMS, t) #else - #ifdef STOCK_MD_DS3231 - #include - - typedef unsigned long timestamp_t; - - typedef struct tmElements_t { - uint8_t Second; - uint8_t Minute; - uint8_t Hour; - uint8_t Day; - uint8_t month; - uint8_t year; // year from 2000 - }; - - class MD_DS3231_Ext : public MD_DS3231 - { - private: - void unpack(tmElements_t &time); - void pack(const tmElements_t &time); - public: - boolean readTime(tmElements_t &time); - boolean writeTime(const tmElements_t &time); - - boolean readAlarm1(almType_t &almType, tmElements_t &time); - boolean writeAlarm1(almType_t almType, const tmElements_t &time); - }; - - #define RTC_A_CLASS MD_DS3231_Ext - #define WRITE_ALARM_1(t) RTC_A.writeAlarm1(DS3231_ALM_HMS, t) - #else - #include - #define RTC_A_CLASS MD_DS3231 - #define WRITE_ALARM_1(t) RTC_A.writeAlarm1(alm1Type_t::ALM_HMS, t) - - typedef unsigned long timestamp_t; - #endif + #include + + typedef struct tmElements_t { + uint8_t second = 0; + uint8_t minute = 0; + uint8_t hour = 0; + uint8_t day = 0; + uint8_t month = 0; + uint16_t year = 0; // year from 2000 + }; + + class MD_DS3231_Ext : public MD_DS3231 + { + private: + void unpack(tmElements_t &time); + void pack(const tmElements_t &time); + public: + boolean readTime(tmElements_t &time); + boolean writeTime(const tmElements_t &time); + + boolean readAlarm1(almType_t &almType, tmElements_t &time); + boolean writeAlarm1(almType_t almType, const tmElements_t &time); + }; + + #define RTC_A_CLASS MD_DS3231_Ext + #define WRITE_ALARM_1(t) RTC_A.writeAlarm1(DS3231_ALM_HMS, t) #endif \ No newline at end of file diff --git a/src/Time2.h b/src/Time2.h index fa4f1f5..50db9fb 100644 --- a/src/Time2.h +++ b/src/Time2.h @@ -3,6 +3,8 @@ #include #include "RtcAbstraction.h" +typedef unsigned long timestamp_t; + namespace utils { namespace time { diff --git a/src/config/System.h b/src/config/System.h index 9240bb1..331672c 100644 --- a/src/config/System.h +++ b/src/config/System.h @@ -20,7 +20,7 @@ \def VERSION Version string, only used for indicative purpose */ -#define VERSION "1.22" +#define VERSION "1.30" /**