mirror of
https://github.com/esphome/esphome.git
synced 2026-09-04 03:56:04 +00:00
[ld2450] Single-pass zone target counting (#14387)
This commit is contained in:
@@ -283,16 +283,19 @@ void LD2450Component::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
// Count targets in zone
|
||||
uint8_t LD2450Component::count_targets_in_zone_(const Zone &zone, bool is_moving) {
|
||||
uint8_t count = 0;
|
||||
for (auto &index : this->target_info_) {
|
||||
if (index.x > zone.x1 && index.x < zone.x2 && index.y > zone.y1 && index.y < zone.y2 &&
|
||||
index.is_moving == is_moving) {
|
||||
count++;
|
||||
// Count targets in zone (single pass for both still and moving)
|
||||
void LD2450Component::count_targets_in_zone_(const Zone &zone, uint8_t &still, uint8_t &moving) {
|
||||
still = 0;
|
||||
moving = 0;
|
||||
for (auto &target : this->target_info_) {
|
||||
if (target.x > zone.x1 && target.x < zone.x2 && target.y > zone.y1 && target.y < zone.y2) {
|
||||
if (target.is_moving) {
|
||||
moving++;
|
||||
} else {
|
||||
still++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Service reset_radar_zone
|
||||
@@ -540,8 +543,7 @@ void LD2450Component::handle_periodic_data_() {
|
||||
uint8_t zone_moving_targets = 0;
|
||||
uint8_t zone_all_targets = 0;
|
||||
for (index = 0; index < MAX_ZONES; index++) {
|
||||
zone_still_targets = this->count_targets_in_zone_(this->zone_config_[index], false);
|
||||
zone_moving_targets = this->count_targets_in_zone_(this->zone_config_[index], true);
|
||||
this->count_targets_in_zone_(this->zone_config_[index], zone_still_targets, zone_moving_targets);
|
||||
zone_all_targets = zone_still_targets + zone_moving_targets;
|
||||
|
||||
// Publish Still Target Count in Zones
|
||||
|
||||
@@ -163,7 +163,7 @@ class LD2450Component : public Component, public uart::UARTDevice {
|
||||
void save_to_flash_(float value);
|
||||
float restore_from_flash_();
|
||||
bool get_timeout_status_(uint32_t check_millis);
|
||||
uint8_t count_targets_in_zone_(const Zone &zone, bool is_moving);
|
||||
void count_targets_in_zone_(const Zone &zone, uint8_t &still, uint8_t &moving);
|
||||
|
||||
uint32_t presence_millis_ = 0;
|
||||
uint32_t still_presence_millis_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user