mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 12:46:22 +01:00
Add ld2450 zone set reset services
This commit is contained in:
parent
ec4531a790
commit
89f9d2bd1b
@ -26,6 +26,27 @@ void LD2450Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Mac Address : %s", const_cast<char *>(this->mac_.c_str()));
|
||||
ESP_LOGCONFIG(TAG, "Firmware Version : %s", const_cast<char *>(this->version_.c_str()));
|
||||
ESP_LOGCONFIG(TAG, "HLK-LD2450 setup complete");
|
||||
#ifdef USE_API
|
||||
ESP_LOGCONFIG(TAG, "Registering services");
|
||||
CustomAPIDevice::register_service(&::esphome::ld2450::LD2450Component::on_set_radar_zone_, "set_radar_zone",
|
||||
{
|
||||
"zone_type",
|
||||
"zone1_x1",
|
||||
"zone1_y1",
|
||||
"zone1_x2",
|
||||
"zone1_y2",
|
||||
"zone2_x1",
|
||||
"zone2_y1",
|
||||
"zone2_x2",
|
||||
"zone2_y2",
|
||||
"zone3_x1",
|
||||
"zone3_y1",
|
||||
"zone3_x2",
|
||||
"zone3_y2",
|
||||
});
|
||||
CustomAPIDevice::register_service(&::esphome::ld2450::LD2450Component::on_reset_radar_zone_, "reset_radar_zone");
|
||||
ESP_LOGCONFIG(TAG, "Services registration complete");
|
||||
#endif
|
||||
}
|
||||
|
||||
void LD2450Component::dump_config() {
|
||||
@ -109,6 +130,34 @@ void LD2450Component::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
// Service reset_radar_zone
|
||||
void LD2450Component::on_reset_radar_zone_() {
|
||||
this->zone_type_ = 0;
|
||||
for (auto &i : zone_config_) {
|
||||
i.x1 = 0;
|
||||
i.y1 = 0;
|
||||
i.x2 = 0;
|
||||
i.y2 = 0;
|
||||
}
|
||||
this->send_set_zone_command_();
|
||||
}
|
||||
|
||||
// Service set_radar_zone
|
||||
void LD2450Component::on_set_radar_zone_(int zone_type, int zone1_x1, int zone1_y1, int zone1_x2, int zone1_y2,
|
||||
int zone2_x1, int zone2_y1, int zone2_x2, int zone2_y2, int zone3_x1,
|
||||
int zone3_y1, int zone3_x2, int zone3_y2) {
|
||||
this->zone_type_ = zone_type;
|
||||
int zone_parameters[12] = {zone1_x1, zone1_y1, zone1_x2, zone1_y2, zone2_x1, zone2_y1,
|
||||
zone2_x2, zone2_y2, zone3_x1, zone3_y1, zone3_x2, zone3_y2};
|
||||
for (int i = 0; i < MAX_ZONES; i++) {
|
||||
zone_config_[i].x1 = zone_parameters[i * 4];
|
||||
zone_config_[i].y1 = zone_parameters[i * 4 + 1];
|
||||
zone_config_[i].x2 = zone_parameters[i * 4 + 2];
|
||||
zone_config_[i].y2 = zone_parameters[i * 4 + 3];
|
||||
}
|
||||
this->send_set_zone_command_();
|
||||
}
|
||||
|
||||
// Set Zone on LD2450 Sensor
|
||||
void LD2450Component::send_set_zone_command_() {
|
||||
uint8_t cmd_value[26] = {};
|
||||
|
@ -23,6 +23,9 @@
|
||||
#ifdef USE_SELECT
|
||||
#include "esphome/components/select/select.h"
|
||||
#endif
|
||||
#ifdef USE_API
|
||||
#include "esphome/components/api/custom_api_device.h"
|
||||
#endif
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#endif
|
||||
@ -110,7 +113,11 @@ enum PeriodicDataValue : uint8_t { HEAD = 0XAA, END = 0x55, CHECK = 0x00 };
|
||||
|
||||
enum AckDataStructure : uint8_t { COMMAND = 6, COMMAND_STATUS = 7 };
|
||||
|
||||
#ifdef USE_API
|
||||
class LD2450Component : public Component, public uart::UARTDevice, public esphome::api::CustomAPIDevice {
|
||||
#else
|
||||
class LD2450Component : public Component, public uart::UARTDevice {
|
||||
#endif
|
||||
#ifdef USE_SENSOR
|
||||
SUB_SENSOR(target_count)
|
||||
SUB_SENSOR(still_target_count)
|
||||
|
@ -43,6 +43,8 @@ uart:
|
||||
parity: NONE
|
||||
stop_bits: 1
|
||||
|
||||
api:
|
||||
|
||||
ld2450:
|
||||
id: ld2450_radar
|
||||
uart_id: uart_ld2450
|
||||
|
Loading…
Reference in New Issue
Block a user