mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 15:04:54 +01:00
Added new sensors for distance and SNR
This commit is contained in:
parent
faa52b9cc0
commit
45a6ca7451
1 changed files with 24 additions and 0 deletions
|
@ -7,12 +7,17 @@
|
||||||
#ifdef USE_BINARY_SENSOR
|
#ifdef USE_BINARY_SENSOR
|
||||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_SENSOR
|
||||||
|
#include "esphome/components/sensor/sensor.h"
|
||||||
|
#endif
|
||||||
#ifdef USE_SWITCH
|
#ifdef USE_SWITCH
|
||||||
#include "esphome/components/switch/switch.h"
|
#include "esphome/components/switch/switch.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
|
||||||
|
#define TARGET_COUNT 9
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace dfrobot_sen0395 {
|
namespace dfrobot_sen0395 {
|
||||||
|
|
||||||
|
@ -94,12 +99,29 @@ class DfrobotSen0395Component : public uart::UARTDevice, public Component {
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
int8_t enqueue(std::unique_ptr<Command> cmd);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifdef USE_BINARY_SENSOR
|
#ifdef USE_BINARY_SENSOR
|
||||||
binary_sensor::BinarySensor *detected_binary_sensor_{nullptr};
|
binary_sensor::BinarySensor *detected_binary_sensor_{nullptr};
|
||||||
#endif
|
#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 detected_{false};
|
||||||
bool active_{false};
|
bool active_{false};
|
||||||
|
@ -117,6 +139,8 @@ class DfrobotSen0395Component : public uart::UARTDevice, public Component {
|
||||||
|
|
||||||
void set_detected_(bool detected);
|
void set_detected_(bool detected);
|
||||||
|
|
||||||
|
bool is_valid_target_(int target) { return target >= 1 && target <= TARGET_COUNT; }
|
||||||
|
|
||||||
friend class Command;
|
friend class Command;
|
||||||
friend class ReadStateCommand;
|
friend class ReadStateCommand;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue