Remove custom api code

This commit is contained in:
Jesse Hills 2024-05-02 16:04:36 +12:00
parent 3b19b581e8
commit 76c9f5530e
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
2 changed files with 12 additions and 42 deletions

View File

@ -28,27 +28,6 @@ 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() {
@ -154,7 +133,7 @@ uint8_t LD2450Component::count_targets_in_zone_(const Zone &zone, bool is_moving
}
// Service reset_radar_zone
void LD2450Component::on_reset_radar_zone_() {
void LD2450Component::reset_radar_zone() {
this->zone_type_ = 0;
for (auto &i : zone_config_) {
i.x1 = 0;
@ -165,8 +144,7 @@ void LD2450Component::on_reset_radar_zone_() {
this->send_set_zone_command_();
}
// Service set_radar_zone
void LD2450Component::on_set_radar_zone_(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2,
void LD2450Component::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) {

View File

@ -1,13 +1,13 @@
#pragma once
#include <iomanip>
#include <map>
#include <sstream>
#include <iomanip>
#include "esphome/components/uart/uart.h"
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include "esphome/core/component.h"
#include "esphome/core/preferences.h"
#include "esphome/components/uart/uart.h"
#ifdef USE_SENSOR
#include "esphome/components/sensor/sensor.h"
#endif
@ -23,9 +23,6 @@
#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
@ -117,12 +114,7 @@ enum PeriodicDataStructure : uint8_t {
enum PeriodicDataValue : uint8_t { HEAD = 0XAA, END = 0x55, CHECK = 0x00 };
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 {
#endif
#ifdef USE_SENSOR
SUB_SENSOR(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_moving_target_count_sensor(int zone, sensor::Sensor *s);
#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:
ESPPreferenceObject pref_;
@ -207,14 +203,10 @@ class LD2450Component : public Component, public uart::UARTDevice {
void restart_();
void send_set_zone_command_();
void convert_int_values_to_hex_(const int *values, uint8_t *bytes);
void on_reset_radar_zone_();
void save_to_flash_(float value);
float restore_from_flash_();
Target target_info_[MAX_TARGETS];
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 coordinate = (high_byte & 0x7F) << 8 | low_byte;
if ((high_byte & 0x80) == 0)