Added new sensors for distance and SNR

This commit is contained in:
Robin Thoni 2024-06-24 08:40:30 +00:00 committed by GitHub
parent faa52b9cc0
commit 45a6ca7451
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,12 +7,17 @@
#ifdef USE_BINARY_SENSOR
#include "esphome/components/binary_sensor/binary_sensor.h"
#endif
#ifdef USE_SENSOR
#include "esphome/components/sensor/sensor.h"
#endif
#ifdef USE_SWITCH
#include "esphome/components/switch/switch.h"
#endif
#include "commands.h"
#define TARGET_COUNT 9
namespace esphome {
namespace dfrobot_sen0395 {
@ -94,12 +99,29 @@ class DfrobotSen0395Component : public uart::UARTDevice, public Component {
}
#endif
#ifdef USE_SENSOR
void set_detected_target_distance_sensor(int target, sensor::Sensor *detected_target_distance_sensor) {
if (is_valid_target_(target)) {
detected_targets_distance_sensors_[target - 1] = detected_target_distance_sensor;
}
}
void set_detected_target_snr_sensor(int target, sensor::Sensor *detected_target_snr_sensor) {
if (is_valid_target_(target)) {
detected_targets_snr_sensors_[target - 1] = detected_target_snr_sensor;
}
}
#endif
int8_t enqueue(std::unique_ptr<Command> cmd);
protected:
#ifdef USE_BINARY_SENSOR
binary_sensor::BinarySensor *detected_binary_sensor_{nullptr};
#endif
#ifdef USE_SENSOR
sensor::Sensor *detected_targets_distance_sensors_[TARGET_COUNT]{nullptr};
sensor::Sensor *detected_targets_snr_sensors_[TARGET_COUNT]{nullptr};
#endif
bool detected_{false};
bool active_{false};
@ -117,6 +139,8 @@ class DfrobotSen0395Component : public uart::UARTDevice, public Component {
void set_detected_(bool detected);
bool is_valid_target_(int target) { return target >= 1 && target <= TARGET_COUNT; }
friend class Command;
friend class ReadStateCommand;
};