ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
rx8111.h
Go to the documentation of this file.
1#pragma once
2
6#ifdef USE_BINARY_SENSOR
8#endif
9#ifdef USE_RX8111_TIMESTAMP
11#endif
12
13namespace esphome::rx8111 {
14
20
21#ifdef USE_BINARY_SENSOR
33#endif
34
36 enum State : uint8_t { UNREAD, FAILED, VALID };
38 uint8_t value{0};
39};
40
41namespace testing {
42class RX8111Test;
43} // namespace testing
44
46 public:
47 void setup() override;
48 void update() override;
49 void dump_config() override;
50 void read_time();
51 void write_time();
52 void set_alarm_enabled(bool enabled) { this->alarm_enabled_ = enabled; }
53 void set_alarm_explicitly_configured(bool configured) { this->alarm_explicitly_configured_ = configured; }
54 void set_alarm_second(uint8_t value) { this->alarm_second_ = value; }
55 void set_alarm_minute(uint8_t value) { this->alarm_minute_ = value; }
56 void set_alarm_hour(uint8_t value) { this->alarm_hour_ = value; }
57 void set_alarm_weekday(uint8_t value) { this->alarm_weekday_ = value; }
58 void set_alarm_day(uint8_t value) { this->alarm_day_ = value; }
60 void set_timer_clock(uint8_t clock) { this->timer_clock_ = clock; }
61 void set_timer_enabled(bool enabled) { this->timer_enabled_ = enabled; }
62 void set_timer_configured(bool configured) { this->timer_configured_ = configured; }
63 void set_event_poll_interval(uint32_t interval) { this->event_poll_interval_ = interval; }
64 void set_evin_settings(uint8_t settings) { this->evin_settings_ = settings; }
65#ifdef USE_BINARY_SENSOR
66 void set_status_sensor(uint8_t index, binary_sensor::BinarySensor *sensor) {
67 if (index < STATUS_SENSOR_COUNT)
68 this->status_sensors_[index] = sensor;
69 }
70#endif
71#ifdef USE_RX8111_TIMESTAMP
77#endif
78 void set_battery_backup(bool enabled, bool charging) {
79 this->battery_configured_ = true;
80 this->battery_backup_ = enabled;
81 this->battery_charging_ = charging;
82 }
84 this->fout_configured_ = true;
86 }
87 void set_event_config(uint8_t settings) {
88 this->event_configured_ = true;
89 this->event_enabled_ = true;
90 this->evin_settings_ = settings;
91 }
93 this->event_configured_ = true;
94 this->event_enabled_ = false;
95 }
96 template<typename F> void add_on_event_callback(F &&callback) {
97 this->event_callbacks_.add(std::forward<F>(callback));
98 }
99 bool clear_event_flag();
100 template<typename F> void add_on_alarm_callback(F &&callback) {
101 this->alarm_callbacks_.add(std::forward<F>(callback));
102 }
103 bool set_alarm(uint16_t second, uint16_t minute, uint16_t hour, uint16_t weekday, uint16_t day);
104 bool schedule_alarm_in(uint32_t seconds);
105 bool unset_alarm();
106 bool clear_alarm_flag();
107 bool clear_timer_flag();
108 bool start_timer();
109 bool stop_timer();
110 template<typename F> void add_on_timer_callback(F &&callback) {
111 this->timer_callbacks_.add(std::forward<F>(callback));
112 }
113
114 protected:
115 friend class testing::RX8111Test;
116
117 static constexpr uint32_t BOOT_RETRY_DELAY_MS = 1000;
118 // set_alarm() and the boot alarm ignore a field set to this value
119 static constexpr uint8_t ALARM_FIELD_UNSET = 0xFF;
120
121 // One bit per fault source, so a recovery in one path cannot hide another path's fault
122 enum Warning : uint16_t {
125 WARN_ALARM = 1 << 2,
126 WARN_TIMER = 1 << 3,
130 WARN_BATTERY = 1 << 7,
131 WARN_FOUT = 1 << 8,
132 WARN_EVENT = 1 << 9,
134 WARN_TIMESTAMP = 1 << 11,
135 };
136
137 bool set_stop_bit_(bool stop);
138 bool finish_time_write_(bool calendar_written);
139 bool read_calendar_(ESPTime &rtc_time, FlagSnapshot *flags = nullptr);
141 void run_deferred_update_(bool status_only);
142 void set_warning_(uint16_t bit, const LogString *message);
143 void clear_warning_(uint16_t bit);
148 void boot_config_result_(BootFeature feature, bool success);
149 bool watching_() const {
150#ifdef USE_BINARY_SENSOR
151 if (this->has_status_sensor_())
152 return true;
153#endif
154#ifdef USE_RX8111_TIMESTAMP
155 if (this->timestamp_sensor_ != nullptr && !this->event_boot_pending_)
156 return true;
157#endif
158 return this->alarm_armed_ || this->timer_enabled_ || this->timer_retained_event_pending_ ||
159 (this->event_enabled_ && !this->event_boot_pending_ && !this->event_callbacks_.empty());
160 }
162 bool configure_event_();
163#ifdef USE_RX8111_TIMESTAMP
164 bool publish_timestamps_(uint8_t flags, bool buffered, bool startup = false);
166 void deliver_timestamps_(const uint8_t *records, uint8_t count, bool buffered);
167 void publish_timestamp_(const uint8_t *raw, bool buffered);
169 uint8_t last_timestamp_[10]{};
170 uint8_t staged_timestamps_[64]{};
171 uint8_t staged_count_{0};
172 uint8_t retained_flags_{0};
174 bool timestamps_staged_ : 1 {false};
175 bool defer_timestamps_ : 1 {false}; // setup() delivers retained records after the alarm and timer
176 bool timestamp_clear_pending_ : 1 {false};
177 bool retained_flags_seen_ : 1 {false};
178 bool staged_buffered_ : 1 {false};
179 bool retained_evidence_seen_ : 1 {false};
181 bool timestamp_seen_ : 1 {false};
182 bool capture_restore_pending_ : 1 {false};
183#endif
185#ifdef USE_BINARY_SENSOR
186 bool has_status_sensor_() const {
187 for (auto *sensor : this->status_sensors_) {
188 if (sensor != nullptr)
189 return true;
190 }
191 return false;
192 }
194#endif
195 bool program_alarm_(uint8_t second, uint8_t minute, uint8_t hour, uint8_t weekday, uint8_t day, bool boot = false);
196 bool set_alarm_interrupt_(bool enabled);
197 bool disable_timer_(uint8_t &extension, uint8_t &control);
198 bool configure_timer_(bool clear_stale_flag = false);
200 bool poll_event_flags_(FlagSnapshot snapshot = {});
203 void cancel_boot_retry_(bool alarm);
204
211 uint16_t warnings_{0};
213 uint8_t evin_settings_{0};
214 uint8_t fout_frequency_{3};
215 uint8_t timer_clock_{2}; // 1 Hz
221 bool time_write_invalid_ : 1 {false};
222 bool update_running_ : 1 {false};
223 bool deferred_update_running_ : 1 {false};
224 bool sync_running_ : 1 {false};
225 bool poll_running_ : 1 {false};
226 bool battery_configured_ : 1 {false};
227 bool battery_backup_ : 1 {false};
228 bool battery_charging_ : 1 {false};
229 bool fout_configured_ : 1 {false};
230 bool event_configured_ : 1 {false};
231 bool event_enabled_ : 1 {false};
232 bool event_flag_seen_ : 1 {false};
233 bool event_boot_pending_ : 1 {false};
234 bool timer_enabled_ : 1 {false};
235 bool timer_configured_ : 1 {false};
236 bool timer_flag_seen_ : 1 {false};
238 bool event_polling_started_ : 1 {false};
239 bool boot_alarm_event_seen_ : 1 {false};
240 bool alarm_enabled_ : 1 {false};
242 bool alarm_flag_seen_ : 1 {false};
243 bool alarm_armed_ : 1 {false};
244 bool alarm_reprogrammed_ : 1 {false}; // set_alarm ran while a poll's callbacks were running
245};
246
247} // namespace esphome::rx8111
BedjetMode mode
BedJet operating mode.
uint8_t raw[35]
Definition bl0939.h:0
uint16_le_t frequency
Definition bl0942.h:6
Base class for all binary_sensor-type classes.
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
void deliver_timestamps_(const uint8_t *records, uint8_t count, bool buffered)
Definition rx8111.cpp:849
static constexpr uint8_t ALARM_FIELD_UNSET
Definition rx8111.h:119
bool set_alarm(uint16_t second, uint16_t minute, uint16_t hour, uint16_t weekday, uint16_t day)
Definition rx8111.cpp:602
LazyCallbackManager< void()> alarm_callbacks_
Definition rx8111.h:205
uint8_t boot_attempts_[BOOT_FEATURE_COUNT]
Definition rx8111.h:212
bool program_alarm_(uint8_t second, uint8_t minute, uint8_t hour, uint8_t weekday, uint8_t day, bool boot=false)
Definition rx8111.cpp:564
void set_timer_configured(bool configured)
Definition rx8111.h:62
bool poll_event_flags_(FlagSnapshot snapshot={})
Definition rx8111.cpp:750
bool disable_timer_(uint8_t &extension, uint8_t &control)
Definition rx8111.cpp:673
void set_timer_clock(uint8_t clock)
Definition rx8111.h:60
bool read_calendar_(ESPTime &rtc_time, FlagSnapshot *flags=nullptr)
Definition rx8111.cpp:470
void set_timer_count(uint32_t count)
Definition rx8111.h:59
void set_alarm_enabled(bool enabled)
Definition rx8111.h:52
void set_evin_settings(uint8_t settings)
Definition rx8111.h:64
void publish_timestamp_(const uint8_t *raw, bool buffered)
Definition rx8111.cpp:858
void set_alarm_weekday(uint8_t value)
Definition rx8111.h:57
void set_alarm_minute(uint8_t value)
Definition rx8111.h:55
bool schedule_alarm_in(uint32_t seconds)
Definition rx8111.cpp:626
binary_sensor::BinarySensor * status_sensors_[STATUS_SENSOR_COUNT]
Definition rx8111.h:193
void read_time_(FlagSnapshot &flags)
Definition rx8111.cpp:454
bool configure_timer_(bool clear_stale_flag=false)
Definition rx8111.cpp:680
void set_event_config(uint8_t settings)
Definition rx8111.h:87
void set_alarm_second(uint8_t value)
Definition rx8111.h:54
void set_alarm_explicitly_configured(bool configured)
Definition rx8111.h:53
void add_on_timer_callback(F &&callback)
Definition rx8111.h:110
void run_deferred_update_(bool status_only)
Definition rx8111.cpp:376
void add_on_alarm_callback(F &&callback)
Definition rx8111.h:100
bool set_alarm_interrupt_(bool enabled)
Definition rx8111.cpp:560
void set_alarm_hour(uint8_t value)
Definition rx8111.h:56
void set_battery_backup(bool enabled, bool charging)
Definition rx8111.h:78
void set_timer_enabled(bool enabled)
Definition rx8111.h:61
void set_fout_frequency(uint8_t frequency)
Definition rx8111.h:83
void set_event_timestamp_sensor(text_sensor::TextSensor *sensor, TimestampMode mode)
Definition rx8111.h:72
text_sensor::TextSensor * timestamp_sensor_
Definition rx8111.h:168
bool finish_time_write_(bool calendar_written)
Definition rx8111.cpp:539
void cancel_boot_retry_(bool alarm)
Definition rx8111.cpp:321
void boot_config_result_(BootFeature feature, bool success)
Definition rx8111.cpp:242
void clear_warning_(uint16_t bit)
Definition rx8111.cpp:391
void check_event_flags_(FlagSnapshot flags={})
Definition rx8111.cpp:325
static constexpr uint32_t BOOT_RETRY_DELAY_MS
Definition rx8111.h:117
void set_event_poll_interval(uint32_t interval)
Definition rx8111.h:63
void set_alarm_day(uint8_t value)
Definition rx8111.h:58
void set_warning_(uint16_t bit, const LogString *message)
Definition rx8111.cpp:386
void set_status_sensor(uint8_t index, binary_sensor::BinarySensor *sensor)
Definition rx8111.h:66
bool publish_timestamps_(uint8_t flags, bool buffered, bool startup=false)
Definition rx8111.cpp:880
LazyCallbackManager< void()> event_callbacks_
Definition rx8111.h:207
LazyCallbackManager< void()> timer_callbacks_
Definition rx8111.h:206
void add_on_event_callback(F &&callback)
Definition rx8111.h:96
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
const LogString * message
Definition component.cpp:35
uint8_t day
Definition date_entity.h:2
uint8_t second
uint8_t minute
uint8_t hour
uint16_t flags
unsigned count
Definition gif.cpp:51
@ TIMESTAMP_MODE_OVERWRITE
Definition rx8111.h:18
@ TIMESTAMP_MODE_LATEST
Definition rx8111.h:16
@ TIMESTAMP_MODE_STOP_WHEN_FULL
Definition rx8111.h:17
@ STATUS_SENSOR_EVENT_FLAG
Definition rx8111.h:27
@ STATUS_SENSOR_TIMER_FLAG
Definition rx8111.h:25
@ STATUS_SENSOR_VLF
Definition rx8111.h:23
@ STATUS_SENSOR_ALARM_FLAG
Definition rx8111.h:24
@ STATUS_SENSOR_BATTERY_LOW
Definition rx8111.h:28
@ STATUS_SENSOR_XST
Definition rx8111.h:26
@ STATUS_SENSOR_COUNT
Definition rx8111.h:30
@ STATUS_SENSOR_FIRST_MONITOR
Definition rx8111.h:31
@ STATUS_SENSOR_EVIN
Definition rx8111.h:29
uint32_t value
Definition hal.cpp:41
static void uint32_t
A more user-friendly version of struct tm from time.h.
Definition time.h:23