Implement optional automatic setting of day of week
This commit is contained in:
parent
c728d99f97
commit
80cce4671f
@ -24,7 +24,7 @@ struct Time {
|
|||||||
struct DateTime : Date, Time {
|
struct DateTime : Date, Time {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename I2cDriver>
|
template <typename I2cDriver, bool SetDayOfWeek = true>
|
||||||
class DS3231 {
|
class DS3231 {
|
||||||
public:
|
public:
|
||||||
static constexpr auto I2C_ADDRESS = 0x68;
|
static constexpr auto I2C_ADDRESS = 0x68;
|
||||||
@ -125,6 +125,13 @@ class DS3231 {
|
|||||||
static_assert(type::always_false_v<decltype(Address)>, "Invalid register address");
|
static_assert(type::always_false_v<decltype(Address)>, "Invalid register address");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t calcDayOfWeek(uint16_t year, uint8_t month, uint16_t day)
|
||||||
|
{
|
||||||
|
day += month < 3 ? year-- : year - 2;
|
||||||
|
const auto dayOfWeek = (23 * month / 9 + day + 4 + year / 4 - year / 100 + year / 400);
|
||||||
|
return dayOfWeek % 7;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rtc
|
} // namespace rtc
|
||||||
|
Loading…
Reference in New Issue
Block a user