ESPHome
2026.11.0b6
Loading...
Searching...
No Matches
esphome
components
ld2450
polygon_zone.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/defines.h
"
4
#ifdef LD2450_POLYGON_ZONE_COUNT
5
6
#include "
esphome/components/binary_sensor/binary_sensor.h
"
7
#include "
esphome/components/text/text.h
"
8
#include "
esphome/core/preferences.h
"
9
#include "
polygon.h
"
10
11
namespace
esphome::ld2450
{
12
22
class
PolygonZone
:
public
text::Text
{
23
public
:
25
SUB_BINARY_SENSOR
(presence)
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
}
47
void
invalidate_presence
() {
48
this->presence_binary_sensor_->invalidate_state();
49
this->
last_inside_ms_
= 0;
50
}
52
uint32_t
get_last_inside_ms
()
const
{
return
this->
last_inside_ms_
; }
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
60
Polygon
polygon_
;
61
ESPPreferenceObject
pref_
;
62
uint32_t
last_inside_ms_
{0};
63
};
64
65
}
// namespace esphome::ld2450
66
67
#endif
// LD2450_POLYGON_ZONE_COUNT
binary_sensor.h
esphome::ESPPreferenceObject
Definition
preference_backend.h:57
esphome::EntityBase::setup
friend void::setup()
esphome::ld2450::PolygonZone
A zone with any polygon shape.
Definition
polygon_zone.h:22
esphome::ld2450::PolygonZone::SUB_BINARY_SENSOR
SUB_BINARY_SENSOR(presence) void setup()
Config validation guarantees every zone gets exactly one presence binary sensor.
esphome::ld2450::PolygonZone::dump_config
void dump_config()
Definition
polygon_zone.cpp:25
esphome::ld2450::PolygonZone::pref_
ESPPreferenceObject pref_
Definition
polygon_zone.h:61
esphome::ld2450::PolygonZone::get_last_inside_ms
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.
Definition
polygon_zone.h:52
esphome::ld2450::PolygonZone::invalidate_presence
void invalidate_presence()
Link lost: presence becomes unknown and the hold is cleared.
Definition
polygon_zone.h:47
esphome::ld2450::PolygonZone::contains
bool contains(int16_t x, int16_t y) const
Definition
polygon_zone.h:53
esphome::ld2450::PolygonZone::update
void update(bool target_inside, uint32_t now, bool timed_out)
Publish presence for one radar frame.
Definition
polygon_zone.h:36
esphome::ld2450::PolygonZone::last_inside_ms_
uint32_t last_inside_ms_
Definition
polygon_zone.h:62
esphome::ld2450::PolygonZone::polygon_
Polygon polygon_
Definition
polygon_zone.h:60
esphome::ld2450::PolygonZone::control
void control(const std::string &value) override
Definition
polygon_zone.cpp:33
esphome::ld2450::PolygonZone::has_polygon
bool has_polygon() const
Definition
polygon_zone.h:54
esphome::ld2450::PolygonZone::publish_polygon_
void publish_polygon_()
Definition
polygon_zone.cpp:54
esphome::text::Text
Base-class for all text inputs.
Definition
text.h:20
preferences.h
defines.h
esphome::ld2450
Definition
ld2450.cpp:19
esphome::value
uint32_t value
Definition
hal.cpp:41
polygon.h
uint32_t
static void uint32_t
Definition
crash_handler.cpp:153
esphome::ld2450::Polygon
A polygon in radar coordinates. Trivially copyable so it can be saved to preferences as-is.
Definition
polygon.h:26
esphome::ld2450::Polygon::contains
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
esphome::ld2450::Polygon::empty
bool empty() const
True when the polygon has no points, which disables the zone.
Definition
polygon.h:31
text.h
x
uint16_t x
Definition
tt21100.cpp:5
y
uint16_t y
Definition
tt21100.cpp:6
Generated by
1.12.0