ESPHome
2026.11.0b6
Loading...
Searching...
No Matches
esphome
components
uart
event
uart_event.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/core/defines.h
"
5
#include "
esphome/components/event/event.h
"
6
#include "
esphome/components/uart/uart.h
"
7
#include <type_traits>
8
#include <vector>
9
10
namespace
esphome::uart
{
11
13
struct
UARTEventMatcher
{
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.
19
static_assert
(std::is_same_v<
decltype
(
UARTEventMatcher::event_name
),
const
char
*>,
20
"UARTEventMatcher fields must stay word sized"
);
21
static_assert
(std::is_same_v<
decltype
(
UARTEventMatcher::data
),
const
uint8_t *>,
22
"UARTEventMatcher fields must stay word sized"
);
23
static_assert
(std::is_same_v<
decltype
(
UARTEventMatcher::data_len
),
size_t
>,
24
"UARTEventMatcher fields must stay word sized"
);
25
#ifdef USE_ESP8266
26
static_assert
(
sizeof
(
UARTEventMatcher
) == 3 *
sizeof
(
uint32_t
),
"UARTEventMatcher is read from flash with word loads"
);
27
#endif
28
29
class
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
esphome::Component
Definition
component.h:147
esphome::event::Event
Definition
event.h:23
esphome::uart::UARTDevice
Definition
uart.h:15
esphome::uart::UARTEvent
Definition
uart_event.h:29
esphome::uart::UARTEvent::matchers_
const UARTEventMatcher * matchers_
Definition
uart_event.h:44
esphome::uart::UARTEvent::loop
void loop() override
Definition
uart_event.cpp:13
esphome::uart::UARTEvent::dump_config
void dump_config() override
Definition
uart_event.cpp:11
esphome::uart::UARTEvent::buffer_
std::vector< uint8_t > buffer_
Definition
uart_event.h:45
esphome::uart::UARTEvent::matcher_count_
uint16_t matcher_count_
Definition
uart_event.h:46
esphome::uart::UARTEvent::setup
void setup() override
Definition
uart_event.cpp:9
esphome::uart::UARTEvent::max_matcher_len_
uint16_t max_matcher_len_
Definition
uart_event.h:47
esphome::uart::UARTEvent::read_data_
void read_data_()
Definition
uart_event.cpp:15
esphome::uart::UARTEvent::set_matchers
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
component.h
defines.h
event.h
count
unsigned count
Definition
gif.cpp:51
esphome::uart
Definition
serial_proxy.h:33
uint32_t
static void uint32_t
Definition
crash_handler.cpp:153
esphome::uart::UARTEventMatcher
An event type and the byte pattern that fires it; data may point to PROGMEM.
Definition
uart_event.h:13
esphome::uart::UARTEventMatcher::data_len
size_t data_len
Definition
uart_event.h:16
esphome::uart::UARTEventMatcher::event_name
const char * event_name
Definition
uart_event.h:14
esphome::uart::UARTEventMatcher::data
const uint8_t * data
Definition
uart_event.h:15
uart.h
Generated by
1.12.0