6 #ifndef ACE_TIME_DS3231_CLOCK_H 7 #define ACE_TIME_DS3231_CLOCK_H 12 #include "../hw/DS3231.h" 13 #include "../hw/HardwareDateTime.h" 14 #include "../LocalDateTime.h" 23 class DS3231Clock:
public Clock {
25 explicit DS3231Clock() {}
29 acetime_t getNow()
const override {
30 hw::HardwareDateTime hardwareDateTime;
31 mDS3231.readDateTime(&hardwareDateTime);
32 return toDateTime(hardwareDateTime).toEpochSeconds();
35 void setNow(acetime_t epochSeconds)
override {
36 if (epochSeconds == kInvalidSeconds)
return;
39 mDS3231.setDateTime(toHardwareDateTime(now));
47 static LocalDateTime toDateTime(
const hw::HardwareDateTime& dt) {
50 dt.hour, dt.minute, dt.second);
59 static hw::HardwareDateTime toHardwareDateTime(
const LocalDateTime& dt) {
60 return hw::HardwareDateTime{(uint8_t) dt.yearTiny(), dt.month(),
61 dt.day(), dt.hour(), dt.minute(), dt.second(), dt.dayOfWeek()};
64 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.