From a2f02aba57205ad1a08e2c2818b82c8fb65f325f Mon Sep 17 00:00:00 2001 From: Robin Thoni Date: Mon, 24 Jun 2024 08:42:03 +0000 Subject: [PATCH] set_detected_target_* helpers --- .../dfrobot_sen0395/dfrobot_sen0395.cpp | 20 +++++++++++++++++++ .../dfrobot_sen0395/dfrobot_sen0395.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp b/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp index 7cb96a859e..96cd924d52 100644 --- a/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp +++ b/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp @@ -101,6 +101,26 @@ void DfrobotSen0395Component::set_detected_(bool detected) { #endif } +void DfrobotSen0395Component::set_detected_target_distance_(int target, float value) { +#ifdef USE_SENSOR + if (is_valid_target_(target)) { + if (detected_targets_distance_sensors_[target - 1]) { + detected_targets_distance_sensors_[target - 1]->publish_state(value); + } + } +#endif +} + +void DfrobotSen0395Component::set_detected_target_snr_(int target, float value) { +#ifdef USE_SENSOR + if (is_valid_target_(target)) { + if (detected_targets_snr_sensors_[target - 1]) { + detected_targets_snr_sensors_[target - 1]->publish_state(value); + } + } +#endif +} + int8_t CircularCommandQueue::enqueue(std::unique_ptr cmd) { if (this->is_full()) { ESP_LOGE(TAG, "Command queue is full"); diff --git a/esphome/components/dfrobot_sen0395/dfrobot_sen0395.h b/esphome/components/dfrobot_sen0395/dfrobot_sen0395.h index 893519a414..4351ff7abd 100644 --- a/esphome/components/dfrobot_sen0395/dfrobot_sen0395.h +++ b/esphome/components/dfrobot_sen0395/dfrobot_sen0395.h @@ -139,6 +139,9 @@ class DfrobotSen0395Component : public uart::UARTDevice, public Component { void set_detected_(bool detected); + void set_detected_target_distance_(int target, float value); + void set_detected_target_snr_(int target, float value); + bool is_valid_target_(int target) { return target >= 1 && target <= TARGET_COUNT; } friend class Command;