ESPHome 2026.11.0-dev
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
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_->publish_state(true);
42 } else if (timed_out) {
43 this->presence_->publish_state(false);
44 }
45 }
48 bool contains(int16_t x, int16_t y) const { return this->polygon_.contains(x, y); }
49 bool has_polygon() const { return !this->polygon_.empty(); }
50
51 protected:
52 void control(const std::string &value) override;
53 void publish_polygon_();
54
59};
60
61} // namespace esphome::ld2450
62
63#endif // LD2450_POLYGON_ZONE_COUNT
Base class for all binary_sensor-type classes.
void publish_state(bool new_state)
Publish a new state to the front-end.
A zone with any polygon shape.
void set_presence_binary_sensor(binary_sensor::BinarySensor *presence)
Config validation guarantees every zone gets exactly one presence binary sensor.
void setup()
Load the saved polygon and publish it. Called from the hub's setup().
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.
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
binary_sensor::BinarySensor * presence_
Base-class for all text inputs.
Definition text.h:21
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