Compare commits

...

2 Commits

Author SHA1 Message Date
8a6170cb10 Add get alarm helper to reduce code duplication 2020-05-17 20:11:35 +02:00
21f9215bba Implement getting alarm times 2020-05-17 20:06:13 +02:00

View File

@@ -142,6 +142,15 @@ class DS3231 {
return dateTime;
}
static DateTime getAlarm1()
{
return getAlarmHelper<ALARM1_REG_ADDR>();
}
static DateTime getAlarm2()
{
return getAlarmHelper<ALARM2_REG_ADDR>();
}
static void setDate(const Date &date)
{
detail::TimeReg timeReg;
@@ -299,6 +308,24 @@ class DS3231 {
writePartialRegister<0, sizeof(Register) - 1>(reg);
}
template <uint8_t Address>
static inline auto getAlarmHelper()
{
constexpr auto IsAlarm1 = Address == ALARM1_REG_ADDR;
static_assert(IsAlarm1 || Address == ALARM2_REG_ADDR, "Must use valid alarm address");
const auto alarmReg = readRegister<Address>();
DateTime alarmTime = {};
alarmReg.getDate(alarmTime.day);
alarmTime.hour = alarmReg.getHours();
alarmTime.minute = alarmReg.getMinutes();
if constexpr (IsAlarm1)
alarmTime.second = alarmReg.getSeconds();
return alarmTime;
}
template <typename AlarmRate>
static inline void setAlarmHelper(const DateTime &alarmTime, const AlarmRate &alarmRate)
{