10 namespace dfrobot_sen0395 {
12 static const char *
const TAG =
"dfrobot_sen0395.commands";
19 if (message.rfind(
"is not recognized as a CLI command") != std::string::npos) {
20 ESP_LOGD(TAG,
"Command not recognized properly by sensor");
24 ESP_LOGD(TAG,
"Retrying...");
36 ESP_LOGD(TAG,
"Retrying...");
50 ESP_LOGD(TAG,
"Command timeout");
54 ESP_LOGD(TAG,
"Retrying...");
69 if (message.rfind(
"$JYBSS,0, , , *") != std::string::npos) {
71 this->
parent_->set_active(
true);
73 }
else if (message.rfind(
"$JYBSS,1, , , *") != std::string::npos) {
75 this->
parent_->set_active(
true);
88 if (message ==
"sensor stopped already") {
89 this->
parent_->set_active(
false);
90 ESP_LOGI(TAG,
"Stopped sensor (already stopped)");
92 }
else if (message ==
"sensor started already") {
93 this->
parent_->set_active(
true);
94 ESP_LOGI(TAG,
"Started sensor (already started)");
96 }
else if (message ==
"new parameter isn't save, can't startSensor") {
97 this->
parent_->set_active(
false);
98 ESP_LOGE(TAG,
"Can't start sensor! (Use SaveCfgCommand to save config first)");
100 }
else if (message ==
"Done") {
101 this->
parent_->set_active(this->power_on_);
102 if (this->power_on_) {
103 ESP_LOGI(TAG,
"Started sensor");
105 ESP_LOGI(TAG,
"Stopped sensor");
113 float min4,
float max4) {
115 if (min1 < 0 || max1 < 0) {
116 this->min1_ = min1 = 0;
117 this->max1_ = max1 = 0;
118 this->min2_ = min2 = this->max2_ = max2 = this->min3_ = min3 = this->max3_ = max3 = this->min4_ = min4 =
119 this->max4_ = max4 = -1;
121 ESP_LOGW(TAG,
"DetRangeCfgCommand invalid input parameters. Using range config 0 0.");
123 this->
cmd_ =
"detRangeCfg -1 0 0";
124 }
else if (min2 < 0 || max2 < 0) {
125 this->min1_ = min1 = round(min1 / 0.15) * 0.15;
126 this->max1_ = max1 = round(max1 / 0.15) * 0.15;
127 this->min2_ = min2 = this->max2_ = max2 = this->min3_ = min3 = this->max3_ = max3 = this->min4_ = min4 =
128 this->max4_ = max4 = -1;
130 this->
cmd_ =
str_sprintf(
"detRangeCfg -1 %.0f %.0f", min1 / 0.15, max1 / 0.15);
131 }
else if (min3 < 0 || max3 < 0) {
132 this->min1_ = min1 = round(min1 / 0.15) * 0.15;
133 this->max1_ = max1 = round(max1 / 0.15) * 0.15;
134 this->min2_ = min2 = round(min2 / 0.15) * 0.15;
135 this->max2_ = max2 = round(max2 / 0.15) * 0.15;
136 this->min3_ = min3 = this->max3_ = max3 = this->min4_ = min4 = this->max4_ = max4 = -1;
138 this->
cmd_ =
str_sprintf(
"detRangeCfg -1 %.0f %.0f %.0f %.0f", min1 / 0.15, max1 / 0.15, min2 / 0.15, max2 / 0.15);
139 }
else if (min4 < 0 || max4 < 0) {
140 this->min1_ = min1 = round(min1 / 0.15) * 0.15;
141 this->max1_ = max1 = round(max1 / 0.15) * 0.15;
142 this->min2_ = min2 = round(min2 / 0.15) * 0.15;
143 this->max2_ = max2 = round(max2 / 0.15) * 0.15;
144 this->min3_ = min3 = round(min3 / 0.15) * 0.15;
145 this->max3_ = max3 = round(max3 / 0.15) * 0.15;
146 this->min4_ = min4 = this->max4_ = max4 = -1;
149 "%.0f %.0f %.0f %.0f %.0f %.0f",
150 min1 / 0.15, max1 / 0.15, min2 / 0.15, max2 / 0.15, min3 / 0.15, max3 / 0.15);
152 this->min1_ = min1 = round(min1 / 0.15) * 0.15;
153 this->max1_ = max1 = round(max1 / 0.15) * 0.15;
154 this->min2_ = min2 = round(min2 / 0.15) * 0.15;
155 this->max2_ = max2 = round(max2 / 0.15) * 0.15;
156 this->min3_ = min3 = round(min3 / 0.15) * 0.15;
157 this->max3_ = max3 = round(max3 / 0.15) * 0.15;
158 this->min4_ = min4 = round(min4 / 0.15) * 0.15;
159 this->max4_ = max4 = round(max4 / 0.15) * 0.15;
162 "%.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f",
163 min1 / 0.15, max1 / 0.15, min2 / 0.15, max2 / 0.15, min3 / 0.15, max3 / 0.15, min4 / 0.15,
178 if (message ==
"sensor is not stopped") {
179 ESP_LOGE(TAG,
"Cannot configure range config. Sensor is not stopped!");
181 }
else if (message ==
"Done") {
182 ESP_LOGI(TAG,
"Updated detection area config:");
183 ESP_LOGI(TAG,
"Detection area 1 from %.02fm to %.02fm.", this->min1_, this->max1_);
184 if (this->min2_ >= 0 && this->max2_ >= 0) {
185 ESP_LOGI(TAG,
"Detection area 2 from %.02fm to %.02fm.", this->min2_, this->max2_);
187 if (this->min3_ >= 0 && this->max3_ >= 0) {
188 ESP_LOGI(TAG,
"Detection area 3 from %.02fm to %.02fm.", this->min3_, this->max3_);
190 if (this->min4_ >= 0 && this->max4_ >= 0) {
191 ESP_LOGI(TAG,
"Detection area 4 from %.02fm to %.02fm.", this->min4_, this->max4_);
193 ESP_LOGD(TAG,
"Used command: %s", this->
cmd_.c_str());
200 delay_after_detection = std::round(delay_after_detection / 0.025f) * 0.025f;
201 delay_after_disappear = std::round(delay_after_disappear / 0.025f) * 0.025f;
202 this->delay_after_detection_ =
clamp(delay_after_detection, 0.0f, 1638.375f);
203 this->delay_after_disappear_ =
clamp(delay_after_disappear, 0.0f, 1638.375f);
204 this->
cmd_ =
str_sprintf(
"setLatency %.03f %.03f", this->delay_after_detection_, this->delay_after_disappear_);
208 if (message ==
"sensor is not stopped") {
209 ESP_LOGE(TAG,
"Cannot configure output latency. Sensor is not stopped!");
211 }
else if (message ==
"Done") {
212 ESP_LOGI(TAG,
"Updated output latency config:");
213 ESP_LOGI(TAG,
"Signal that someone was detected is delayed by %.03f s.", this->delay_after_detection_);
214 ESP_LOGI(TAG,
"Signal that nobody is detected anymore is delayed by %.03f s.", this->delay_after_disappear_);
215 ESP_LOGD(TAG,
"Used command: %s", this->
cmd_.c_str());
222 if (message ==
"sensor is not stopped") {
223 ESP_LOGE(TAG,
"Cannot configure sensor startup behavior. Sensor is not stopped!");
225 }
else if (message ==
"Done") {
226 ESP_LOGI(TAG,
"Updated sensor startup behavior:");
228 this->
parent_->set_start_after_boot(
true);
229 ESP_LOGI(TAG,
"Sensor will start automatically after power-on.");
231 this->
parent_->set_start_after_boot(
false);
232 ESP_LOGI(TAG,
"Sensor needs to be started manually after power-on.");
234 ESP_LOGD(TAG,
"Used command: %s", this->
cmd_.c_str());
241 if (message ==
"sensor is not stopped") {
242 ESP_LOGE(TAG,
"Cannot factory reset. Sensor is not stopped!");
244 }
else if (message ==
"Done") {
245 ESP_LOGI(TAG,
"Sensor factory reset done.");
252 if (message ==
"leapMMW:/>") {
253 ESP_LOGI(TAG,
"Restarted sensor.");
260 if (message ==
"no parameter has changed") {
261 ESP_LOGI(TAG,
"Not saving config (no parameter changed).");
263 }
else if (message ==
"Done") {
264 ESP_LOGI(TAG,
"Saved config. Saving a lot may damage the sensor.");
271 if (message ==
"sensor is not stopped") {
272 ESP_LOGE(TAG,
"Cannot set led mode. Sensor is not stopped!");
274 }
else if (message ==
"Done") {
275 ESP_LOGI(TAG,
"Set led mode done.");
277 this->
parent_->set_led_active(
true);
278 ESP_LOGI(TAG,
"Sensor LED will blink.");
280 this->
parent_->set_led_active(
false);
281 ESP_LOGI(TAG,
"Turned off LED.");
283 ESP_LOGD(TAG,
"Used command: %s", this->
cmd_.c_str());
290 if (message ==
"sensor is not stopped") {
291 ESP_LOGE(TAG,
"Cannot set uart output mode. Sensor is not stopped!");
293 }
else if (message ==
"Done") {
294 ESP_LOGI(TAG,
"Set uart mode done.");
296 this->
parent_->set_uart_presence_active(
true);
297 ESP_LOGI(TAG,
"Presence information is sent via UART and GPIO.");
299 this->
parent_->set_uart_presence_active(
false);
300 ESP_LOGI(TAG,
"Presence information is only sent via GPIO.");
302 ESP_LOGD(TAG,
"Used command: %s", this->
cmd_.c_str());
309 if (message ==
"sensor is not stopped") {
310 ESP_LOGE(TAG,
"Cannot set sensitivity. Sensor is not stopped!");
312 }
else if (message ==
"Done") {
313 ESP_LOGI(TAG,
"Set sensitivity done. Set to value %d.", this->sensitivity_);
314 ESP_LOGD(TAG,
"Used command: %s", this->
cmd_.c_str());
uint8_t execute(DfrobotSen0395Component *parent) override
uint8_t on_message(std::string &message) override
uint8_t on_message(std::string &message) override
DfrobotSen0395Component * parent_
uint8_t on_message(std::string &message) override
uint8_t on_message(std::string &message) override
uint8_t on_message(std::string &message) override
DetRangeCfgCommand(float min1, float max1, float min2, float max2, float min3, float max3, float min4, float max4)
uint8_t on_message(std::string &message) override
uint8_t on_message(std::string &message) override
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
uint32_t IRAM_ATTR HOT millis()
virtual uint8_t execute(DfrobotSen0395Component *parent)
uint8_t send_cmd_(const char *cmd, uint32_t duration)
std::string str_sprintf(const char *fmt,...)
SetLatencyCommand(float delay_after_detection, float delay_after_disappear)
uint32_t cmd_duration_ms_
char read_buffer_[MMWAVE_READ_BUFFER_LENGTH]
uint8_t on_message(std::string &message) override
uint32_t ts_last_cmd_sent_
uint8_t on_message(std::string &message) override
void set_detected_(bool detected)
Implementation of SPI Controller mode.
virtual uint8_t on_message(std::string &message)=0
uint8_t on_message(std::string &message) override
uint8_t on_message(std::string &message) override