9#ifdef USE_BINARY_SENSOR
40 void setup()
override;
65#ifdef USE_BINARY_SENSOR
73 bool read_calendar(uint8_t *
raw);
84 uint8_t day_of_week,
bool enabled);
138 void write_alarm_(uint8_t alarm,
const uint8_t *regs,
size_t len,
bool enabled);
BedjetMode mode
BedJet operating mode.
Hub for a single DS3231 real-time clock.
void enable_square_wave(SquareWaveFrequency frequency)
Switch INT/SQW to a square-wave output at frequency. Alarms then no longer drive the pin.
void publish_oscillator_stopped_()
uint32_t alarm_check_interval_
void write_alarm_(uint8_t alarm, const uint8_t *regs, size_t len, bool enabled)
Write the alarm registers, clear the stale flag and set the interrupt enable.
void set_output_32khz(bool enabled)
static constexpr uint8_t STATUS_FLAGS
static constexpr uint8_t STATUS_A1F
static constexpr uint8_t STATUS_OSF
static constexpr uint8_t CONTROL_A2IE
void set_aging_offset(int8_t offset)
Aging offset in LSB (about 0.1 ppm each at 25 degC); positive values slow the clock down.
bool write_status_(uint8_t clear)
Write the status register, clearing the flags in clear (writing 1 to a flag leaves it unchanged).
static constexpr uint8_t CONTROL_BBSQW
void set_square_wave_frequency(SquareWaveFrequency frequency)
static constexpr uint8_t CONTROL_RS_SHIFT
void check_alarms_()
Read the flags, fire triggers and update the binary sensors.
SquareWaveFrequency square_wave_frequency_
void clear_alarm(uint8_t alarm)
Clear the alarm flag, which also releases the INT/SQW line.
bool write_aging_offset_(int8_t offset)
void dump_config() override
bool aging_offset_configured_
static constexpr uint8_t CONTROL_A1IE
static constexpr uint8_t CONTROL_INTCN
bool read_temperature(float &out)
static void interrupt_handler(DS3231Component *arg)
static constexpr uint8_t STATUS_BSY
SUB_BINARY_SENSOR(alarm_1) SUB_BINARY_SENSOR(alarm_2) SUB_BINARY_SENSOR(oscillator_stopped) bool read_calendar(uint8_t *raw)
Read the calendar registers into raw. Fails if the oscillator was stopped since the time was last set...
static constexpr uint8_t STATUS_A2F
LazyCallbackManager< void(uint8_t)> alarm_callback_
bool square_wave_configured_
void enable_alarm(uint8_t alarm)
Enable alarm. A match from while it was disabled is cleared first, so only the next one fires.
void set_output_32khz_config(bool enabled)
void disable_alarm(uint8_t alarm)
void set_alarm_2(AlarmMode mode, uint8_t minute, uint8_t hour, uint8_t day_of_month, uint8_t day_of_week, bool enabled)
Program alarm 2 (minute resolution, fires at second 00).
void set_aging_offset_config(int8_t offset)
static constexpr uint8_t STATUS_EN32KHZ
static constexpr uint8_t CONTROL_RS_MASK
static constexpr uint8_t CONTROL_EOSC
InternalGPIOPin * interrupt_pin_
void set_interrupt_pin(InternalGPIOPin *pin)
static constexpr uint32_t ALARM_PULSE_TIMEOUT_ID
Scheduler ids: one pulse timer per alarm (id + alarm - 1).
void set_alarm_enabled_(uint8_t alarm, bool enabled)
bool read_control_status_()
Read the control and status registers into the cached copies. Sets the warning flag on failure.
void set_auto_clear_alarms(bool auto_clear)
bool update_control_(uint8_t mask, uint8_t value)
Replace the bits in mask of the control register with value, on the chip and in the cache.
int8_t battery_backed_square_wave_
-1: leave the chip as it is, 0: off, 1: on.
void disable_square_wave()
Switch INT/SQW back to the (active-low) alarm interrupt output.
void set_alarm_1(AlarmMode mode, uint8_t second, uint8_t minute, uint8_t hour, uint8_t day_of_month, uint8_t day_of_week, bool enabled)
Program alarm 1. day_of_month is used in MONTHLY mode, day_of_week (1 = Sunday) in WEEKLY mode.
static constexpr uint8_t CONTROL_CONV
void set_monitor_alarms(bool monitor)
void set_alarm_check_interval(uint32_t interval)
void set_battery_backed_square_wave(bool enabled)
bool alarm_active_[2]
Set while an alarm flag has been reported, so a latched flag fires its trigger only once.
bool is_alarm_triggered(uint8_t alarm)
True while the alarm flag of alarm (1 or 2) is set on the chip.
void add_on_alarm_callback(F &&callback)
Register a void(uint8_t alarm) callback that runs when an enabled alarm (1 or 2) matches.
void force_temperature_conversion()
void publish_alarm_state_(uint8_t alarm, bool state)
bool write_calendar(const uint8_t *raw)
Write the calendar registers from raw and clear the oscillator-stop flag.
bool clear_alarm_flag_(uint8_t alarm)
Clear the flag of alarm and report it off. Returns false (state unchanged) if that fails.
static constexpr size_t CALENDAR_LEN
Seconds through year, the 7-byte BCD calendar the time platform decodes with time::DS_BCD_CALENDAR.
This Class provides the methods to read/write bytes from/to an i2c device.
std::vector< uint8_t > & out
AlarmMode
When an alarm fires. Alarm 1 supports every mode, alarm 2 has no seconds register and so no EVERY_SEC...
@ ALARM_MODE_WEEKLY
When day of week, hours, minutes (and seconds) match.
@ ALARM_MODE_EVERY_SECOND
Alarm 1 only.
@ ALARM_MODE_DAILY
When hours, minutes (and seconds) match.
@ ALARM_MODE_MONTHLY
When date, hours, minutes (and seconds) match.
@ ALARM_MODE_EVERY_MINUTE
Alarm 1: when the seconds match. Alarm 2: at second 00 of every minute.
@ ALARM_MODE_HOURLY
When minutes (and seconds) match.
SquareWaveFrequency
Frequency of the INT/SQW pin when it is a square-wave output (RS2:RS1 in the control register).