mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
Remove custom api code
This commit is contained in:
parent
3b19b581e8
commit
76c9f5530e
2 changed files with 12 additions and 42 deletions
|
@ -28,27 +28,6 @@ void LD2450Component::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Mac Address: %s", const_cast<char *>(this->mac_.c_str()));
|
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, "Firmware Version: %s", const_cast<char *>(this->version_.c_str()));
|
||||||
ESP_LOGCONFIG(TAG, "HLK-LD2450 setup complete");
|
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() {
|
void LD2450Component::dump_config() {
|
||||||
|
@ -154,7 +133,7 @@ uint8_t LD2450Component::count_targets_in_zone_(const Zone &zone, bool is_moving
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service reset_radar_zone
|
// Service reset_radar_zone
|
||||||
void LD2450Component::on_reset_radar_zone_() {
|
void LD2450Component::reset_radar_zone() {
|
||||||
this->zone_type_ = 0;
|
this->zone_type_ = 0;
|
||||||
for (auto &i : zone_config_) {
|
for (auto &i : zone_config_) {
|
||||||
i.x1 = 0;
|
i.x1 = 0;
|
||||||
|
@ -165,11 +144,10 @@ void LD2450Component::on_reset_radar_zone_() {
|
||||||
this->send_set_zone_command_();
|
this->send_set_zone_command_();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service set_radar_zone
|
void LD2450Component::set_radar_zone(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2,
|
||||||
void LD2450Component::on_set_radar_zone_(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2,
|
int32_t zone1_y2, int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2,
|
||||||
int32_t zone1_y2, int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2,
|
int32_t zone2_y2, int32_t zone3_x1, int32_t zone3_y1, int32_t zone3_x2,
|
||||||
int32_t zone2_y2, int32_t zone3_x1, int32_t zone3_y1, int32_t zone3_x2,
|
int32_t zone3_y2) {
|
||||||
int32_t zone3_y2) {
|
|
||||||
this->zone_type_ = zone_type;
|
this->zone_type_ = zone_type;
|
||||||
int zone_parameters[12] = {zone1_x1, zone1_y1, zone1_x2, zone1_y2, zone2_x1, zone2_y1,
|
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};
|
zone2_x2, zone2_y2, zone3_x1, zone3_y1, zone3_x2, zone3_y2};
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include "esphome/components/uart/uart.h"
|
||||||
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/component.h"
|
|
||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
#include "esphome/components/uart/uart.h"
|
|
||||||
#ifdef USE_SENSOR
|
#ifdef USE_SENSOR
|
||||||
#include "esphome/components/sensor/sensor.h"
|
#include "esphome/components/sensor/sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,9 +23,6 @@
|
||||||
#ifdef USE_SELECT
|
#ifdef USE_SELECT
|
||||||
#include "esphome/components/select/select.h"
|
#include "esphome/components/select/select.h"
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_API
|
|
||||||
#include "esphome/components/api/custom_api_device.h"
|
|
||||||
#endif
|
|
||||||
#ifdef USE_TEXT_SENSOR
|
#ifdef USE_TEXT_SENSOR
|
||||||
#include "esphome/components/text_sensor/text_sensor.h"
|
#include "esphome/components/text_sensor/text_sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -117,12 +114,7 @@ enum PeriodicDataStructure : uint8_t {
|
||||||
enum PeriodicDataValue : uint8_t { HEAD = 0XAA, END = 0x55, CHECK = 0x00 };
|
enum PeriodicDataValue : uint8_t { HEAD = 0XAA, END = 0x55, CHECK = 0x00 };
|
||||||
|
|
||||||
enum AckDataStructure : uint8_t { COMMAND = 6, COMMAND_STATUS = 7 };
|
enum AckDataStructure : uint8_t { COMMAND = 6, COMMAND_STATUS = 7 };
|
||||||
// Use CustomAPIDevice if API is defined in YAML - used for service calls to set/reset zone
|
|
||||||
#ifdef USE_API
|
|
||||||
class LD2450Component : public Component, public uart::UARTDevice, public esphome::api::CustomAPIDevice {
|
|
||||||
#else
|
|
||||||
class LD2450Component : public Component, public uart::UARTDevice {
|
class LD2450Component : public Component, public uart::UARTDevice {
|
||||||
#endif
|
|
||||||
#ifdef USE_SENSOR
|
#ifdef USE_SENSOR
|
||||||
SUB_SENSOR(target_count)
|
SUB_SENSOR(target_count)
|
||||||
SUB_SENSOR(still_target_count)
|
SUB_SENSOR(still_target_count)
|
||||||
|
@ -191,6 +183,10 @@ class LD2450Component : public Component, public uart::UARTDevice {
|
||||||
void set_zone_still_target_count_sensor(int zone, sensor::Sensor *s);
|
void set_zone_still_target_count_sensor(int zone, sensor::Sensor *s);
|
||||||
void set_zone_moving_target_count_sensor(int zone, sensor::Sensor *s);
|
void set_zone_moving_target_count_sensor(int zone, sensor::Sensor *s);
|
||||||
#endif
|
#endif
|
||||||
|
void reset_radar_zone();
|
||||||
|
void set_radar_zone(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2, int32_t zone1_y2,
|
||||||
|
int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2, int32_t zone2_y2, int32_t zone3_x1,
|
||||||
|
int32_t zone3_y1, int32_t zone3_x2, int32_t zone3_y2);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ESPPreferenceObject pref_;
|
ESPPreferenceObject pref_;
|
||||||
|
@ -207,14 +203,10 @@ class LD2450Component : public Component, public uart::UARTDevice {
|
||||||
void restart_();
|
void restart_();
|
||||||
void send_set_zone_command_();
|
void send_set_zone_command_();
|
||||||
void convert_int_values_to_hex_(const int *values, uint8_t *bytes);
|
void convert_int_values_to_hex_(const int *values, uint8_t *bytes);
|
||||||
void on_reset_radar_zone_();
|
|
||||||
void save_to_flash_(float value);
|
void save_to_flash_(float value);
|
||||||
float restore_from_flash_();
|
float restore_from_flash_();
|
||||||
Target target_info_[MAX_TARGETS];
|
Target target_info_[MAX_TARGETS];
|
||||||
Zone zone_config_[MAX_ZONES];
|
Zone zone_config_[MAX_ZONES];
|
||||||
void on_set_radar_zone_(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2, int32_t zone1_y2,
|
|
||||||
int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2, int32_t zone2_y2, int32_t zone3_x1,
|
|
||||||
int32_t zone3_y1, int32_t zone3_x2, int32_t zone3_y2);
|
|
||||||
int16_t decode_coordinate_(uint8_t low_byte, uint8_t high_byte) {
|
int16_t decode_coordinate_(uint8_t low_byte, uint8_t high_byte) {
|
||||||
int16_t coordinate = (high_byte & 0x7F) << 8 | low_byte;
|
int16_t coordinate = (high_byte & 0x7F) << 8 | low_byte;
|
||||||
if ((high_byte & 0x80) == 0)
|
if ((high_byte & 0x80) == 0)
|
||||||
|
|
Loading…
Reference in a new issue