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