From cd5317db5bff25753f56dc3fe90d3641291cbf50 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 16 May 2020 17:03:30 +0200 Subject: [PATCH] Implement setting RTC date --- ds3231.hpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ds3231.hpp b/ds3231.hpp index f7f0c6c..9557c6c 100644 --- a/ds3231.hpp +++ b/ds3231.hpp @@ -2,6 +2,8 @@ #include "../clock.hpp" +#include + #include "../i2c/i2c.hpp" #include "../type/type.hpp" @@ -85,7 +87,19 @@ class DS3231 { return dateTime; } - static void setDate(const Date &date) {} + static void setDate(const Date &date) + { + detail::TimeReg timeReg; + timeReg.setYear(date.year); + timeReg.setMonth(date.month); + timeReg.setDate(date.day); + if constexpr (SetDayOfWeek) { + timeReg.setDay(calcDayOfWeek(date.year, date.month, date.day) + 1); + } + + constexpr auto DATE_OFFSET = offsetof(detail::TimeReg, day); + writePartialRegister(timeReg); + } static void setTime(const Time &time) {} static void setDateTime(const DateTime &dateTime) {}