ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
uart_binary_sensor.h
Go to the documentation of this file.
1#pragma once
2
7
8namespace esphome::uart {
9
10// One per bus: reads the bytes once and presses each sensor whose pattern ends the stream
12 public:
13 void setup() override { this->buffer_.init(this->max_len_); }
14 void loop() override;
15 void dump_config() override;
16
17 // The pattern lives in flash; called once per sensor by the generated code
18 void add_event_matcher(binary_sensor::BinarySensor *sensor, const uint8_t *data, uint8_t data_len) {
19 this->matchers_.push_back({sensor, data, data_len});
20 this->max_len_ = std::max(this->max_len_, data_len);
21 }
22
23 protected:
24 struct EventMatcher {
26 const uint8_t *data;
27 uint8_t data_len;
28 };
29
30 bool matches_(const EventMatcher &matcher) const;
31
34 uint8_t max_len_{0};
35};
36
37} // namespace esphome::uart
Fixed-capacity circular buffer - allocates once at runtime, never reallocates.
Definition helpers.h:469
void init(index_type capacity)
Allocate capacity - can only be called once.
Definition helpers.h:519
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:286
Base class for all binary_sensor-type classes.
bool matches_(const EventMatcher &matcher) const
StaticVector< EventMatcher, UART_BINARY_SENSOR_COUNT > matchers_
FixedRingBuffer< uint8_t, 255 > buffer_
void add_event_matcher(binary_sensor::BinarySensor *sensor, const uint8_t *data, uint8_t data_len)