ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
ld2460.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <array>
8
9namespace esphome::ld2460 {
10
11static constexpr uint8_t MAX_LINE_LENGTH = 32; // Longest frame is a 5-target data frame of 31 bytes
12static constexpr uint8_t MAX_TARGETS = 5;
13
14enum class InstallationMode : uint8_t {
17};
18
20#ifdef USE_SENSOR
21 SUB_SENSOR_WITH_DEDUP(target_count, uint8_t)
22#endif
23
24 public:
25 void setup() override;
26 void dump_config() override;
27 void loop() override;
28
29#ifdef USE_SENSOR
30 void set_target_x_sensor(uint8_t target, sensor::Sensor *s) { this->target_sensors_[target].x.set_sensor(s); }
31 void set_target_y_sensor(uint8_t target, sensor::Sensor *s) { this->target_sensors_[target].y.set_sensor(s); }
32 void set_target_distance_sensor(uint8_t target, sensor::Sensor *s) {
33 this->target_sensors_[target].distance.set_sensor(s);
34 }
35 void set_target_angle_sensor(uint8_t target, sensor::Sensor *s) { this->target_sensors_[target].angle.set_sensor(s); }
36#endif
37
39 template<typename F> void add_on_data_callback(F &&callback) { this->data_callback_.add(std::forward<F>(callback)); }
40
41 protected:
42 void send_query_();
43 bool align_to_header_(const uint8_t *header);
45 void handle_ack_();
46 void readline_(uint8_t readch);
47
48#ifdef USE_SENSOR
49 // INT16_MIN marks a slot with no published coordinates, so the next report always publishes
52 int16_t last_x{INT16_MIN};
53 int16_t last_y{INT16_MIN};
54 };
55 std::array<TargetSensors, MAX_TARGETS> target_sensors_{};
56#endif
57
59 uint8_t buffer_data_[MAX_LINE_LENGTH];
60 uint8_t buffer_pos_{0};
61 // The angle formula depends on how the module is mounted, so it is read from the module at boot
63 // Queries sent so far; 0 once the module answered. Data frames resend up to MAX_QUERY_ATTEMPTS.
64 uint8_t query_attempts_{1};
65};
66
67} // namespace esphome::ld2460
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:84
InstallationMode installation_mode_
Definition ld2460.h:62
uint8_t buffer_data_[MAX_LINE_LENGTH]
Definition ld2460.h:59
void readline_(uint8_t readch)
Definition ld2460.cpp:155
bool align_to_header_(const uint8_t *header)
Definition ld2460.cpp:187
std::array< TargetSensors, MAX_TARGETS > target_sensors_
Definition ld2460.h:55
LazyCallbackManager< void()> data_callback_
Definition ld2460.h:58
Sensor with deduplication — sensor may be null, null check is internal.
Definition ld24xx.h:66
Base-class for all sensors.
Definition sensor.h:47
ld24xx::SensorWithDedup< float > y
Definition ld2460.h:51
ld24xx::SensorWithDedup< float > x
Definition ld2460.h:51
ld24xx::SensorWithDedup< float > distance
Definition ld2460.h:51
ld24xx::SensorWithDedup< float > angle
Definition ld2460.h:51