8static constexpr uint8_t STOVE_REPLY_SIZE = 2;
9static constexpr uint32_t STOVE_REPLY_TIMEOUT = 200;
10static constexpr uint8_t WRITE_BIT = 1 << 7;
16 " Memory Location: %02X\n"
17 " Memory Address: %02X",
23 LOG_UPDATE_INTERVAL(
this);
37 ESP_LOGCONFIG(TAG,
"MicroNova:");
41#ifdef MICRONOVA_LISTENER_COUNT
49 ESP_LOGD(TAG,
"Requesting update from all listeners");
51 this->
queue_read_request(listener->get_memory_location(), listener->get_memory_address());
60 if (this->
available() >= STOVE_REPLY_SIZE) {
61#ifdef MICRONOVA_LISTENER_COUNT
64 if (stove_reply_value == -1) {
65 ESP_LOGW(TAG,
"Write to [0x%02X:0x%02X] may have failed (checksum mismatch in reply)",
73 if (listener->get_memory_location() == loc && listener->get_memory_address() == addr) {
74 listener->process_value_from_stove(stove_reply_value);
84 ESP_LOGW(TAG,
"Timeout waiting for reply from [0x%02X:0x%02X], available: %d",
92#ifdef USE_MICRONOVA_WRITER
100#ifdef MICRONOVA_LISTENER_COUNT
109#ifdef MICRONOVA_LISTENER_COUNT
113 if (queued.memory_location == location && queued.memory_address ==
address) {
114 ESP_LOGV(TAG,
"Read [%02X,%02X] already queued, skipping", location,
address);
124 if (!this->read_queue_.push(cmd)) {
125 ESP_LOGW(TAG,
"Read queue full, dropping read [%02X,%02X]", location,
address);
128 ESP_LOGV(TAG,
"Queued read [%02X,%02X] (queue size: %u)", location,
address, this->read_queue_.size());
138 ESP_LOGW(TAG,
"Reading excess byte 0x%02X", trash_rx);
148 write_data[3] = write_data[0] + write_data[1] + write_data[2];
149 ESP_LOGV_HEX(TAG, write_data,
sizeof(write_data),
sizeof(write_data),
"Sending write request [%s]");
152 ESP_LOGV(TAG,
"Sending read request [%02X,%02X]", write_data[0], write_data[1]);
165 uint8_t reply_data[2] = {0, 0};
169 ESP_LOGV(TAG,
"Reply from stove [%02X,%02X]", reply_data[0], reply_data[1]);
173 ESP_LOGE(TAG,
"Checksum mismatch! From [0x%02X:0x%02X] received [0x%02X,0x%02X]. Expected 0x%02X, got 0x%02X",
175 reply_data[1],
checksum, reply_data[0]);
178 return ((
int) reply_data[1]);
181#ifdef USE_MICRONOVA_WRITER
191 if (queued.data != cmd.
data) {
192 ESP_LOGD(TAG,
"Updating queued write [%02X,%02X] data 0x%02X -> 0x%02X", location,
address, queued.data, data);
193 queued.data = cmd.
data;
195 ESP_LOGV(TAG,
"Write [%02X,%02X] with data 0x%02X already queued, skipping", location,
address, data);
201 if (!this->write_queue_.push(cmd)) {
202 ESP_LOGW(TAG,
"Write queue full, dropping command");
205 ESP_LOGD(TAG,
"Queued write [%02X,%02X] (queue size: %u)", location,
address, this->write_queue_.size());
206#ifdef MICRONOVA_LISTENER_COUNT
virtual void pin_mode(gpio::Flags flags)=0
virtual void digital_write(bool value)=0
uint8_t get_memory_address()
uint8_t get_memory_location()
void dump_config() override
MicroNovaCommand current_command_
StaticVector< MicroNovaListener *, MICRONOVA_LISTENER_COUNT > listeners_
bool reply_pending_
True if we are waiting for a reply from the stove.
void send_current_command_()
StaticRingBuffer< MicroNovaCommand, MICRONOVA_LISTENER_COUNT > read_queue_
void request_update_listeners_()
void queue_read_request(uint8_t location, uint8_t address)
Queue a read request to the stove (low priority - added at back) All listeners registered for this ad...
bool queue_write_command(uint8_t location, uint8_t address, uint8_t data)
Queue a write command to the stove (processed before reads)
uint32_t transmission_time_
Time when current command was sent.
StaticRingBuffer< MicroNovaCommand, WRITE_QUEUE_SIZE > write_queue_
void register_micronova_listener(MicroNovaListener *listener)
void request_value_from_stove_()
optional< std::array< uint8_t, N > > read_array()
bool read_byte(uint8_t *data)
void write_array(const uint8_t *data, size_t len)
ESPHOME_LOG_TAG(TAG, "micronova")
uint32_t IRAM_ATTR HOT millis()
Represents a command to be sent to the stove Write commands have the high bit (0x80) set in memory_lo...
uint8_t data
Only used for write commands.