ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ld600x.cpp
Go to the documentation of this file.
1#include "ld600x.h"
3#include "esphome/core/hal.h"
5#include "esphome/core/log.h"
7#include <algorithm>
8#include <cctype>
9#include <cinttypes>
10#include <cmath>
11#include <cstdio>
12#include <cstring>
13
14namespace esphome::ld600x {
15
16// Every log line in this file carries the derived model's tag. The ESP_LOG* and LOG_* macros take the
17// identifier TAG, so it resolves to the per-instance tag inside the member functions below.
18#define TAG (this->log_tag_)
19
20static constexpr uint32_t SETUP_DELAY_MS = 100;
21
22// Command/message types
23static constexpr uint16_t TYPE_CONTROL = 0x0201;
24static constexpr uint16_t TYPE_SET_AREA = 0x0202;
25static constexpr uint16_t TYPE_SET_HOLD_DELAY = 0x0203;
26static constexpr uint16_t TYPE_SET_Z_RANGE = 0x0204;
27static constexpr uint16_t TYPE_SET_LOW_POWER_SLEEP = 0x0205;
28
29static constexpr uint16_t TYPE_REPORT_TARGET = 0x0A04;
30static constexpr uint16_t TYPE_REPORT_POINT_CLOUD = 0x0A08;
31static constexpr uint16_t TYPE_REPORT_AREA_PRESENCE = 0x0A0A;
32static constexpr uint16_t TYPE_REPORT_INTERFERENCE_AREAS = 0x0A0B;
33static constexpr uint16_t TYPE_REPORT_DETECTION_AREAS = 0x0A0C;
34static constexpr uint16_t TYPE_REPORT_DELAY = 0x0A0D;
35static constexpr uint16_t TYPE_REPORT_SENSITIVITY = 0x0A0E;
36static constexpr uint16_t TYPE_REPORT_TRIGGER = 0x0A0F;
37static constexpr uint16_t TYPE_REPORT_Z_RANGE = 0x0A10;
38static constexpr uint16_t TYPE_REPORT_INSTALLATION = 0x0A11;
39static constexpr uint16_t TYPE_REPORT_MODE = 0x0A12; // low power on the LD6002B, work mode on the LD6004
40static constexpr uint16_t TYPE_REPORT_LOW_POWER_SLEEP = 0x0A13;
41#if LD600X_AREA_KINDS > 2
42static constexpr uint16_t TYPE_REPORT_DWELL_AREAS = 0x0A16;
43#endif
44static constexpr uint16_t TYPE_QUERY_VERSION = 0xFFFF;
45
46// Control command values for TYPE_CONTROL
47static constexpr uint32_t CMD_AUTO_INTERFERENCE = 0x01;
48static constexpr uint32_t CMD_GET_AREAS = 0x02;
49static constexpr uint32_t CMD_CLEAR_INTERFERENCE = 0x03;
50static constexpr uint32_t CMD_RESET_DETECTION_AREA = 0x04;
51static constexpr uint32_t CMD_GET_DELAY = 0x05;
52static constexpr uint32_t CMD_POINT_CLOUD_ON = 0x06;
53static constexpr uint32_t CMD_POINT_CLOUD_OFF = 0x07;
54static constexpr uint32_t CMD_TARGET_DISPLAY_ON = 0x08;
55static constexpr uint32_t CMD_TARGET_DISPLAY_OFF = 0x09;
56static constexpr uint32_t CMD_SENSITIVITY_LOW = 0x0A;
57static constexpr uint32_t CMD_SENSITIVITY_MEDIUM = 0x0B;
58static constexpr uint32_t CMD_SENSITIVITY_HIGH = 0x0C;
59static constexpr uint32_t CMD_GET_SENSITIVITY = 0x0D;
60static constexpr uint32_t CMD_TRIGGER_SLOW = 0x0E;
61static constexpr uint32_t CMD_TRIGGER_MEDIUM = 0x0F;
62static constexpr uint32_t CMD_TRIGGER_FAST = 0x10;
63static constexpr uint32_t CMD_GET_TRIGGER = 0x11;
64static constexpr uint32_t CMD_GET_Z_RANGE = 0x12;
65static constexpr uint32_t CMD_INSTALL_TOP = 0x13;
66static constexpr uint32_t CMD_INSTALL_SIDE = 0x14;
67// set_select_value() sends the first command of each run plus the option index.
68static_assert(CMD_SENSITIVITY_MEDIUM == CMD_SENSITIVITY_LOW + 1 && CMD_SENSITIVITY_HIGH == CMD_SENSITIVITY_LOW + 2);
69static_assert(CMD_TRIGGER_MEDIUM == CMD_TRIGGER_SLOW + 1 && CMD_TRIGGER_FAST == CMD_TRIGGER_SLOW + 2);
70static_assert(CMD_INSTALL_SIDE == CMD_INSTALL_TOP + 1);
71static constexpr uint32_t CMD_GET_INSTALLATION = 0x15;
72// Both models answer 0x16 to 0x18 with report 0x0A12; the opcodes stay here for the verbose logs.
73static constexpr uint32_t CMD_LOW_POWER_ON = 0x16;
74static constexpr uint32_t CMD_LOW_POWER_OFF = 0x17;
75// Asks for report 0x0A12, which each model reads its own way: low power on the LD6002B, the work mode
76// on the LD6004. Only the shared get_low_power_mode button sends it from here.
77static constexpr uint32_t CMD_GET_MODE = 0x18;
78static constexpr uint32_t CMD_GET_LOW_POWER_SLEEP = 0x19;
79static constexpr uint32_t CMD_RESET_UNATTENDED = 0x1A;
80
81static constexpr uint16_t TARGET_DATA_LEN = 20; // x,y,z,dop_idx,cluster_id
82static constexpr uint16_t AREA_DATA_LEN = 24; // 6 floats
83static constexpr uint16_t AREA_CONFIG_LEN = 28; // int32 + 6 floats
84static constexpr uint16_t AREA_PRESENCE_ENTRY_LEN = 4; // uint32 per detection area
85
86static constexpr uint8_t AREA_ID_DEFAULT = 4; // detection_area_0 for initial display
87
88static constexpr uint8_t VERSION_QUERY_DATA[] = {0x01, 0x01, 0x00, 0x00};
89
90#ifdef ESPHOME_LOG_HAS_VERBOSE
91// Indexed by control command code - 1 (codes run 0x01 to 0x1A); the last entry is the fallback.
92PROGMEM_STRING_TABLE(ControlCommandNames, "auto_interference", "get_areas", "clear_interference",
93 "reset_detection_area", "get_delay", "point_cloud_on", "point_cloud_off", "target_display_on",
94 "target_display_off", "sensitivity_low", "sensitivity_medium", "sensitivity_high",
95 "get_sensitivity", "trigger_slow", "trigger_medium", "trigger_fast", "get_trigger", "get_z_range",
96 "install_top", "install_side", "get_installation", "low_power_on", "low_power_off", "get_mode",
97 "get_low_power_sleep", "reset_unattended", "unknown");
98static_assert(CMD_AUTO_INTERFERENCE == 1 && CMD_RESET_UNATTENDED == ControlCommandNames::LAST_INDEX,
99 "ControlCommandNames is indexed by command - 1");
100
101static const LogString *control_command_name(uint32_t command) {
102 // Range checked in 32 bits: get_log_str takes a uint8_t index; command 0 wraps and falls back too
103 const uint32_t idx = command - 1;
104 return ControlCommandNames::get_log_str(idx < ControlCommandNames::COUNT ? idx : ControlCommandNames::LAST_INDEX,
105 ControlCommandNames::LAST_INDEX);
106}
107
108static const LogString *frame_type_name(uint16_t type) {
109 switch (type) {
110 case TYPE_CONTROL:
111 return LOG_STR("control");
112 case TYPE_SET_AREA:
113 return LOG_STR("set_area");
114 case TYPE_SET_HOLD_DELAY:
115 return LOG_STR("set_hold_delay");
116 case TYPE_SET_Z_RANGE:
117 return LOG_STR("set_z_range");
118 case TYPE_SET_LOW_POWER_SLEEP:
119 return LOG_STR("set_low_power_sleep");
120 case TYPE_REPORT_TARGET:
121 return LOG_STR("report_target");
122 case TYPE_REPORT_POINT_CLOUD:
123 return LOG_STR("report_point_cloud");
124 case TYPE_REPORT_AREA_PRESENCE:
125 return LOG_STR("report_area_presence");
126 case TYPE_REPORT_INTERFERENCE_AREAS:
127 return LOG_STR("report_interference_areas");
128 case TYPE_REPORT_DETECTION_AREAS:
129 return LOG_STR("report_detection_areas");
130 case TYPE_REPORT_DELAY:
131 return LOG_STR("report_delay");
132 case TYPE_REPORT_SENSITIVITY:
133 return LOG_STR("report_sensitivity");
134 case TYPE_REPORT_TRIGGER:
135 return LOG_STR("report_trigger");
136 case TYPE_REPORT_Z_RANGE:
137 return LOG_STR("report_z_range");
138 case TYPE_REPORT_INSTALLATION:
139 return LOG_STR("report_installation");
140 case TYPE_REPORT_MODE:
141 return LOG_STR("report_mode");
142 case TYPE_REPORT_LOW_POWER_SLEEP:
143 return LOG_STR("report_low_power_sleep");
144 case TYPE_QUERY_VERSION:
145 return LOG_STR("query_version");
146 default:
147 return LOG_STR("unknown");
148 }
149}
150
151static bool is_expected_control_report(uint32_t command, uint16_t type) {
152 switch (command) {
153 case CMD_GET_AREAS:
154 return type == TYPE_REPORT_INTERFERENCE_AREAS || type == TYPE_REPORT_DETECTION_AREAS;
155 case CMD_GET_DELAY:
156 return type == TYPE_REPORT_DELAY;
157 case CMD_GET_SENSITIVITY:
158 return type == TYPE_REPORT_SENSITIVITY;
159 case CMD_GET_TRIGGER:
160 return type == TYPE_REPORT_TRIGGER;
161 case CMD_GET_Z_RANGE:
162 return type == TYPE_REPORT_Z_RANGE;
163 case CMD_GET_INSTALLATION:
164 return type == TYPE_REPORT_INSTALLATION;
165 case CMD_LOW_POWER_ON:
166 case CMD_LOW_POWER_OFF:
167 case CMD_GET_MODE:
168 return type == TYPE_REPORT_MODE;
169 case CMD_GET_LOW_POWER_SLEEP:
170 return type == TYPE_REPORT_LOW_POWER_SLEEP;
171 default:
172 return false;
173 }
174}
175#endif
176
178 // Only the point cloud stream needs the larger frame; nothing resizes the buffer after setup.
179 bool point_cloud_configured = false;
180#ifdef USE_SENSOR
181 point_cloud_configured = point_cloud_configured || this->point_count_sensor_.has_sensor();
182#endif
183#ifdef USE_SWITCH
184 point_cloud_configured = point_cloud_configured || this->point_cloud_switch_ != nullptr;
185#endif
186 const uint16_t capacity = point_cloud_configured ? DEFAULT_MAX_DATA_LEN_POINT_CLOUD : DEFAULT_MAX_DATA_LEN;
187 // One allocation for the component lifetime; the parser reuses it for every payload.
188 RAMAllocator<uint8_t> allocator;
189 uint8_t *buffer = allocator.allocate(capacity);
190 if (buffer == nullptr) {
191 this->mark_failed(LOG_STR("Failed to allocate frame buffer"));
192 return;
193 }
194 this->parser_.init(buffer, capacity);
195
196 this->set_timeout(SETUP_DELAY_MS, [this]() {
197 bool want_target_stream = false;
198#ifdef USE_SENSOR
199 want_target_stream = want_target_stream || this->target_count_sensor_.has_sensor();
200 if (!want_target_stream) {
201 for (const auto &target : this->targets_) {
202 if (target.x != nullptr || target.y != nullptr || target.z != nullptr || target.dop_idx != nullptr ||
203 target.cluster_id.has_sensor()) {
204 want_target_stream = true;
205 break;
206 }
207 }
208 }
209#endif
210#ifdef USE_BINARY_SENSOR
211 want_target_stream = want_target_stream || this->presence_binary_sensor_ != nullptr;
212 if (!want_target_stream) {
213 for (auto *sensor : this->target_presence_) {
214 if (sensor != nullptr) {
215 want_target_stream = true;
216 break;
217 }
218 }
219 }
220#endif
221 // This only feeds the automatic branch below: with a target_display switch
222 // configured that switch still decides.
223 want_target_stream = want_target_stream || this->model_wants_target_stream();
224 bool target_display_controlled = false;
225#ifdef USE_SWITCH
226 if (this->target_display_switch_ != nullptr) {
227 target_display_controlled = true;
228 // Nothing reports this switch back, so its restored state is the only state there is.
229 this->target_display_switch_->restore(true);
230 }
231#endif
232 if (!target_display_controlled) {
233 // No switch: the stream follows its consumers. With none, nothing is sent
234 // and the module's own default stands -- but the reports are gated out
235 // regardless, because there is nothing configured for them to feed.
236 this->target_display_enabled_ = want_target_stream;
237 if (want_target_stream) {
238 this->send_control_command_(CMD_TARGET_DISPLAY_ON);
239 }
240 }
241
242 bool point_cloud_controlled = false;
243#ifdef USE_SWITCH
244 if (this->point_cloud_switch_ != nullptr) {
245 point_cloud_controlled = true;
246 this->point_cloud_switch_->restore(false);
247 }
248#endif
249 if (!point_cloud_controlled) {
250 // No switch: the stream follows the sensor that reads it, which is also what
251 // the frame buffer above was sized for.
252 bool want_point_cloud = false;
253#ifdef USE_SENSOR
254 want_point_cloud = this->point_count_sensor_.has_sensor();
255#endif
256 this->send_control_command_(want_point_cloud ? CMD_POINT_CLOUD_ON : CMD_POINT_CLOUD_OFF);
257 this->point_cloud_enabled_ = want_point_cloud;
258 }
259
260#ifdef USE_SELECT
261 if (this->sensitivity_select_ != nullptr) {
262 this->send_control_command_(CMD_GET_SENSITIVITY);
263 }
264 if (this->trigger_speed_select_ != nullptr) {
265 this->send_control_command_(CMD_GET_TRIGGER);
266 }
267 if (this->installation_select_ != nullptr) {
268 this->send_control_command_(CMD_GET_INSTALLATION);
269 }
270#endif
271#ifdef USE_NUMBER
272 if (this->z_min_number_ != nullptr || this->z_max_number_ != nullptr) {
273 this->send_control_command_(CMD_GET_Z_RANGE);
274 }
275 if (this->low_power_sleep_number_ != nullptr) {
276 this->send_control_command_(CMD_GET_LOW_POWER_SLEEP);
277 }
278 if (this->hold_delay_number_ != nullptr) {
279 this->send_control_command_(CMD_GET_DELAY);
280 }
281#endif
282 bool want_area_report = false;
283#ifdef USE_SENSOR
284 for (const auto &area : this->areas_) {
285 for (auto *sensor : area)
286 want_area_report = want_area_report || sensor != nullptr;
287 }
288#endif
289#ifdef USE_NUMBER
290 if (this->area_x_min_number_ != nullptr || this->area_x_max_number_ != nullptr ||
291 this->area_y_min_number_ != nullptr || this->area_y_max_number_ != nullptr ||
292 this->area_z_min_number_ != nullptr || this->area_z_max_number_ != nullptr) {
293 want_area_report = true;
294 }
295#endif
296 if (want_area_report) {
297 this->send_control_command_(CMD_GET_AREAS);
298 }
299
300 this->init_area_id_pref_();
301 this->init_version_pref_();
302
303#ifdef USE_TEXT_SENSOR
304 if (this->ota_version_text_sensor_ != nullptr) {
305 this->queue_command_(TYPE_QUERY_VERSION, VERSION_QUERY_DATA, sizeof(VERSION_QUERY_DATA));
306 }
307#endif
308 this->setup_model();
309 });
310}
311
313 // "HLK-" plus the upper-cased tag. The tag sits in flash on ESP8266, so it is read a byte at a time.
314 char model[16] = "HLK-";
315 size_t pos = 4;
316 for (const auto *p = reinterpret_cast<const uint8_t *>(this->log_tag_); pos < sizeof(model) - 1; p++) {
317 const uint8_t c = progmem_read_byte(p);
318 if (c == 0)
319 break;
320 model[pos++] = static_cast<char>(std::toupper(c));
321 }
322 model[pos] = '\0';
323 ESP_LOGCONFIG(TAG,
324 "%s:\n"
325 " Max data length: %u",
326 model, static_cast<unsigned>(this->parser_.capacity()));
327#ifdef USE_SENSOR
328 LOG_SENSOR_WITH_DEDUP(" ", "Target Count", this->target_count_sensor_);
329 LOG_SENSOR_WITH_DEDUP(" ", "Point Count", this->point_count_sensor_);
330 for (auto &target : this->targets_) {
331 LOG_SENSOR(" ", "Target X", target.x);
332 LOG_SENSOR(" ", "Target Y", target.y);
333 LOG_SENSOR(" ", "Target Z", target.z);
334 LOG_SENSOR(" ", "Target Doppler Index", target.dop_idx);
335 LOG_SENSOR_WITH_DEDUP(" ", "Target Cluster ID", target.cluster_id);
336 }
337 for (uint8_t i = 0; i < AREA_COUNT; i++) {
338 const AreaSensors &area = this->areas_[area_index(AREA_KIND_INTERFERENCE, i)];
339 LOG_SENSOR(" ", "Interference Area X Min", area[AREA_AXIS_X_MIN]);
340 LOG_SENSOR(" ", "Interference Area X Max", area[AREA_AXIS_X_MAX]);
341 LOG_SENSOR(" ", "Interference Area Y Min", area[AREA_AXIS_Y_MIN]);
342 LOG_SENSOR(" ", "Interference Area Y Max", area[AREA_AXIS_Y_MAX]);
343 LOG_SENSOR(" ", "Interference Area Z Min", area[AREA_AXIS_Z_MIN]);
344 LOG_SENSOR(" ", "Interference Area Z Max", area[AREA_AXIS_Z_MAX]);
345 }
346 for (uint8_t i = 0; i < AREA_COUNT; i++) {
347 const AreaSensors &area = this->areas_[area_index(AREA_KIND_DETECTION, i)];
348 LOG_SENSOR(" ", "Detection Area X Min", area[AREA_AXIS_X_MIN]);
349 LOG_SENSOR(" ", "Detection Area X Max", area[AREA_AXIS_X_MAX]);
350 LOG_SENSOR(" ", "Detection Area Y Min", area[AREA_AXIS_Y_MIN]);
351 LOG_SENSOR(" ", "Detection Area Y Max", area[AREA_AXIS_Y_MAX]);
352 LOG_SENSOR(" ", "Detection Area Z Min", area[AREA_AXIS_Z_MIN]);
353 LOG_SENSOR(" ", "Detection Area Z Max", area[AREA_AXIS_Z_MAX]);
354 }
355#if LD600X_AREA_KINDS > 2
356 for (uint8_t i = 0; i < AREA_COUNT; i++) {
357 const AreaSensors &area = this->areas_[area_index(AREA_KIND_DWELL, i)];
358 LOG_SENSOR(" ", "Dwell Area X Min", area[AREA_AXIS_X_MIN]);
359 LOG_SENSOR(" ", "Dwell Area X Max", area[AREA_AXIS_X_MAX]);
360 LOG_SENSOR(" ", "Dwell Area Y Min", area[AREA_AXIS_Y_MIN]);
361 LOG_SENSOR(" ", "Dwell Area Y Max", area[AREA_AXIS_Y_MAX]);
362 LOG_SENSOR(" ", "Dwell Area Z Min", area[AREA_AXIS_Z_MIN]);
363 LOG_SENSOR(" ", "Dwell Area Z Max", area[AREA_AXIS_Z_MAX]);
364 }
365#endif
366#endif
367#ifdef USE_BINARY_SENSOR
368 LOG_BINARY_SENSOR(" ", "Presence", this->presence_binary_sensor_);
369 for (uint8_t i = 0; i < LD600X_MAX_TARGETS; i++) {
370 LOG_BINARY_SENSOR(" ", "Target Presence", this->target_presence_[i]);
371 }
372 for (uint8_t i = 0; i < AREA_COUNT; i++) {
373 LOG_BINARY_SENSOR(" ", "Detection Area Presence", this->area_presence_[i]);
374 }
375#endif
376#ifdef USE_TEXT_SENSOR
377 LOG_TEXT_SENSOR(" ", "Work Mode", this->work_mode_text_sensor_);
378 LOG_TEXT_SENSOR(" ", "OTA Version", this->ota_version_text_sensor_);
379#endif
380#ifdef USE_NUMBER
381 LOG_NUMBER(" ", "Hold Delay", this->hold_delay_number_);
382 LOG_NUMBER(" ", "Z Min", this->z_min_number_);
383 LOG_NUMBER(" ", "Z Max", this->z_max_number_);
384 LOG_NUMBER(" ", "Low Power Sleep", this->low_power_sleep_number_);
385 LOG_NUMBER(" ", "Area X Min", this->area_x_min_number_);
386 LOG_NUMBER(" ", "Area X Max", this->area_x_max_number_);
387 LOG_NUMBER(" ", "Area Y Min", this->area_y_min_number_);
388 LOG_NUMBER(" ", "Area Y Max", this->area_y_max_number_);
389 LOG_NUMBER(" ", "Area Z Min", this->area_z_min_number_);
390 LOG_NUMBER(" ", "Area Z Max", this->area_z_max_number_);
391#endif
392#ifdef USE_SWITCH
393 LOG_SWITCH(" ", "Point Cloud", this->point_cloud_switch_);
394 LOG_SWITCH(" ", "Target Display", this->target_display_switch_);
395#endif
396#ifdef USE_SELECT
397 LOG_SELECT(" ", "Sensitivity", this->sensitivity_select_);
398 LOG_SELECT(" ", "Trigger Speed", this->trigger_speed_select_);
399 LOG_SELECT(" ", "Installation Mode", this->installation_select_);
400 LOG_SELECT(" ", "Area ID", this->area_id_select_);
401#endif
402 this->dump_model_config();
403}
404
406 this->read_available([this](uint8_t byte) {
407 if (this->parser_.feed(byte)) {
408 this->handle_frame_(this->parser_.type(), this->parser_.data(), this->parser_.length());
409 }
410 });
412}
413
414void LD600XComponent::handle_frame_(uint16_t type, const uint8_t *data, uint16_t len) {
416 this->last_traffic_ms_ = now;
417 if (this->stale_ack_count_ > 0 && now - this->stale_ack_ms_ > STALE_ACK_MAX_AGE_MS) {
418 this->stale_ack_count_ = 0;
419 }
420 // ACKs carry no id and arrive in send order: debt from earlier attempts is paid before the active command.
421 if (len == 0 && this->stale_ack_count_ > 0 && this->stale_ack_type_ == type) {
422 this->stale_ack_count_--;
423 ESP_LOGV(TAG, "Ignoring ACK for command 0x%04X from an earlier attempt (module frame 0x%04X)", type,
424 this->parser_.id());
425 return;
426 }
427 if (len == 0 && this->command_active_ && this->command_sent_ && type == this->active_command_.type) {
428 ESP_LOGV(TAG, "ACK for command 0x%04X (module frame 0x%04X)", type, this->parser_.id());
429 const bool refresh_areas = (type == TYPE_SET_AREA) && this->area_write_in_flight_;
430 // This settles one expected reply; the rest stay owed and become the debt for the next command.
431 this->send_generation_++;
432 this->stale_ack_type_ = type;
433 this->stale_ack_count_ = this->acks_expected_ > 0 ? static_cast<uint8_t>(this->acks_expected_ - 1) : 0;
434 this->stale_ack_ms_ = now;
435 this->command_active_ = false;
436 this->command_sent_ = false;
437 this->last_send_ms_ = 0;
439 if (refresh_areas) {
440 this->area_write_in_flight_ = false;
441 this->set_timeout(AREA_REFRESH_TIMEOUT_ID, 50, [this]() { this->send_control_command_(CMD_GET_AREAS); });
442 }
443 return;
444 }
445
446#ifdef ESPHOME_LOG_HAS_VERBOSE
447 const uint32_t active_control_command =
448 (this->command_active_ && this->active_command_.type == TYPE_CONTROL && this->active_command_.len >= 4)
450 : 0;
451 if (active_control_command != 0 && is_expected_control_report(active_control_command, type)) {
452 ESP_LOGV(TAG, "Received %s (0x%04X) while waiting for %s (0x%02" PRIX32 ") ACK", LOG_STR_ARG(frame_type_name(type)),
453 type, LOG_STR_ARG(control_command_name(active_control_command)), active_control_command);
454 }
455#endif
456
457 if (this->handle_model_report(type, data, len))
458 return;
459
460 switch (type) {
461 case TYPE_REPORT_TARGET:
462 this->handle_target_report_(data, len);
463 break;
464 case TYPE_REPORT_POINT_CLOUD:
465 this->handle_point_cloud_(data, len);
466 break;
467 case TYPE_REPORT_AREA_PRESENCE:
468 this->handle_area_presence_(data, len);
469 break;
470 case TYPE_REPORT_INTERFERENCE_AREAS:
472 break;
473 case TYPE_REPORT_DETECTION_AREAS:
475 break;
476#if LD600X_AREA_KINDS > 2
477 case TYPE_REPORT_DWELL_AREAS:
479 break;
480#endif
481 case TYPE_REPORT_DELAY:
482 this->handle_delay_report_(data, len);
483 break;
484 case TYPE_REPORT_SENSITIVITY:
485 this->handle_sensitivity_report_(data, len);
486 break;
487 case TYPE_REPORT_TRIGGER:
489 break;
490 case TYPE_REPORT_Z_RANGE:
491 this->handle_z_range_report_(data, len);
492 break;
493 case TYPE_REPORT_INSTALLATION:
494 this->handle_installation_report_(data, len);
495 break;
496 case TYPE_REPORT_LOW_POWER_SLEEP:
498 break;
499 case TYPE_QUERY_VERSION:
500 this->handle_version_report_(data, len);
501 break;
502 default:
503 break;
504 }
505}
506
507void LD600XComponent::handle_target_report_(const uint8_t *data, uint16_t len) {
508 // The module stops streaming when it acts on the command, not when the command
509 // is queued, so trailing frames after an off must not repopulate what
510 // set_switch_state just cleared.
511 if (!this->target_display_enabled_) {
512 return;
513 }
514 if (len < 4)
515 return;
516
517 uint32_t target_num = encode_value_le<uint32_t>(data);
518 uint16_t available = (len - 4) / TARGET_DATA_LEN;
519 // Un-narrowed: a report of e.g. 256 targets must not truncate to 0 and read as "absent".
520 const uint32_t reported = std::min<uint32_t>(target_num, available);
521 uint8_t count = static_cast<uint8_t>(std::min<uint32_t>(reported, LD600X_MAX_TARGETS));
522
523 // The module re-sorts its array by cluster id, so slots key on the id to track the person.
524 std::array<int32_t, LD600X_MAX_TARGETS> wire_cluster{};
525 std::array<bool, LD600X_MAX_TARGETS> wire_placed{};
526 std::array<bool, LD600X_MAX_TARGETS> slot_seen{};
527 std::array<uint8_t, LD600X_MAX_TARGETS> slot_wire{};
528 for (uint8_t i = 0; i < count; i++) {
529 uint16_t cluster_offset = 4 + (i * TARGET_DATA_LEN) + 16;
530 wire_cluster[i] = encode_value_le<int32_t>(data + cluster_offset);
531 }
532 for (uint8_t i = 0; i < count; i++) {
533 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
534 if (this->slot_occupied_[s] && !slot_seen[s] && this->slot_cluster_[s] == wire_cluster[i]) {
535 slot_seen[s] = true;
536 wire_placed[i] = true;
537 slot_wire[s] = i;
538 break;
539 }
540 }
541 }
542 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
543 if (!slot_seen[s]) {
544 this->slot_occupied_[s] = false;
545 }
546 }
547 for (uint8_t i = 0; i < count; i++) {
548 if (wire_placed[i]) {
549 continue;
550 }
551 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
552 if (!this->slot_occupied_[s]) {
553 this->slot_occupied_[s] = true;
554 this->slot_cluster_[s] = wire_cluster[i];
555 slot_wire[s] = i;
556 break;
557 }
558 }
559 }
560
561#ifdef USE_SENSOR
562 this->target_count_sensor_.publish_state_if_not_dup(reported);
563#endif
564
565 this->target_presence_any_ = (reported > 0);
566#ifdef USE_BINARY_SENSOR
567 bool presence = this->target_presence_any_ || this->area_presence_any_;
568 PUBLISH_STATE(this->presence_binary_sensor_, presence);
569#endif
570 this->on_presence_update();
571
572 for (uint8_t i = 0; i < LD600X_MAX_TARGETS; i++) {
573 bool has_target = this->slot_occupied_[i];
574 if (has_target) {
575#ifdef USE_SENSOR
576 uint16_t offset = 4 + (slot_wire[i] * TARGET_DATA_LEN);
577 float x = read_f32_le(data + offset + 0);
578 float y = read_f32_le(data + offset + 4);
579 float z = read_f32_le(data + offset + 8);
580 int32_t dop_idx = encode_value_le<int32_t>(data + offset + 12);
581 int32_t cluster_id = this->slot_cluster_[i];
582 TargetSensors &target = this->targets_[i];
583 PUBLISH_STATE(target.x, x);
584 PUBLISH_STATE(target.y, y);
585 PUBLISH_STATE(target.z, z);
586 PUBLISH_STATE(target.dop_idx, static_cast<float>(dop_idx));
587 target.cluster_id.publish_state_if_not_dup(cluster_id);
588#endif
589 } else {
590#ifdef USE_SENSOR
591 this->clear_target_slot_(i);
592#endif
593 }
594#ifdef USE_BINARY_SENSOR
595 // publish_state() already skips unchanged states, no manual de-dup needed.
596 PUBLISH_STATE(this->target_presence_[i], has_target);
597#endif
598#ifdef USE_SENSOR
599 this->last_target_presence_[i] = has_target;
600#endif
601 }
602}
603
604void LD600XComponent::handle_point_cloud_(const uint8_t *data, uint16_t len) {
605 // Same window as the target stream: a frame already in flight must not put the
606 // count back after the switch cleared it.
607 if (!this->point_cloud_enabled_) {
608 return;
609 }
610 if (len < 4)
611 return;
612
613#ifdef USE_SENSOR
614 this->point_count_sensor_.publish_state_if_not_dup(encode_value_le<uint32_t>(data));
615#endif
616}
617
618// 0x0A0A carries one uint32 per detection area -- the protocol names the four
619// fields detection_state_area0..3 -- so this covers area ids 4..7 only. The
620// interference areas have no presence report: a target inside one is what they
621// exist to suppress.
622void LD600XComponent::handle_area_presence_(const uint8_t *data, uint16_t len) {
623 const uint16_t needed = AREA_COUNT * AREA_PRESENCE_ENTRY_LEN;
624 if (len < needed)
625 return;
626
627 this->area_presence_any_ = false;
628 for (uint8_t i = 0; i < AREA_COUNT; i++) {
629 uint32_t state = encode_value_le<uint32_t>(data + (i * AREA_PRESENCE_ENTRY_LEN));
630 bool present = state != 0;
631 this->area_presence_any_ = this->area_presence_any_ || present;
632#ifdef USE_BINARY_SENSOR
633 PUBLISH_STATE(this->area_presence_[i], present);
634#endif
635 }
636
637#ifdef USE_BINARY_SENSOR
638 bool presence = this->target_presence_any_ || this->area_presence_any_;
639 PUBLISH_STATE(this->presence_binary_sensor_, presence);
640#endif
641 this->on_presence_update();
642}
643
644void LD600XComponent::handle_area_report_(uint8_t kind, const uint8_t *data, uint16_t len) {
645 uint16_t needed = AREA_COUNT * AREA_DATA_LEN;
646 if (len < needed)
647 return;
648
649 for (uint8_t i = 0; i < AREA_COUNT; i++) {
650 uint16_t offset = i * AREA_DATA_LEN;
651 float x_min = read_f32_le(data + offset + 0);
652 float x_max = read_f32_le(data + offset + 4);
653 float y_min = read_f32_le(data + offset + 8);
654 float y_max = read_f32_le(data + offset + 12);
655 float z_min = read_f32_le(data + offset + 16);
656 float z_max = read_f32_le(data + offset + 20);
657
658#ifdef USE_SENSOR
659 const AreaSensors &area = this->areas_[area_index(kind, i)];
660 const float values[AREA_AXIS_COUNT] = {x_min, x_max, y_min, y_max, z_min, z_max};
661 for (uint8_t axis = 0; axis < AREA_AXIS_COUNT; axis++)
662 PUBLISH_STATE(area[axis], values[axis]);
663#endif
664
665 AreaConfig &store = this->area_values_[area_index(kind, i)];
666 store.x_min = x_min;
667 store.x_max = x_max;
668 store.y_min = y_min;
669 store.y_max = y_max;
670 store.z_min = z_min;
671 store.z_max = z_max;
672
673 uint8_t selected_id = this->area_id_set_ ? this->area_id_ : AREA_ID_DEFAULT;
674 if (selected_id == area_index(kind, i)) {
675 this->update_area_numbers_(store);
676 }
677 }
678 this->try_apply_pending_area_(kind);
679}
680
681void LD600XComponent::handle_delay_report_(const uint8_t *data, uint16_t len) {
682 if (len < 4)
683 return;
684#ifdef USE_NUMBER
686 this->publish_number_clamped_(this->hold_delay_number_, delay);
687#endif
688}
689
690void LD600XComponent::handle_sensitivity_report_(const uint8_t *data, uint16_t len) {
691 if (len < 1)
692 return;
693#ifdef USE_SELECT
694 if (this->sensitivity_select_ == nullptr)
695 return;
696 uint8_t value = data[0];
697 if (value <= 2) {
698 this->sensitivity_select_->publish_state(value);
699 }
700#endif
701}
702
703void LD600XComponent::handle_trigger_speed_report_(const uint8_t *data, uint16_t len) {
704 if (len < 1)
705 return;
706#ifdef USE_SELECT
707 if (this->trigger_speed_select_ == nullptr)
708 return;
709 uint8_t value = data[0];
710 if (value <= 2) {
711 this->trigger_speed_select_->publish_state(value);
712 }
713#endif
714}
715
716void LD600XComponent::handle_z_range_report_(const uint8_t *data, uint16_t len) {
717 if (len < 8)
718 return;
719 float z_min = read_f32_le(data);
720 float z_max = read_f32_le(data + 4);
721 this->z_min_ = z_min;
722 this->z_max_ = z_max;
723#ifdef USE_NUMBER
724 this->publish_number_clamped_(this->z_min_number_, z_min);
725 this->publish_number_clamped_(this->z_max_number_, z_max);
726#endif
727}
728
729void LD600XComponent::handle_installation_report_(const uint8_t *data, uint16_t len) {
730 if (len < 1)
731 return;
732#ifdef USE_SELECT
733 if (this->installation_select_ == nullptr)
734 return;
735 uint8_t value = data[0];
736 if (value <= 1) {
737 this->installation_select_->publish_state(value);
738 }
739#endif
740}
741
742void LD600XComponent::handle_low_power_sleep_report_(const uint8_t *data, uint16_t len) {
743 if (len < 4)
744 return;
745#ifdef USE_NUMBER
746 uint32_t sleep_ms = encode_value_le<uint32_t>(data);
747 this->publish_number_clamped_(this->low_power_sleep_number_, sleep_ms);
748#endif
749}
750
751#ifdef USE_NUMBER
753 if (number == nullptr)
754 return;
755 if (std::isnan(value)) {
756 // NAN is this component's "the module has not told us yet". Publishing it on an
757 // entity that has never had a state would report a nan where unknown is the
758 // truth; on one that already shows a value it is the only way to say that value
759 // no longer describes the selected area.
760 if (number->has_state()) {
761 number->publish_state(value);
762 }
763 return;
764 }
765 const float min_value = number->traits.get_min_value();
766 const float max_value = number->traits.get_max_value();
767 // Outside the declared range the user cannot write the value back, so publish
768 // what they can reach and say what the module actually sent.
769 if (value < min_value || value > max_value) {
770 ESP_LOGW(TAG, "'%s': module reported %.1f, clamped to %.1f..%.1f", LOG_STR_ARG(number->get_log_name()), value,
771 min_value, max_value);
772 value = std::clamp(value, min_value, max_value);
773 }
774 number->publish_state(value);
775}
776#endif
777
778void LD600XComponent::handle_version_report_(const uint8_t *data, uint16_t len) {
779 if (len < 4)
780 return;
781#ifdef USE_TEXT_SENSOR
782 if (this->ota_version_text_sensor_ == nullptr)
783 return;
784 uint8_t project = data[0];
785 uint8_t major = data[1];
786 uint8_t minor = data[2];
787 uint8_t patch = data[3];
788 char buf[32];
789 if (project == 0) {
790 std::snprintf(buf, sizeof(buf), "%u.%u.%u", major, minor, patch);
791 } else {
792 std::snprintf(buf, sizeof(buf), "p%u %u.%u.%u", project, major, minor, patch);
793 }
794 this->ota_version_text_sensor_->publish_state(buf);
795 this->save_version_pref_(buf);
796#endif
797}
798
799bool LD600XComponent::queue_command_(uint16_t type, const uint8_t *data, uint8_t len) {
800 if (len > CMD_MAX_DATA_LEN) {
801 ESP_LOGW(TAG, "Command data too large: %u", len);
802 return false;
803 }
804 if (this->cmd_queue_.size() >= CMD_QUEUE_SIZE) {
805 ESP_LOGW(TAG, "Command queue full, dropping command 0x%04X", type);
806 return false;
807 }
808
809 PendingCommand cmd;
810 cmd.type = type;
811 cmd.len = len;
812 if (len > 0 && data != nullptr) {
813 std::memcpy(cmd.data.data(), data, len);
814 }
815 this->cmd_queue_.push(cmd);
816
818 return true;
819}
820
823 if (this->command_active_) {
824 // A sleeping module consumes the opening attempt as its wake-up instead of answering it.
825 const uint32_t ack_timeout = this->attempts_sent_ <= 1 ? CMD_FIRST_ACK_TIMEOUT_MS : CMD_ACK_TIMEOUT_MS;
826 if (this->command_sent_ && now - this->last_send_ms_ >= ack_timeout) {
827 const uint32_t active_control_command =
828 (this->active_command_.type == TYPE_CONTROL && this->active_command_.len >= 4)
830 : 0;
831 if (this->retries_left_ > 0) {
832#ifdef ESPHOME_LOG_HAS_VERBOSE
833 if (active_control_command != 0) {
834 ESP_LOGV(TAG, "Retrying %s (0x%02" PRIX32 "), %u attempt(s) remaining",
835 LOG_STR_ARG(control_command_name(active_control_command)), active_control_command,
836 this->retries_left_);
837 } else {
838 // Writes without a control subcommand (hold delay, z-range) had no retry trace at all.
839 ESP_LOGV(TAG, "Retrying command 0x%04X, %u attempt(s) remaining", this->active_command_.type,
840 this->retries_left_);
841 }
842#endif
843 this->command_sent_ = false;
844 this->last_send_ms_ = 0;
845 this->send_command_(this->active_command_.type, this->active_command_.data.data(), this->active_command_.len);
846 this->retries_left_--;
847 } else {
848 if (active_control_command != 0) {
849 ESP_LOGW(TAG, "Command 0x%04X subcommand 0x%02" PRIX32 " timed out", this->active_command_.type,
850 active_control_command);
851 } else {
852 ESP_LOGW(TAG, "Command 0x%04X timed out", this->active_command_.type);
853 }
854 if (this->active_command_.type == TYPE_SET_AREA) {
855 this->area_write_in_flight_ = false;
856 }
857 // The deferred apply is waiting on the report this command would have
858 // brought back, and nothing else re-arms it. Dropping it here is the
859 // difference between one apply lost to a timeout and one that rides in on
860 // an unrelated area report later, writing bounds the user has moved on from.
861 if (active_control_command == CMD_GET_AREAS && this->deferred_apply_pending_) {
862 this->deferred_apply_pending_ = false;
864 ESP_LOGW(TAG, "Area read timed out, dropping deferred area apply");
865 }
866 // A reply may still be in flight for the attempt we just gave up on, so carry one over as
867 // debt rather than clearing the ledger, or that late ACK would retire the successor. Only
868 // one: reaching this point means nothing was answered at all, so the older attempts are
869 // speculative, and carrying them would swallow the successor's own replies.
870 const uint16_t owed = (this->stale_ack_type_ == this->active_command_.type ? this->stale_ack_count_ : 0) +
871 (this->acks_expected_ > 0 ? 1 : 0);
873 this->stale_ack_count_ = static_cast<uint8_t>(std::min<uint16_t>(owed, 255));
874 this->stale_ack_ms_ = now;
875 this->send_generation_++;
876 this->command_active_ = false;
877 this->command_sent_ = false;
878 this->last_send_ms_ = 0;
879 }
880 }
881 return;
882 }
883
884 if (this->cmd_queue_.empty())
885 return;
886
887 this->active_command_ = this->cmd_queue_.front();
888 this->cmd_queue_.pop();
889
890 this->send_generation_++;
892 this->command_active_ = true;
893 this->command_sent_ = false;
894 this->last_send_ms_ = 0;
895 this->attempts_sent_ = 0;
896 this->acks_expected_ = 0;
897 if (this->stale_ack_type_ != this->active_command_.type) {
898 this->stale_ack_count_ = 0;
899 }
900 this->send_command_(this->active_command_.type, this->active_command_.data.data(), this->active_command_.len);
901}
902
903void LD600XComponent::send_command_(uint16_t type, const uint8_t *data, uint8_t len) {
904 this->send_command_internal_(type, data, len, true);
905}
906
907void LD600XComponent::send_command_internal_(uint16_t type, const uint8_t *data, uint8_t len, bool track) {
908 if (len > CMD_MAX_DATA_LEN) {
909 ESP_LOGW(TAG, "Command data too large: %u", len);
910 if (track) {
911 // Release the slot: an unwritten command is never acked and never times out.
912 this->command_active_ = false;
913 this->command_sent_ = false;
914 this->last_send_ms_ = 0;
915 }
916 return;
917 }
918
919 if (this->defer_frame_write(type, data, len, track))
920 return;
921 this->write_frame_(type, data, len, track);
922}
923
924void LD600XComponent::write_frame_(uint16_t type, const uint8_t *data, uint8_t len, bool track) {
925 const uint16_t frame_id = next_frame_id(this->next_frame_id_);
926 // send_command_internal_ rejects anything longer than CMD_MAX_DATA_LEN before it gets here.
927 uint8_t frame[TF_FRAME_OVERHEAD + CMD_MAX_DATA_LEN];
928 size_t frame_len = encode_frame(frame_id, type, data, len, frame);
929 this->write_array(frame, frame_len);
931 if (track) {
932 // A frame sent to a module that has had time to fall asleep is its wake-up, and goes unanswered.
933 if (this->last_traffic_ms_ != 0 && now - this->last_traffic_ms_ < MODULE_AWAKE_MS) {
934 this->acks_expected_++;
935 }
936 this->last_send_ms_ = now;
937 this->command_sent_ = true;
938 this->attempts_sent_++;
939 }
940 this->last_traffic_ms_ = now;
941}
942
944 uint8_t data[4];
945 put_le32(data, command);
946 return this->queue_command_(TYPE_CONTROL, data, sizeof(data));
947}
948
949bool LD600XComponent::send_z_range_(float z_min, float z_max) {
950 // One frame carries both bounds, so half a range cannot be written; the bound is held until the other is known.
951 if (std::isnan(z_min) || std::isnan(z_max)) {
952 ESP_LOGW(TAG, "Z range not written, other bound unknown");
953 return true;
954 }
955 // Both bounds are known and crossed; the frame has no way to say that.
956 if (z_min > z_max) {
957 ESP_LOGW(TAG, "Z range not written, min above max");
958 return false;
959 }
960 uint8_t data[8];
961 write_f32_le(data, z_min);
962 write_f32_le(data + 4, z_max);
963 return this->queue_command_(TYPE_SET_Z_RANGE, data, sizeof(data));
964}
965
966#ifdef USE_NUMBER
968 // NumberCall keeps the value inside the traits' range but does not round it to the step;
969 // the module takes whole numbers only.
970 if (std::floor(value) != value) {
971 ESP_LOGW(TAG, "Invalid number value: %f", value);
972 return false;
973 }
974 uint8_t data[4];
975 put_le32(data, static_cast<uint32_t>(value));
976 return this->queue_command_(type, data, sizeof(data));
977}
978#endif
979
981 if (!this->area_id_set_) {
982 ESP_LOGW(TAG, "Area ID not selected; ignoring apply");
983 return;
984 }
985 if (this->area_id_ >= AREA_ID_COUNT) {
986 ESP_LOGW(TAG, "Invalid area id: %u", this->area_id_);
987 return;
988 }
989
990 AreaConfig desired = this->area_values_[this->area_id_];
991 if (!std::isnan(this->area_x_min_))
992 desired.x_min = this->area_x_min_;
993 if (!std::isnan(this->area_x_max_))
994 desired.x_max = this->area_x_max_;
995 if (!std::isnan(this->area_y_min_))
996 desired.y_min = this->area_y_min_;
997 if (!std::isnan(this->area_y_max_))
998 desired.y_max = this->area_y_max_;
999 if (!std::isnan(this->area_z_min_))
1000 desired.z_min = this->area_z_min_;
1001 if (!std::isnan(this->area_z_max_))
1002 desired.z_max = this->area_z_max_;
1003
1004 if (std::isnan(desired.x_min) || std::isnan(desired.x_max) || std::isnan(desired.y_min) ||
1005 std::isnan(desired.y_max) || std::isnan(desired.z_min) || std::isnan(desired.z_max)) {
1006 // Ask first: a read that never reached the queue would leave a deferral waiting
1007 // on a report nobody requested, with the user's values already retired for it.
1008 if (!this->send_control_command_(CMD_GET_AREAS)) {
1009 ESP_LOGW(TAG, "Area read not queued; area config left unapplied");
1010 return;
1011 }
1012 this->deferred_apply_pending_ = true;
1013 this->pending_area_id_ = this->area_id_;
1014 // The ledger, not the mirror: the mirror also carries whatever the module last
1015 // reported for the axes the user never touched, and staging those would hand them
1016 // back later wearing the user's badge -- a module value the next report is then
1017 // kept away from. Staging only what was actually typed is also what makes the
1018 // replay's overlay right: the untouched axes come from the fresh report. An
1019 // empty ledger is a meaning rather than a gap, then: an apply with nothing
1020 // staged rewrites the area exactly as the report just described it, which is
1021 // what a direct apply with nothing staged already does.
1022 this->pending_area_updates_ = this->area_edits_;
1023 // Staged above, so they are the deferred apply's values now rather than an
1024 // unsent edit. Anything typed from here belongs to whatever the user does
1025 // next, which may well be a different area.
1026 this->area_edits_ = AreaConfig{};
1027 ESP_LOGI(TAG, "Area config incomplete; requesting current areas before applying");
1028 return;
1029 }
1030 // Only a write the module will actually see retires them.
1031 if (this->queue_area_config_(this->area_id_, desired)) {
1032 this->area_edits_ = AreaConfig{};
1033 }
1034}
1035
1036#ifdef USE_NUMBER
1037// Each setter picks its setting by entity pointer, so the entities share one generated class.
1038bool LD600XComponent::set_number_value(number::Number *entity, float value) {
1039 if (entity == this->hold_delay_number_)
1040 return this->queue_u32_setting_(TYPE_SET_HOLD_DELAY, value);
1041 if (entity == this->low_power_sleep_number_)
1042 return this->queue_u32_setting_(TYPE_SET_LOW_POWER_SLEEP, value);
1043 // The z bounds and the area edits are kept here until both bounds or the apply button write them.
1044 if (entity == this->z_min_number_ || entity == this->z_max_number_) {
1045 const bool is_min = entity == this->z_min_number_;
1046 const float z_min = is_min ? value : this->z_min_;
1047 const float z_max = is_min ? this->z_max_ : value;
1048 if (!this->send_z_range_(z_min, z_max))
1049 return false;
1050 this->z_min_ = z_min;
1051 this->z_max_ = z_max;
1052 return true;
1053 }
1054 if (entity == this->area_x_min_number_) {
1055 this->area_x_min_ = value;
1056 this->area_edits_.x_min = value;
1057 } else if (entity == this->area_x_max_number_) {
1058 this->area_x_max_ = value;
1059 this->area_edits_.x_max = value;
1060 } else if (entity == this->area_y_min_number_) {
1061 this->area_y_min_ = value;
1062 this->area_edits_.y_min = value;
1063 } else if (entity == this->area_y_max_number_) {
1064 this->area_y_max_ = value;
1065 this->area_edits_.y_max = value;
1066 } else if (entity == this->area_z_min_number_) {
1067 this->area_z_min_ = value;
1068 this->area_edits_.z_min = value;
1069 } else { // Only registered entities call this, so the last one needs no compare
1070 this->area_z_max_ = value;
1071 this->area_edits_.z_max = value;
1072 }
1073 return true;
1074}
1075#endif
1076
1077#ifdef USE_SELECT
1079 if (entity == this->sensitivity_select_)
1080 return index < 3 && this->send_control_command_(CMD_SENSITIVITY_LOW + index);
1081 if (entity == this->trigger_speed_select_)
1082 return index < 3 && this->send_control_command_(CMD_TRIGGER_SLOW + index);
1083 if (entity == this->installation_select_)
1084 return index < 2 && this->send_control_command_(CMD_INSTALL_TOP + index);
1085 // Only registered entities call this, so the last one needs no compare
1086 this->area_id_ = static_cast<uint8_t>(index);
1087 this->area_id_set_ = true;
1089 this->save_area_id_pref_(this->area_id_);
1090 return true;
1091}
1092#endif
1093
1095 // A report refreshes every axis the user is not in the middle of changing. An
1096 // unapplied edit is the one value here the module cannot know about, so taking
1097 // the report over it would discard what the user typed with nothing to show for it.
1098 const AreaConfig &edits = this->area_edits_;
1099 if (std::isnan(edits.x_min))
1100 this->area_x_min_ = area.x_min;
1101 if (std::isnan(edits.x_max))
1102 this->area_x_max_ = area.x_max;
1103 if (std::isnan(edits.y_min))
1104 this->area_y_min_ = area.y_min;
1105 if (std::isnan(edits.y_max))
1106 this->area_y_max_ = area.y_max;
1107 if (std::isnan(edits.z_min))
1108 this->area_z_min_ = area.z_min;
1109 if (std::isnan(edits.z_max))
1110 this->area_z_max_ = area.z_max;
1111 this->publish_area_numbers_();
1112}
1113
1114// The mirror, not the report: an axis a report was kept away from has to keep its
1115// displayed value too, or the entity and the value the next apply sends disagree.
1117#ifdef USE_NUMBER
1118 this->publish_number_clamped_(this->area_x_min_number_, this->area_x_min_);
1119 this->publish_number_clamped_(this->area_x_max_number_, this->area_x_max_);
1120 this->publish_number_clamped_(this->area_y_min_number_, this->area_y_min_);
1121 this->publish_number_clamped_(this->area_y_max_number_, this->area_y_max_);
1122 this->publish_number_clamped_(this->area_z_min_number_, this->area_z_min_);
1123 this->publish_number_clamped_(this->area_z_max_number_, this->area_z_max_);
1124#endif
1125}
1126
1128 if (area_id >= AREA_ID_COUNT)
1129 return;
1130 const AreaConfig &area = this->area_values_[area_id];
1131 // The edits belonged to the area being navigated away from.
1132 this->area_edits_ = AreaConfig{};
1133 this->update_area_numbers_(area);
1134}
1135
1136bool LD600XComponent::queue_area_config_(uint8_t area_id, const AreaConfig &desired) {
1137 // One frame carries all three pairs and cannot express a crossed one; the module
1138 // would keep a box nothing can ever be inside. Both callers arrive with the six
1139 // bounds resolved, so this is the last place that can say no -- and the return
1140 // value is how saying no reaches the caller, which must not then retire the edits
1141 // the user still has to fix.
1142 if (desired.x_min > desired.x_max || desired.y_min > desired.y_max || desired.z_min > desired.z_max) {
1143 ESP_LOGW(TAG, "Area %u not written, min above max", area_id);
1144 return false;
1145 }
1146 uint8_t data[AREA_CONFIG_LEN];
1147 put_le32(data, static_cast<uint32_t>(area_id));
1148 write_f32_le(data + 4, desired.x_min);
1149 write_f32_le(data + 8, desired.x_max);
1150 write_f32_le(data + 12, desired.y_min);
1151 write_f32_le(data + 16, desired.y_max);
1152 write_f32_le(data + 20, desired.z_min);
1153 write_f32_le(data + 24, desired.z_max);
1154
1155 if (!this->queue_command_(TYPE_SET_AREA, data, sizeof(data))) {
1156 // Nothing is on its way, so the cache must not claim these bounds, the ack
1157 // refresh must not be armed for an ack that cannot come, and the values stay
1158 // the user's unsent edit.
1159 return false;
1160 }
1161 this->area_write_in_flight_ = true;
1162
1163 AreaConfig &store = this->area_values_[area_id];
1164 store = desired;
1165 // The six numbers show one area at a time, and a deferred apply can land here for
1166 // an area the user has navigated away from. Same question handle_area_report_
1167 // asks before it touches them.
1168 const uint8_t selected_id = this->area_id_set_ ? this->area_id_ : AREA_ID_DEFAULT;
1169 if (area_id == selected_id) {
1170 this->update_area_numbers_(store);
1171 }
1172 return true;
1173}
1174
1175void LD600XComponent::try_apply_pending_area_(uint8_t reported_kind) {
1176 if (!this->deferred_apply_pending_) {
1177 return;
1178 }
1179 if (this->pending_area_id_ >= AREA_ID_COUNT) {
1180 this->deferred_apply_pending_ = false;
1181 return;
1182 }
1183 const uint8_t kind = this->pending_area_id_ / AREA_COUNT;
1184 AreaConfig desired = this->area_values_[this->pending_area_id_];
1185
1186 if (!std::isnan(this->pending_area_updates_.x_min))
1187 desired.x_min = this->pending_area_updates_.x_min;
1188 if (!std::isnan(this->pending_area_updates_.x_max))
1189 desired.x_max = this->pending_area_updates_.x_max;
1190 if (!std::isnan(this->pending_area_updates_.y_min))
1191 desired.y_min = this->pending_area_updates_.y_min;
1192 if (!std::isnan(this->pending_area_updates_.y_max))
1193 desired.y_max = this->pending_area_updates_.y_max;
1194 if (!std::isnan(this->pending_area_updates_.z_min))
1195 desired.z_min = this->pending_area_updates_.z_min;
1196 if (!std::isnan(this->pending_area_updates_.z_max))
1197 desired.z_max = this->pending_area_updates_.z_max;
1198
1199 if (std::isnan(desired.x_min) || std::isnan(desired.x_max) || std::isnan(desired.y_min) ||
1200 std::isnan(desired.y_max) || std::isnan(desired.z_min) || std::isnan(desired.z_max)) {
1201 // Only the report covering this area's half can still fill it in, and there is
1202 // exactly one of those per read. Once it has landed with a bound still unknown,
1203 // nothing further is coming and waiting means waiting forever.
1204 if (reported_kind == kind) {
1205 this->deferred_apply_pending_ = false;
1207 ESP_LOGW(TAG, "Dropping deferred area apply, area report incomplete");
1208 }
1209 return;
1210 }
1211
1212 const uint8_t area_id = this->pending_area_id_;
1213 this->deferred_apply_pending_ = false;
1214 if (!this->queue_area_config_(area_id, desired)) {
1215 // Nothing was queued, so this is a drop like the other two: hand the staged
1216 // values back rather than leaving them with no ledger to protect them.
1218 }
1219}
1220
1222#ifdef USE_SELECT
1223 if (this->area_id_select_ == nullptr) {
1224 return;
1225 }
1226 this->area_id_pref_ = this->area_id_select_->make_entity_preference<uint8_t>();
1227 this->area_id_pref_initialized_ = true;
1228
1229 uint8_t value = 0;
1230 if (!this->area_id_pref_.load(&value) || value >= AREA_ID_COUNT) {
1231 // No stored selection. The numbers are about to display this area either way,
1232 // so select it for real: a displayed area that apply_area then refuses to write
1233 // is the one combination the user cannot make sense of.
1234 value = AREA_ID_DEFAULT;
1235 }
1236 this->area_id_select_->publish_state(value);
1237 this->area_id_ = value;
1238 this->area_id_set_ = true;
1239 this->update_area_numbers_for_id_(value);
1240#endif
1241}
1242
1244#ifdef USE_SELECT
1245 if (!this->area_id_pref_initialized_) {
1246 return;
1247 }
1248 this->area_id_pref_.save(&value);
1249#endif
1250}
1251
1253#ifdef USE_TEXT_SENSOR
1254 if (this->ota_version_text_sensor_ == nullptr) {
1255 return;
1256 }
1257 this->version_pref_ = this->ota_version_text_sensor_->make_entity_preference<VersionPref>();
1258 this->version_pref_initialized_ = true;
1259
1260 VersionPref pref{};
1261 if (this->version_pref_.load(&pref) && pref.value[0] != '\0') {
1262 pref.value[sizeof(pref.value) - 1] = '\0';
1263 this->ota_version_text_sensor_->publish_state(pref.value);
1264 }
1265#endif
1266}
1267
1269#ifdef USE_TEXT_SENSOR
1270 if (!this->version_pref_initialized_) {
1271 return;
1272 }
1273 VersionPref pref{};
1274 std::strncpy(pref.value, value, sizeof(pref.value) - 1);
1275 pref.value[sizeof(pref.value) - 1] = '\0';
1276 this->version_pref_.save(&pref);
1277#endif
1278}
1279
1280#ifdef USE_SENSOR
1282 if (!this->last_target_presence_[index]) {
1283 return;
1284 }
1285 TargetSensors &target = this->targets_[index];
1286 PUBLISH_STATE(target.x, NAN);
1287 PUBLISH_STATE(target.y, NAN);
1288 PUBLISH_STATE(target.z, NAN);
1289 PUBLISH_STATE(target.dop_idx, NAN);
1290 // The slot is free: the next person's id is new even when it repeats this one.
1292}
1293#endif
1294
1296 // The staged values become an unsent edit again, but only for the user who is
1297 // still looking at the area they were staged for; anyone else's ledger belongs to
1298 // the area they are on now.
1299 const uint8_t selected_id = this->area_id_set_ ? this->area_id_ : AREA_ID_DEFAULT;
1300 if (this->pending_area_id_ != selected_id) {
1301 return;
1302 }
1303 // Axis by axis rather than a whole-struct assignment: the user can have edited
1304 // another bound while the deferral was in flight, and that edit is newer than
1305 // anything the deferral staged. Assigning over the ledger would drop it back to
1306 // NaN and let the next report take the value away. A live edit wins; only an axis
1307 // with nothing in the ledger takes its staged value back.
1308 //
1309 // The mirror moves with the ledger, because on the report path handle_area_report_
1310 // ran update_area_numbers_ before the replay, with the ledger still empty -- so the
1311 // mirror already holds the module's bounds and both the entities and the next apply
1312 // would build on them. On the timeout path no report arrived, the mirror still
1313 // holds the staged values, and this is an identity.
1314 const AreaConfig &staged = this->pending_area_updates_;
1315 if (std::isnan(this->area_edits_.x_min) && !std::isnan(staged.x_min)) {
1316 this->area_edits_.x_min = staged.x_min;
1317 this->area_x_min_ = staged.x_min;
1318 }
1319 if (std::isnan(this->area_edits_.x_max) && !std::isnan(staged.x_max)) {
1320 this->area_edits_.x_max = staged.x_max;
1321 this->area_x_max_ = staged.x_max;
1322 }
1323 if (std::isnan(this->area_edits_.y_min) && !std::isnan(staged.y_min)) {
1324 this->area_edits_.y_min = staged.y_min;
1325 this->area_y_min_ = staged.y_min;
1326 }
1327 if (std::isnan(this->area_edits_.y_max) && !std::isnan(staged.y_max)) {
1328 this->area_edits_.y_max = staged.y_max;
1329 this->area_y_max_ = staged.y_max;
1330 }
1331 if (std::isnan(this->area_edits_.z_min) && !std::isnan(staged.z_min)) {
1332 this->area_edits_.z_min = staged.z_min;
1333 this->area_z_min_ = staged.z_min;
1334 }
1335 if (std::isnan(this->area_edits_.z_max) && !std::isnan(staged.z_max)) {
1336 this->area_edits_.z_max = staged.z_max;
1337 this->area_z_max_ = staged.z_max;
1338 }
1339 this->publish_area_numbers_();
1340}
1341
1343 if (!this->area_presence_any_) {
1344 return;
1345 }
1346 // Nothing else corrects this: 0x0A0A carries no period the protocol states and no
1347 // command stops it, so the module going unattended is the only moment the
1348 // component can know a stored "occupied" has stopped being true.
1349 this->area_presence_any_ = false;
1350#ifdef USE_BINARY_SENSOR
1351 for (uint8_t i = 0; i < AREA_COUNT; i++) {
1352 PUBLISH_STATE(this->area_presence_[i], false);
1353 }
1354 const bool presence = this->target_presence_any_ || this->area_presence_any_;
1355 PUBLISH_STATE(this->presence_binary_sensor_, presence);
1356#endif
1357}
1358
1360 // Nothing corrects any of this until the stream comes back. The slot table goes
1361 // with it: slots key on cluster ids, which only track a person while reports are
1362 // arriving, and the room can empty and refill across the gap -- so the next
1363 // report starts from an empty table and fills slots in wire order, rather than
1364 // handing one back to whoever last held that id.
1365 for (uint8_t i = 0; i < LD600X_MAX_TARGETS; i++) {
1366#ifdef USE_SENSOR
1367 this->clear_target_slot_(i);
1368 this->last_target_presence_[i] = false;
1369#endif
1370 if (this->slot_occupied_[i]) {
1371 this->slot_occupied_[i] = false;
1372#ifdef USE_BINARY_SENSOR
1373 PUBLISH_STATE(this->target_presence_[i], false);
1374#endif
1375 }
1376 }
1377#ifdef USE_SENSOR
1378 this->target_count_sensor_.publish_state_unknown();
1379#endif
1380 if (this->target_presence_any_) {
1381 this->target_presence_any_ = false;
1382#ifdef USE_BINARY_SENSOR
1383 bool presence = this->target_presence_any_ || this->area_presence_any_;
1384 PUBLISH_STATE(this->presence_binary_sensor_, presence);
1385#endif
1386 this->on_presence_update();
1387 }
1388}
1389
1390#ifdef USE_SWITCH
1392 if (entity == this->point_cloud_switch_) {
1393 if (!this->send_control_command_(state ? CMD_POINT_CLOUD_ON : CMD_POINT_CLOUD_OFF))
1394 return false;
1396#ifdef USE_SENSOR
1397 // The count only moves while the stream runs, so the last one would stand as
1398 // a live reading. The dedup sentinel is cleared with it: the same count is
1399 // new again when the stream comes back.
1400 if (!state)
1401 this->point_count_sensor_.publish_state_unknown();
1402#endif
1403 } else { // Only registered entities call this, so the last one needs no compare
1404 if (!this->send_control_command_(state ? CMD_TARGET_DISPLAY_ON : CMD_TARGET_DISPLAY_OFF))
1405 return false;
1407 if (!state) {
1408 // Every target entity is fed by the reports this just stopped.
1409 this->clear_target_state_();
1410 }
1411 }
1412 return true;
1413}
1414#endif
1415
1416#ifdef USE_BUTTON
1418 switch (kind) {
1419 case BUTTON_APPLY_AREA:
1420 this->apply_area_config_();
1421 break;
1423 this->send_control_command_(CMD_AUTO_INTERFERENCE);
1424 // The module recomputes the interference areas without reporting them.
1425 this->send_control_command_(CMD_GET_AREAS);
1426 break;
1427 case BUTTON_GET_AREAS:
1428 this->send_control_command_(CMD_GET_AREAS);
1429 break;
1431 this->send_control_command_(CMD_CLEAR_INTERFERENCE);
1432 // The module rewrites the areas but does not report them, so ask for the new geometry the
1433 // way the apply_area ack path does; the queue keeps it behind the command above.
1434 this->send_control_command_(CMD_GET_AREAS);
1435 break;
1437 this->send_control_command_(CMD_RESET_DETECTION_AREA);
1438 this->send_control_command_(CMD_GET_AREAS);
1439 break;
1440 case BUTTON_GET_DELAY:
1441 this->send_control_command_(CMD_GET_DELAY);
1442 break;
1444 this->send_control_command_(CMD_GET_SENSITIVITY);
1445 break;
1447 this->send_control_command_(CMD_GET_TRIGGER);
1448 break;
1449 case BUTTON_GET_Z_RANGE:
1450 this->send_control_command_(CMD_GET_Z_RANGE);
1451 break;
1453 this->send_control_command_(CMD_GET_INSTALLATION);
1454 break;
1456 this->send_control_command_(CMD_GET_MODE);
1457 break;
1459 this->send_control_command_(CMD_GET_LOW_POWER_SLEEP);
1460 break;
1462 this->send_control_command_(CMD_RESET_UNATTENDED);
1463 break;
1464 default:
1465 ESP_LOGW(TAG, "Unknown %s kind %u", LOG_STR_LITERAL("button"), kind);
1466 break;
1467 }
1468}
1469#endif // USE_BUTTON
1470
1471} // namespace esphome::ld600x
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void mark_failed()
Mark this component as failed.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
Definition component.cpp:96
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
bool has_state() const
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:2396
T * allocate(size_t n)
Definition helpers.h:2423
void init(uint8_t *buffer, uint16_t capacity)
static constexpr uint8_t CMD_MAX_RETRIES
Definition ld600x.h:315
bool queue_u32_setting_(uint16_t type, float value)
Definition ld600x.cpp:967
PendingCommand active_command_
Definition ld600x.h:327
static constexpr uint32_t CMD_ACK_TIMEOUT_MS
Definition ld600x.h:310
void update_area_numbers_for_id_(uint8_t area_id)
Definition ld600x.cpp:1127
std::array< AreaConfig, AREA_COUNT *LD600X_AREA_KINDS > area_values_
Definition ld600x.h:360
bool queue_area_config_(uint8_t area_id, const AreaConfig &desired)
Definition ld600x.cpp:1136
std::array< int32_t, LD600X_MAX_TARGETS > slot_cluster_
Definition ld600x.h:365
bool send_z_range_(float z_min, float z_max)
Definition ld600x.cpp:949
void handle_sensitivity_report_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:690
void handle_z_range_report_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:716
virtual bool set_switch_state(switch_::Switch *entity, bool state)
Definition ld600x.cpp:1391
void write_frame_(uint16_t type, const uint8_t *data, uint8_t len, bool track)
Definition ld600x.cpp:924
virtual void press_button(uint8_t kind)
Definition ld600x.cpp:1417
void handle_low_power_sleep_report_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:742
virtual bool model_wants_target_stream() const
Definition ld600x.h:216
static constexpr uint32_t AREA_REFRESH_TIMEOUT_ID
Definition ld600x.h:320
std::array< bool, LD600X_MAX_TARGETS > slot_occupied_
Definition ld600x.h:366
void handle_trigger_speed_report_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:703
std::array< bool, LD600X_MAX_TARGETS > last_target_presence_
Definition ld600x.h:381
std::array< AreaSensors, AREA_COUNT *LD600X_AREA_KINDS > areas_
Definition ld600x.h:285
virtual bool defer_frame_write(uint16_t type, const uint8_t *data, uint8_t len, bool track)
Definition ld600x.h:221
void clear_target_slot_(uint8_t index)
Definition ld600x.cpp:1281
bool queue_command_(uint16_t type, const uint8_t *data, uint8_t len)
Definition ld600x.cpp:799
void handle_area_presence_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:622
static constexpr uint32_t STALE_ACK_MAX_AGE_MS
Definition ld600x.h:322
void update_area_numbers_(const AreaConfig &area)
Definition ld600x.cpp:1094
void handle_target_report_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:507
void try_apply_pending_area_(uint8_t reported_kind)
Definition ld600x.cpp:1175
void handle_version_report_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:778
void handle_point_cloud_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:604
void publish_number_clamped_(number::Number *number, float value)
Definition ld600x.cpp:752
virtual bool handle_model_report(uint16_t type, const uint8_t *data, uint16_t len)
Definition ld600x.h:214
StaticRingBuffer< PendingCommand, CMD_QUEUE_SIZE > cmd_queue_
Definition ld600x.h:324
binary_sensor::BinarySensor * sensor
Definition ld600x.h:152
std::array< binary_sensor::BinarySensor *, AREA_COUNT > area_presence_
Definition ld600x.h:289
void handle_installation_report_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:729
virtual void on_presence_update()
Definition ld600x.h:218
std::array< TargetSensors, LD600X_MAX_TARGETS > targets_
Definition ld600x.h:284
void handle_area_report_(uint8_t kind, const uint8_t *data, uint16_t len)
Definition ld600x.cpp:644
static constexpr uint32_t CMD_FIRST_ACK_TIMEOUT_MS
Definition ld600x.h:312
void handle_frame_(uint16_t type, const uint8_t *data, uint16_t len)
Definition ld600x.cpp:414
virtual void dump_model_config()
Definition ld600x.h:223
ESPPreferenceObject version_pref_
Definition ld600x.h:292
ESPPreferenceObject area_id_pref_
Definition ld600x.h:296
void send_command_internal_(uint16_t type, const uint8_t *data, uint8_t len, bool track)
Definition ld600x.cpp:907
bool send_control_command_(uint32_t command)
Definition ld600x.cpp:943
virtual SUB_TEXT_SENSOR(work_mode) SUB_TEXT_SENSOR(ota_version) SUB_NUMBER(hold_delay) SUB_NUMBER(z_min) SUB_NUMBER(z_max) SUB_NUMBER(low_power_sleep) SUB_NUMBER(area_x_min) SUB_NUMBER(area_x_max) SUB_NUMBER(area_y_min) SUB_NUMBER(area_y_max) SUB_NUMBER(area_z_min) SUB_NUMBER(area_z_max) SUB_SELECT(sensitivity) SUB_SELECT(trigger_speed) SUB_SELECT(installation) SUB_SELECT(area_id) SUB_SWITCH(point_cloud) SUB_SWITCH(target_display) virtual bool set_number_value(number bool set_select_value(select::Select *entity, size_t index)
Definition ld600x.cpp:1078
static constexpr uint8_t CMD_QUEUE_SIZE
Definition ld600x.h:309
void handle_delay_report_(const uint8_t *data, uint16_t len)
Definition ld600x.cpp:681
static constexpr uint32_t MODULE_AWAKE_MS
Definition ld600x.h:314
void save_version_pref_(const char *value)
Definition ld600x.cpp:1268
void send_command_(uint16_t type, const uint8_t *data, uint8_t len)
Definition ld600x.cpp:903
void save_area_id_pref_(uint8_t value)
Definition ld600x.cpp:1243
Base-class for all numbers.
Definition number.h:29
void publish_state(float state)
Definition number.cpp:20
NumberTraits traits
Definition number.h:41
Base-class for all selects.
Definition select.h:28
Base class for all switches.
Definition switch.h:43
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
Definition uart.h:77
void write_array(const uint8_t *data, size_t len)
Definition uart.h:30
uint8_t type
bool state
Definition fan.h:2
unsigned count
Definition gif.cpp:51
uint32_t buffer
Definition gif.cpp:50
bool z
Definition msa3xx.h:1
uint16_t next_frame_id(uint16_t &counter)
void write_f32_le(uint8_t *data, float value)
PROGMEM_STRING_TABLE(ControlCommandNames, "auto_interference", "get_areas", "clear_interference", "reset_detection_area", "get_delay", "point_cloud_on", "point_cloud_off", "target_display_on", "target_display_off", "sensitivity_low", "sensitivity_medium", "sensitivity_high", "get_sensitivity", "trigger_slow", "trigger_medium", "trigger_fast", "get_trigger", "get_z_range", "install_top", "install_side", "get_installation", "low_power_on", "low_power_off", "get_mode", "get_low_power_sleep", "reset_unattended", "unknown")
@ AREA_KIND_DETECTION
Definition ld600x.h:48
@ AREA_KIND_INTERFERENCE
Definition ld600x.h:48
@ BUTTON_GET_LOW_POWER_MODE
Definition ld600x.h:70
@ BUTTON_CLEAR_INTERFERENCE
Definition ld600x.h:63
@ BUTTON_GET_Z_RANGE
Definition ld600x.h:68
@ BUTTON_GET_TRIGGER_SPEED
Definition ld600x.h:67
@ BUTTON_AUTO_INTERFERENCE
Definition ld600x.h:61
@ BUTTON_GET_LOW_POWER_SLEEP_TIME
Definition ld600x.h:71
@ BUTTON_RESET_UNATTENDED
Definition ld600x.h:72
@ BUTTON_RESET_DETECTION_AREA
Definition ld600x.h:64
@ BUTTON_GET_INSTALLATION
Definition ld600x.h:69
@ BUTTON_GET_SENSITIVITY
Definition ld600x.h:66
@ BUTTON_APPLY_AREA
Definition ld600x.h:60
std::array< sensor::Sensor *, AREA_AXIS_COUNT > AreaSensors
Definition ld600x.h:86
float read_f32_le(const uint8_t *data)
size_t encode_frame(uint16_t frame_id, uint16_t type, const uint8_t *data, uint16_t len, uint8_t *out)
uint32_t value
Definition hal.cpp:41
const void size_t len
Definition hal.h:68
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
Definition helpers.h:1084
size_t size_t pos
Definition helpers.h:1333
constexpr uint8_t * put_le32(uint8_t *dst, uint32_t value)
Definition helpers.h:1135
void HOT delay(uint32_t ms)
Definition hal.cpp:85
Application App
Global storage of Application pointer - only one Application can exist.
uint16_t uint16_t & capacity
Definition helpers.cpp:34
uint8_t progmem_read_byte(const uint8_t *addr)
Definition hal.h:51
static void uint32_t
std::array< uint8_t, CMD_MAX_DATA_LEN > data
Definition ld600x.h:230
sensor::Sensor * dop_idx
Definition ld600x.h:80
sensor::SensorWithDedup< int32_t > cluster_id
Definition ld600x.h:82
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6