Files
esphome-wake-up-light-ii/components/uart/event/uart_event.cpp
T
mangavalkandClaude Opus 5.5 1457e25d98 Update the patched UART component to ESPHome 2026.11.0
ESPHome 2026.11's tuya component calls uart.new_uart_component(), which the
2026.10.2 copy didn't have, so the build failed. Copy the UART component from
2026.11.0, reapply the PA13/PA14 patch, regenerate the patch file and point
the refs at v1.0.6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 00:31:45 +01:00

46 lines
1.3 KiB
C++

#include "uart_event.h"
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
namespace esphome::uart {
ESPHOME_LOG_TAG(TAG, "uart.event");
void UARTEvent::setup() {}
void UARTEvent::dump_config() { LOG_EVENT("", "UART Event", this); }
void UARTEvent::loop() { this->read_data_(); }
void UARTEvent::read_data_() {
this->read_available([this](uint8_t data) {
this->buffer_.push_back(data);
bool match_found = false;
for (uint16_t i = 0; i < this->matcher_count_; i++) {
const UARTEventMatcher &matcher = this->matchers_[i];
if (this->buffer_.size() < matcher.data_len) {
continue;
}
const uint8_t *tail = this->buffer_.data() + this->buffer_.size() - matcher.data_len;
size_t pos = 0;
// The pattern is in flash; ESP8266 only allows word loads there, so read it with progmem_read_byte
while (pos < matcher.data_len && progmem_read_byte(matcher.data + pos) == tail[pos])
pos++;
if (pos == matcher.data_len) {
this->trigger(matcher.event_name);
this->buffer_.clear();
match_found = true;
break;
}
}
if (!match_found && this->max_matcher_len_ > 0 && this->buffer_.size() > this->max_matcher_len_) {
this->buffer_.erase(this->buffer_.begin());
}
});
}
} // namespace esphome::uart