ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
uart_event.h
Go to the documentation of this file.
1#pragma once
2
7#include <type_traits>
8#include <vector>
9
10namespace esphome::uart {
11
14 const char *event_name;
15 const uint8_t *data;
16 size_t data_len;
17};
18// Codegen keeps the matchers in a flash table read with plain loads, which ESP8266 only allows for whole words.
19static_assert(std::is_same_v<decltype(UARTEventMatcher::event_name), const char *>,
20 "UARTEventMatcher fields must stay word sized");
21static_assert(std::is_same_v<decltype(UARTEventMatcher::data), const uint8_t *>,
22 "UARTEventMatcher fields must stay word sized");
23static_assert(std::is_same_v<decltype(UARTEventMatcher::data_len), size_t>,
24 "UARTEventMatcher fields must stay word sized");
25#ifdef USE_ESP8266
26static_assert(sizeof(UARTEventMatcher) == 3 * sizeof(uint32_t), "UARTEventMatcher is read from flash with word loads");
27#endif
28
29class UARTEvent final : public event::Event, public UARTDevice, public Component {
30 public:
31 void setup() override;
32 void loop() override;
33 void dump_config() override;
34
36 void set_matchers(const UARTEventMatcher *matchers, uint16_t count, uint16_t max_len) {
37 this->matchers_ = matchers;
38 this->matcher_count_ = count;
39 this->max_matcher_len_ = max_len;
40 }
41
42 protected:
43 void read_data_();
44 const UARTEventMatcher *matchers_{nullptr};
45 std::vector<uint8_t> buffer_;
46 uint16_t matcher_count_{0};
47 uint16_t max_matcher_len_{0};
48};
49
50} // namespace esphome::uart
const UARTEventMatcher * matchers_
Definition uart_event.h:44
void dump_config() override
std::vector< uint8_t > buffer_
Definition uart_event.h:45
void setup() override
Definition uart_event.cpp:9
void set_matchers(const UARTEventMatcher *matchers, uint16_t count, uint16_t max_len)
matchers is a codegen PROGMEM table that must outlive the component.
Definition uart_event.h:36
unsigned count
Definition gif.cpp:51
static void uint32_t
An event type and the byte pattern that fires it; data may point to PROGMEM.
Definition uart_event.h:13