6static const char *
const TAG =
"micronova";
7static constexpr uint8_t STOVE_REPLY_SIZE = 2;
8static constexpr uint32_t STOVE_REPLY_TIMEOUT = 200;
9static constexpr uint8_t WRITE_BIT = 1 << 7;
15 " Memory Location: %02X\n"
16 " Memory Address: %02X",
22 LOG_UPDATE_INTERVAL(
this);
36 ESP_LOGCONFIG(TAG,
"MicroNova:");
40#ifdef MICRONOVA_LISTENER_COUNT
48 ESP_LOGD(TAG,
"Requesting update from all listeners");
50 this->
queue_read_request(listener->get_memory_location(), listener->get_memory_address());
59 if (this->
available() >= STOVE_REPLY_SIZE) {
60#ifdef MICRONOVA_LISTENER_COUNT
63 if (stove_reply_value == -1) {
64 ESP_LOGW(TAG,
"Write to [0x%02X:0x%02X] may have failed (checksum mismatch in reply)",
72 if (listener->get_memory_location() == loc && listener->get_memory_address() == addr) {
73 listener->process_value_from_stove(stove_reply_value);
83 ESP_LOGW(TAG,
"Timeout waiting for reply from [0x%02X:0x%02X], available: %d",
91#ifdef USE_MICRONOVA_WRITER
99#ifdef MICRONOVA_LISTENER_COUNT
108#ifdef MICRONOVA_LISTENER_COUNT
112 if (queued.memory_location == location && queued.memory_address ==
address) {
113 ESP_LOGV(TAG,
"Read [%02X,%02X] already queued, skipping", location,
address);
123 if (!this->read_queue_.push(cmd)) {
124 ESP_LOGW(TAG,
"Read queue full, dropping read [%02X,%02X]", location,
address);
127 ESP_LOGV(TAG,
"Queued read [%02X,%02X] (queue size: %u)", location,
address, this->read_queue_.size());
137 ESP_LOGW(TAG,
"Reading excess byte 0x%02X", trash_rx);
147 write_data[3] = write_data[0] + write_data[1] + write_data[2];
148 ESP_LOGV(TAG,
"Sending write request [%02X,%02X,%02X,%02X]", write_data[0], write_data[1], write_data[2],
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)
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.