ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
polygon_zone.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef LD2450_POLYGON_ZONE_COUNT
5
9#include "polygon.h"
10
11namespace esphome::ld2450 {
12
22class PolygonZone : public text::Text {
23 public:
26
27
28 void setup();
29 void dump_config();
36 void update(bool target_inside, uint32_t now, bool timed_out) {
37 if (this->polygon_.empty())
38 return;
39 if (target_inside) {
40 this->last_inside_ms_ = now;
41 this->presence_binary_sensor_->publish_state(true);
42 } else if (timed_out) {
43 this->presence_binary_sensor_->publish_state(false);
44 }
45 }
48 this->presence_binary_sensor_->invalidate_state();
49 this->last_inside_ms_ = 0;
50 }
53 bool contains(int16_t x, int16_t y) const { return this->polygon_.contains(x, y); }
54 bool has_polygon() const { return !this->polygon_.empty(); }
55
56 protected:
57 void control(const std::string &value) override;
58 void publish_polygon_();
59
63};
64
65} // namespace esphome::ld2450
66
67#endif // LD2450_POLYGON_ZONE_COUNT
friend void::setup()
A zone with any polygon shape.
SUB_BINARY_SENSOR(presence) void setup()
Config validation guarantees every zone gets exactly one presence binary sensor.
ESPPreferenceObject pref_
uint32_t get_last_inside_ms() const
When a target was last inside the zone, in ms; 0 if never since the polygon was set.
void invalidate_presence()
Link lost: presence becomes unknown and the hold is cleared.
bool contains(int16_t x, int16_t y) const
void update(bool target_inside, uint32_t now, bool timed_out)
Publish presence for one radar frame.
void control(const std::string &value) override
Base-class for all text inputs.
Definition text.h:20
uint32_t value
Definition hal.cpp:41
static void uint32_t
A polygon in radar coordinates. Trivially copyable so it can be saved to preferences as-is.
Definition polygon.h:26
bool contains(int16_t x, int16_t y) const
Return whether the point is inside the polygon (even-odd rule). Always false for an empty polygon.
Definition polygon.cpp:73
bool empty() const
True when the polygon has no points, which disables the zone.
Definition polygon.h:31
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6