ESPHome
2026.11.0-dev
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
void
set_presence_binary_sensor
(
binary_sensor::BinarySensor
*presence) { this->
presence_
= presence; }
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
}
47
uint32_t
get_last_inside_ms
()
const
{
return
this->
last_inside_ms_
; }
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
55
binary_sensor::BinarySensor
*
presence_
{
nullptr
};
56
Polygon
polygon_
;
57
ESPPreferenceObject
pref_
;
58
uint32_t
last_inside_ms_
{0};
59
};
60
61
}
// namespace esphome::ld2450
62
63
#endif
// LD2450_POLYGON_ZONE_COUNT
binary_sensor.h
esphome::ESPPreferenceObject
Definition
preference_backend.h:57
esphome::binary_sensor::BinarySensor
Base class for all binary_sensor-type classes.
Definition
binary_sensor.h:33
esphome::binary_sensor::BinarySensor::publish_state
void publish_state(bool new_state)
Publish a new state to the front-end.
Definition
binary_sensor.cpp:20
esphome::ld2450::PolygonZone
A zone with any polygon shape.
Definition
polygon_zone.h:22
esphome::ld2450::PolygonZone::dump_config
void dump_config()
Definition
polygon_zone.cpp:25
esphome::ld2450::PolygonZone::set_presence_binary_sensor
void set_presence_binary_sensor(binary_sensor::BinarySensor *presence)
Config validation guarantees every zone gets exactly one presence binary sensor.
Definition
polygon_zone.h:25
esphome::ld2450::PolygonZone::setup
void setup()
Load the saved polygon and publish it. Called from the hub's setup().
Definition
polygon_zone.cpp:10
esphome::ld2450::PolygonZone::pref_
ESPPreferenceObject pref_
Definition
polygon_zone.h:57
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:47
esphome::ld2450::PolygonZone::contains
bool contains(int16_t x, int16_t y) const
Definition
polygon_zone.h:48
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:58
esphome::ld2450::PolygonZone::polygon_
Polygon polygon_
Definition
polygon_zone.h:56
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:49
esphome::ld2450::PolygonZone::presence_
binary_sensor::BinarySensor * presence_
Definition
polygon_zone.h:55
esphome::ld2450::PolygonZone::publish_polygon_
void publish_polygon_()
Definition
polygon_zone.cpp:52
esphome::text::Text
Base-class for all text inputs.
Definition
text.h:21
preferences.h
defines.h
esphome::ld2450
Definition
factory_reset_button.cpp:3
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