18#define TAG (this->log_tag_)
20static constexpr uint32_t SETUP_DELAY_MS = 100;
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;
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;
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;
44static constexpr uint16_t TYPE_QUERY_VERSION = 0xFFFF;
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;
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;
73static constexpr uint32_t CMD_LOW_POWER_ON = 0x16;
74static constexpr uint32_t CMD_LOW_POWER_OFF = 0x17;
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;
81static constexpr uint16_t TARGET_DATA_LEN = 20;
82static constexpr uint16_t AREA_DATA_LEN = 24;
83static constexpr uint16_t AREA_CONFIG_LEN = 28;
84static constexpr uint16_t AREA_PRESENCE_ENTRY_LEN = 4;
86static constexpr uint8_t AREA_ID_DEFAULT = 4;
88static constexpr uint8_t VERSION_QUERY_DATA[] = {0x01, 0x01, 0x00, 0x00};
90#ifdef ESPHOME_LOG_HAS_VERBOSE
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");
101static const LogString *control_command_name(
uint32_t command) {
104 return ControlCommandNames::get_log_str(idx < ControlCommandNames::COUNT ? idx : ControlCommandNames::LAST_INDEX,
105 ControlCommandNames::LAST_INDEX);
108static const LogString *frame_type_name(uint16_t
type) {
111 return LOG_STR(
"control");
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");
147 return LOG_STR(
"unknown");
151static bool is_expected_control_report(
uint32_t command, uint16_t
type) {
154 return type == TYPE_REPORT_INTERFERENCE_AREAS ||
type == TYPE_REPORT_DETECTION_AREAS;
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:
168 return type == TYPE_REPORT_MODE;
169 case CMD_GET_LOW_POWER_SLEEP:
170 return type == TYPE_REPORT_LOW_POWER_SLEEP;
179 bool point_cloud_configured =
false;
181 point_cloud_configured = point_cloud_configured || this->point_count_sensor_.has_sensor();
184 point_cloud_configured = point_cloud_configured || this->point_cloud_switch_ !=
nullptr;
186 const uint16_t
capacity = point_cloud_configured ? DEFAULT_MAX_DATA_LEN_POINT_CLOUD : DEFAULT_MAX_DATA_LEN;
191 this->
mark_failed(LOG_STR(
"Failed to allocate frame buffer"));
197 bool want_target_stream =
false;
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;
210#ifdef USE_BINARY_SENSOR
211 want_target_stream = want_target_stream || this->presence_binary_sensor_ !=
nullptr;
212 if (!want_target_stream) {
215 want_target_stream =
true;
224 bool target_display_controlled =
false;
226 if (this->target_display_switch_ !=
nullptr) {
227 target_display_controlled =
true;
229 this->target_display_switch_->restore(
true);
232 if (!target_display_controlled) {
237 if (want_target_stream) {
242 bool point_cloud_controlled =
false;
244 if (this->point_cloud_switch_ !=
nullptr) {
245 point_cloud_controlled =
true;
246 this->point_cloud_switch_->restore(
false);
249 if (!point_cloud_controlled) {
252 bool want_point_cloud =
false;
254 want_point_cloud = this->point_count_sensor_.has_sensor();
261 if (this->sensitivity_select_ !=
nullptr) {
264 if (this->trigger_speed_select_ !=
nullptr) {
267 if (this->installation_select_ !=
nullptr) {
272 if (this->z_min_number_ !=
nullptr || this->z_max_number_ !=
nullptr) {
275 if (this->low_power_sleep_number_ !=
nullptr) {
278 if (this->hold_delay_number_ !=
nullptr) {
282 bool want_area_report =
false;
284 for (
const auto &area : this->
areas_) {
286 want_area_report = want_area_report ||
sensor !=
nullptr;
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;
296 if (want_area_report) {
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));
314 char model[16] =
"HLK-";
316 for (
const auto *p =
reinterpret_cast<const uint8_t *
>(this->
log_tag_); pos <
sizeof(model) - 1; p++) {
320 model[
pos++] =
static_cast<char>(std::toupper(c));
325 " Max data length: %u",
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);
337 for (uint8_t i = 0; i < AREA_COUNT; i++) {
346 for (uint8_t i = 0; i < AREA_COUNT; i++) {
355#if LD600X_AREA_KINDS > 2
356 for (uint8_t i = 0; i < AREA_COUNT; i++) {
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++) {
372 for (uint8_t i = 0; i < AREA_COUNT; i++) {
373 LOG_BINARY_SENSOR(
" ",
"Detection Area Presence", this->
area_presence_[i]);
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_);
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_);
393 LOG_SWITCH(
" ",
"Point Cloud", this->point_cloud_switch_);
394 LOG_SWITCH(
" ",
"Target Display", this->target_display_switch_);
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_);
423 ESP_LOGV(TAG,
"Ignoring ACK for command 0x%04X from an earlier attempt (module frame 0x%04X)",
type,
428 ESP_LOGV(TAG,
"ACK for command 0x%04X (module frame 0x%04X)",
type, this->
parser_.
id());
446#ifdef ESPHOME_LOG_HAS_VERBOSE
447 const uint32_t active_control_command =
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);
461 case TYPE_REPORT_TARGET:
464 case TYPE_REPORT_POINT_CLOUD:
467 case TYPE_REPORT_AREA_PRESENCE:
470 case TYPE_REPORT_INTERFERENCE_AREAS:
473 case TYPE_REPORT_DETECTION_AREAS:
476#if LD600X_AREA_KINDS > 2
477 case TYPE_REPORT_DWELL_AREAS:
481 case TYPE_REPORT_DELAY:
484 case TYPE_REPORT_SENSITIVITY:
487 case TYPE_REPORT_TRIGGER:
490 case TYPE_REPORT_Z_RANGE:
493 case TYPE_REPORT_INSTALLATION:
496 case TYPE_REPORT_LOW_POWER_SLEEP:
499 case TYPE_QUERY_VERSION:
521 uint8_t
count =
static_cast<uint8_t
>(std::min<uint32_t>(reported, LD600X_MAX_TARGETS));
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;
532 for (uint8_t i = 0; i <
count; i++) {
533 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
536 wire_placed[i] =
true;
542 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
547 for (uint8_t i = 0; i <
count; i++) {
548 if (wire_placed[i]) {
551 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
562 this->target_count_sensor_.publish_state_if_not_dup(reported);
566#ifdef USE_BINARY_SENSOR
568 PUBLISH_STATE(this->presence_binary_sensor_, presence);
572 for (uint8_t i = 0; i < LD600X_MAX_TARGETS; i++) {
576 uint16_t offset = 4 + (slot_wire[i] * TARGET_DATA_LEN);
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));
594#ifdef USE_BINARY_SENSOR
623 const uint16_t needed = AREA_COUNT * AREA_PRESENCE_ENTRY_LEN;
628 for (uint8_t i = 0; i < AREA_COUNT; i++) {
630 bool present =
state != 0;
632#ifdef USE_BINARY_SENSOR
637#ifdef USE_BINARY_SENSOR
639 PUBLISH_STATE(this->presence_binary_sensor_, presence);
645 uint16_t needed = AREA_COUNT * AREA_DATA_LEN;
649 for (uint8_t i = 0; i < AREA_COUNT; i++) {
650 uint16_t offset = i * AREA_DATA_LEN;
660 const float values[
AREA_AXIS_COUNT] = {x_min, x_max, y_min, y_max, z_min, z_max};
662 PUBLISH_STATE(area[axis], values[axis]);
674 if (selected_id == area_index(kind, i)) {
694 if (this->sensitivity_select_ ==
nullptr)
696 uint8_t
value = data[0];
698 this->sensitivity_select_->publish_state(
value);
707 if (this->trigger_speed_select_ ==
nullptr)
709 uint8_t
value = data[0];
711 this->trigger_speed_select_->publish_state(
value);
733 if (this->installation_select_ ==
nullptr)
735 uint8_t
value = data[0];
737 this->installation_select_->publish_state(
value);
753 if (number ==
nullptr)
755 if (std::isnan(
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);
781#ifdef USE_TEXT_SENSOR
782 if (this->ota_version_text_sensor_ ==
nullptr)
784 uint8_t project = data[0];
785 uint8_t major = data[1];
786 uint8_t minor = data[2];
787 uint8_t patch = data[3];
790 std::snprintf(buf,
sizeof(buf),
"%u.%u.%u", major, minor, patch);
792 std::snprintf(buf,
sizeof(buf),
"p%u %u.%u.%u", project, major, minor, patch);
794 this->ota_version_text_sensor_->publish_state(buf);
800 if (
len > CMD_MAX_DATA_LEN) {
801 ESP_LOGW(TAG,
"Command data too large: %u",
len);
805 ESP_LOGW(TAG,
"Command queue full, dropping command 0x%04X",
type);
812 if (
len > 0 && data !=
nullptr) {
813 std::memcpy(cmd.
data.data(), data,
len);
827 const uint32_t active_control_command =
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,
839 ESP_LOGV(TAG,
"Retrying command 0x%04X, %u attempt(s) remaining", this->
active_command_.
type,
840 this->retries_left_);
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);
864 ESP_LOGW(TAG,
"Area read timed out, dropping deferred area apply");
873 this->
stale_ack_count_ =
static_cast<uint8_t
>(std::min<uint16_t>(owed, 255));
908 if (
len > CMD_MAX_DATA_LEN) {
909 ESP_LOGW(TAG,
"Command data too large: %u",
len);
927 uint8_t frame[TF_FRAME_OVERHEAD + CMD_MAX_DATA_LEN];
951 if (std::isnan(z_min) || std::isnan(z_max)) {
952 ESP_LOGW(TAG,
"Z range not written, other bound unknown");
957 ESP_LOGW(TAG,
"Z range not written, min above max");
963 return this->
queue_command_(TYPE_SET_Z_RANGE, data,
sizeof(data));
971 ESP_LOGW(TAG,
"Invalid number value: %f",
value);
982 ESP_LOGW(TAG,
"Area ID not selected; ignoring apply");
985 if (this->
area_id_ >= AREA_ID_COUNT) {
986 ESP_LOGW(TAG,
"Invalid area id: %u", this->
area_id_);
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)) {
1009 ESP_LOGW(TAG,
"Area read not queued; area config left unapplied");
1027 ESP_LOGI(TAG,
"Area config incomplete; requesting current areas before applying");
1039 if (entity == this->hold_delay_number_)
1041 if (entity == this->low_power_sleep_number_)
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;
1054 if (entity == this->area_x_min_number_) {
1057 }
else if (entity == this->area_x_max_number_) {
1060 }
else if (entity == this->area_y_min_number_) {
1063 }
else if (entity == this->area_y_max_number_) {
1066 }
else if (entity == this->area_z_min_number_) {
1079 if (entity == this->sensitivity_select_)
1081 if (entity == this->trigger_speed_select_)
1083 if (entity == this->installation_select_)
1086 this->
area_id_ =
static_cast<uint8_t
>(index);
1099 if (std::isnan(edits.
x_min))
1101 if (std::isnan(edits.
x_max))
1103 if (std::isnan(edits.
y_min))
1105 if (std::isnan(edits.
y_max))
1107 if (std::isnan(edits.
z_min))
1109 if (std::isnan(edits.
z_max))
1128 if (area_id >= AREA_ID_COUNT)
1143 ESP_LOGW(TAG,
"Area %u not written, min above max", area_id);
1146 uint8_t data[AREA_CONFIG_LEN];
1169 if (area_id == selected_id) {
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)) {
1204 if (reported_kind == kind) {
1207 ESP_LOGW(TAG,
"Dropping deferred area apply, area report incomplete");
1223 if (this->area_id_select_ ==
nullptr) {
1226 this->
area_id_pref_ = this->area_id_select_->make_entity_preference<uint8_t>();
1234 value = AREA_ID_DEFAULT;
1236 this->area_id_select_->publish_state(
value);
1253#ifdef USE_TEXT_SENSOR
1254 if (this->ota_version_text_sensor_ ==
nullptr) {
1262 pref.value[
sizeof(pref.value) - 1] =
'\0';
1263 this->ota_version_text_sensor_->publish_state(pref.value);
1269#ifdef USE_TEXT_SENSOR
1274 std::strncpy(pref.value,
value,
sizeof(pref.value) - 1);
1275 pref.value[
sizeof(pref.value) - 1] =
'\0';
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);
1350#ifdef USE_BINARY_SENSOR
1351 for (uint8_t i = 0; i < AREA_COUNT; i++) {
1355 PUBLISH_STATE(this->presence_binary_sensor_, presence);
1365 for (uint8_t i = 0; i < LD600X_MAX_TARGETS; i++) {
1372#ifdef USE_BINARY_SENSOR
1378 this->target_count_sensor_.publish_state_unknown();
1382#ifdef USE_BINARY_SENSOR
1384 PUBLISH_STATE(this->presence_binary_sensor_, presence);
1392 if (entity == this->point_cloud_switch_) {
1401 this->point_count_sensor_.publish_state_unknown();
1465 ESP_LOGW(TAG,
"Unknown %s kind %u", LOG_STR_LITERAL(
"button"), kind);
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.
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
An STL allocator that uses SPI or internal RAM.
uint16_t capacity() const
void init(uint8_t *buffer, uint16_t capacity)
static constexpr uint8_t CMD_MAX_RETRIES
void init_area_id_pref_()
bool queue_u32_setting_(uint16_t type, float value)
bool version_pref_initialized_
void restore_deferred_edits_()
PendingCommand active_command_
void dump_config() override
static constexpr uint32_t CMD_ACK_TIMEOUT_MS
void update_area_numbers_for_id_(uint8_t area_id)
void clear_target_state_()
std::array< AreaConfig, AREA_COUNT *LD600X_AREA_KINDS > area_values_
bool queue_area_config_(uint8_t area_id, const AreaConfig &desired)
std::array< int32_t, LD600X_MAX_TARGETS > slot_cluster_
bool send_z_range_(float z_min, float z_max)
void handle_sensitivity_report_(const uint8_t *data, uint16_t len)
void handle_z_range_report_(const uint8_t *data, uint16_t len)
virtual bool set_switch_state(switch_::Switch *entity, bool state)
AreaConfig pending_area_updates_
void write_frame_(uint16_t type, const uint8_t *data, uint8_t len, bool track)
virtual void press_button(uint8_t kind)
void handle_low_power_sleep_report_(const uint8_t *data, uint16_t len)
bool point_cloud_enabled_
virtual bool model_wants_target_stream() const
uint32_t last_traffic_ms_
bool target_display_enabled_
static constexpr uint32_t AREA_REFRESH_TIMEOUT_ID
std::array< bool, LD600X_MAX_TARGETS > slot_occupied_
void handle_trigger_speed_report_(const uint8_t *data, uint16_t len)
std::array< bool, LD600X_MAX_TARGETS > last_target_presence_
std::array< AreaSensors, AREA_COUNT *LD600X_AREA_KINDS > areas_
virtual bool defer_frame_write(uint16_t type, const uint8_t *data, uint8_t len, bool track)
void clear_area_presence_()
void clear_target_slot_(uint8_t index)
bool queue_command_(uint16_t type, const uint8_t *data, uint8_t len)
bool deferred_apply_pending_
bool area_id_pref_initialized_
void handle_area_presence_(const uint8_t *data, uint16_t len)
static constexpr uint32_t STALE_ACK_MAX_AGE_MS
void update_area_numbers_(const AreaConfig &area)
void handle_target_report_(const uint8_t *data, uint16_t len)
void process_command_queue_()
void try_apply_pending_area_(uint8_t reported_kind)
bool target_presence_any_
void handle_version_report_(const uint8_t *data, uint16_t len)
void handle_point_cloud_(const uint8_t *data, uint16_t len)
void publish_number_clamped_(number::Number *number, float value)
void publish_area_numbers_()
virtual bool handle_model_report(uint16_t type, const uint8_t *data, uint16_t len)
StaticRingBuffer< PendingCommand, CMD_QUEUE_SIZE > cmd_queue_
binary_sensor::BinarySensor * sensor
std::array< binary_sensor::BinarySensor *, AREA_COUNT > area_presence_
void handle_installation_report_(const uint8_t *data, uint16_t len)
virtual void on_presence_update()
std::array< TargetSensors, LD600X_MAX_TARGETS > targets_
this target_presence_[target]
void handle_area_report_(uint8_t kind, const uint8_t *data, uint16_t len)
static constexpr uint32_t CMD_FIRST_ACK_TIMEOUT_MS
void handle_frame_(uint16_t type, const uint8_t *data, uint16_t len)
virtual void dump_model_config()
ESPPreferenceObject version_pref_
void apply_area_config_()
ESPPreferenceObject area_id_pref_
void send_command_internal_(uint16_t type, const uint8_t *data, uint8_t len, bool track)
void init_version_pref_()
bool send_control_command_(uint32_t command)
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)
static constexpr uint8_t CMD_QUEUE_SIZE
void handle_delay_report_(const uint8_t *data, uint16_t len)
bool area_write_in_flight_
virtual void setup_model()
static constexpr uint32_t MODULE_AWAKE_MS
void save_version_pref_(const char *value)
void send_command_(uint16_t type, const uint8_t *data, uint8_t len)
void save_area_id_pref_(uint8_t value)
Base-class for all numbers.
void publish_state(float state)
float get_min_value() const
float get_max_value() const
Base-class for all selects.
void publish_state_unknown()
void publish_state_if_not_dup(T state)
Base class for all switches.
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
void write_array(const uint8_t *data, size_t len)
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")
@ BUTTON_GET_LOW_POWER_MODE
@ BUTTON_CLEAR_INTERFERENCE
@ BUTTON_GET_TRIGGER_SPEED
@ BUTTON_AUTO_INTERFERENCE
@ BUTTON_GET_LOW_POWER_SLEEP_TIME
@ BUTTON_RESET_UNATTENDED
@ BUTTON_RESET_DETECTION_AREA
@ BUTTON_GET_INSTALLATION
std::array< sensor::Sensor *, AREA_AXIS_COUNT > AreaSensors
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)
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...
constexpr uint8_t * put_le32(uint8_t *dst, uint32_t value)
void HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.
uint16_t uint16_t & capacity
uint8_t progmem_read_byte(const uint8_t *addr)
std::array< uint8_t, CMD_MAX_DATA_LEN > data
sensor::SensorWithDedup< int32_t > cluster_id