Implement checking and clearing alarm
This commit is contained in:
parent
3029c3cfe0
commit
ff52f4f152
41
ds3231.hpp
41
ds3231.hpp
@ -187,6 +187,24 @@ class DS3231 {
|
||||
writePartialRegister<START_OFFSET, END_OFFSET>(timeReg);
|
||||
}
|
||||
|
||||
static bool checkAlarm1()
|
||||
{
|
||||
return checkAlarmHelper<detail::ControlStatusRegFlags::A1F>();
|
||||
}
|
||||
static bool checkAlarm2()
|
||||
{
|
||||
return checkAlarmHelper<detail::ControlStatusRegFlags::A2F>();
|
||||
}
|
||||
|
||||
static void clearAlarm1()
|
||||
{
|
||||
clearAlarmHelper<detail::ControlStatusRegFlags::A1F>();
|
||||
}
|
||||
static void clearAlarm2()
|
||||
{
|
||||
clearAlarmHelper<detail::ControlStatusRegFlags::A2F>();
|
||||
}
|
||||
|
||||
private:
|
||||
template <uint8_t Address, typename Register>
|
||||
static Register readRegisterHelper()
|
||||
@ -268,6 +286,29 @@ class DS3231 {
|
||||
writePartialRegister<0, sizeof(Register) - 1>(reg);
|
||||
}
|
||||
|
||||
template <detail::ControlStatusRegFlags AlarmFlag>
|
||||
static inline bool checkAlarmHelper()
|
||||
{
|
||||
constexpr auto IsAlarm1Flag = AlarmFlag == detail::ControlStatusRegFlags::A1F;
|
||||
constexpr auto IsAlarm2Flag = AlarmFlag == detail::ControlStatusRegFlags::A2F;
|
||||
static_assert(IsAlarm1Flag || IsAlarm2Flag, "Must use valid alarm flag");
|
||||
|
||||
const auto alarmStatus = readRegister<CONTROL_STATUS_REG_ADDR>();
|
||||
return alarmStatus == AlarmFlag;
|
||||
}
|
||||
|
||||
template <detail::ControlStatusRegFlags AlarmFlag>
|
||||
static inline void clearAlarmHelper()
|
||||
{
|
||||
constexpr auto IsAlarm1Flag = AlarmFlag == detail::ControlStatusRegFlags::A1F;
|
||||
constexpr auto IsAlarm2Flag = AlarmFlag == detail::ControlStatusRegFlags::A2F;
|
||||
static_assert(IsAlarm1Flag || IsAlarm2Flag, "Must use valid alarm flag");
|
||||
|
||||
auto controlStatusReg = readRegister<CONTROL_STATUS_REG_ADDR>();
|
||||
controlStatusReg &= ~AlarmFlag;
|
||||
writeRegister(controlStatusReg);
|
||||
}
|
||||
|
||||
static uint8_t calcDayOfWeek(uint16_t year, uint8_t month, uint16_t day)
|
||||
{
|
||||
day += month < 3 ? year-- : year - 2;
|
||||
|
Loading…
Reference in New Issue
Block a user