1 #ifndef ACE_TIME_DS3231_TIME_KEEPER_H 2 #define ACE_TIME_DS3231_TIME_KEEPER_H 7 #include "../hw/DS3231.h" 8 #include "../hw/HardwareDateTime.h" 9 #include "../LocalDateTime.h" 10 #include "TimeKeeper.h" 18 class DS3231TimeKeeper:
public TimeKeeper {
20 explicit DS3231TimeKeeper() {}
24 acetime_t getNow()
const override {
25 hw::HardwareDateTime hardwareDateTime;
26 mDS3231.readDateTime(&hardwareDateTime);
27 return toDateTime(hardwareDateTime).toEpochSeconds();
30 void setNow(acetime_t epochSeconds)
override {
31 if (epochSeconds == kInvalidSeconds)
return;
34 mDS3231.setDateTime(toHardwareDateTime(now));
42 static LocalDateTime toDateTime(
const hw::HardwareDateTime& dt) {
45 dt.hour, dt.minute, dt.second);
54 static hw::HardwareDateTime toHardwareDateTime(
const LocalDateTime& dt) {
55 return hw::HardwareDateTime{(uint8_t) dt.yearTiny(), dt.month(),
56 dt.day(), dt.hour(), dt.minute(), dt.second(), dt.dayOfWeek()};
59 const hw::DS3231 mDS3231;
static LocalDateTime forEpochSeconds(acetime_t epochSeconds)
Factory method.
static LocalDateTime forComponents(int16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
Factory method using separated date and time components.
static const int16_t kEpochYear
Base year of epoch.