ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
ld2410.h
Go to the documentation of this file.
1#pragma once
4#ifdef USE_BINARY_SENSOR
6#endif
7#ifdef USE_SENSOR
9#endif
10#ifdef USE_NUMBER
12#endif
13#ifdef USE_SWITCH
15#endif
16#ifdef USE_BUTTON
18#endif
19#ifdef USE_SELECT
21#endif
22#ifdef USE_TEXT_SENSOR
24#endif
29
30#include <array>
31
32namespace esphome::ld2410 {
33
34using namespace ld24xx;
35
36static constexpr uint8_t MAX_LINE_LENGTH = 46; // Max characters for serial buffer
37static constexpr uint8_t TOTAL_GATES = 9; // Total number of gates supported by the LD2410
38
40#ifdef USE_BINARY_SENSOR
41 SUB_BINARY_SENSOR(out_pin_presence_status)
42 SUB_BINARY_SENSOR(moving_target)
43 SUB_BINARY_SENSOR(still_target)
44 SUB_BINARY_SENSOR(target)
45#endif
46#ifdef USE_SENSOR
47 SUB_SENSOR_WITH_DEDUP(light, uint8_t)
48 SUB_SENSOR_WITH_DEDUP(detection_distance, int)
49 SUB_SENSOR_WITH_DEDUP(moving_target_distance, int)
50 SUB_SENSOR_WITH_DEDUP(moving_target_energy, uint8_t)
51 SUB_SENSOR_WITH_DEDUP(still_target_distance, int)
52 SUB_SENSOR_WITH_DEDUP(still_target_energy, uint8_t)
53#endif
54#ifdef USE_TEXT_SENSOR
55 SUB_TEXT_SENSOR(version)
56 SUB_TEXT_SENSOR(mac)
57#endif
58#ifdef USE_NUMBER
59 SUB_NUMBER(light_threshold)
60 SUB_NUMBER(max_move_distance_gate)
61 SUB_NUMBER(max_still_distance_gate)
62 SUB_NUMBER(timeout)
63#endif
64#ifdef USE_SELECT
65 SUB_SELECT(baud_rate)
66 SUB_SELECT(distance_resolution)
67 SUB_SELECT(light_function)
68 SUB_SELECT(out_pin_level)
69#endif
70#ifdef USE_SWITCH
71 SUB_SWITCH(bluetooth)
72 SUB_SWITCH(engineering_mode)
73#endif
74#ifdef USE_BUTTON
75 SUB_BUTTON(factory_reset)
76 SUB_BUTTON(query)
77 SUB_BUTTON(restart)
78#endif
79
80 public:
81 void setup() override;
82 void dump_config() override;
83 void loop() override;
84 void set_light_out_control();
85#ifdef USE_NUMBER
86 void set_gate_still_threshold_number(uint8_t gate, number::Number *n);
87 void set_gate_move_threshold_number(uint8_t gate, number::Number *n);
88 void set_max_distances_timeout();
89 void set_gate_threshold(uint8_t gate);
90#endif
91#ifdef USE_SENSOR
92 void set_gate_move_sensor(uint8_t gate, sensor::Sensor *s);
93 void set_gate_still_sensor(uint8_t gate, sensor::Sensor *s);
94#endif
95 void set_bluetooth_password(const std::string &password);
96 void set_engineering_mode(bool enable);
97 void read_all_info();
98 void restart_and_read_all_info();
99 void set_bluetooth(bool enable);
100 void set_distance_resolution(const char *state);
101 void set_baud_rate(const char *state);
102 void factory_reset();
103
104 protected:
105 void send_command_(uint8_t command_str, const uint8_t *command_value, uint8_t command_value_len);
106 void set_config_mode_(bool enable);
108 bool handle_ack_data_();
109 void readline_(int readch);
110 void query_parameters_();
111 void get_version_();
112 void get_mac_();
115 void restart_();
116
117 uint8_t light_function_ = 0;
118 uint8_t light_threshold_ = 0;
119 uint8_t out_pin_level_ = 0;
120 uint8_t buffer_pos_ = 0; // where to resume processing/populating buffer
121 uint8_t buffer_data_[MAX_LINE_LENGTH];
122 uint8_t mac_address_[6] = {0, 0, 0, 0, 0, 0};
123 uint8_t version_[6] = {0, 0, 0, 0, 0, 0};
124 bool bluetooth_on_{false};
125#ifdef USE_NUMBER
126 std::array<number::Number *, TOTAL_GATES> gate_move_threshold_numbers_{};
127 std::array<number::Number *, TOTAL_GATES> gate_still_threshold_numbers_{};
128#endif
129#ifdef USE_SENSOR
130 std::array<SensorWithDedup<uint8_t> *, TOTAL_GATES> gate_move_sensors_{};
131 std::array<SensorWithDedup<uint8_t> *, TOTAL_GATES> gate_still_sensors_{};
132#endif
133};
134
135} // namespace esphome::ld2410
virtual void setup()
Where the component's initialization should happen.
std::array< number::Number *, TOTAL_GATES > gate_still_threshold_numbers_
Definition ld2410.h:127
void set_config_mode_(bool enable)
Definition ld2410.cpp:613
std::array< number::Number *, TOTAL_GATES > gate_move_threshold_numbers_
Definition ld2410.h:126
std::array< SensorWithDedup< uint8_t > *, TOTAL_GATES > gate_still_sensors_
Definition ld2410.h:131
std::array< SensorWithDedup< uint8_t > *, TOTAL_GATES > gate_move_sensors_
Definition ld2410.h:130
void send_command_(uint8_t command_str, const uint8_t *command_value, uint8_t command_value_len)
Definition ld2410.cpp:280
uint8_t buffer_data_[MAX_LINE_LENGTH]
Definition ld2410.h:121
Base-class for all numbers.
Definition number.h:29
Base-class for all sensors.
Definition sensor.h:43
bool state
Definition fan.h:0