37 if (this->
buffer_.back() ==
static_cast<char>(ASCII_NBSP)) {
44 if (this->
buffer_.back() ==
static_cast<char>(ASCII_CR) || this->buffer_.length() >= MAX_DATA_LENGTH_BYTES) {
45 ESP_LOGV(TAG,
"Read from serial: %s", this->
buffer_.c_str());
47 size_t rpos = this->
buffer_.find(
static_cast<char>(ASCII_CR));
49 if (this->
buffer_.length() <= MAX_DATA_LENGTH_BYTES && this->buffer_[0] ==
'R' && rpos != std::string::npos) {
50 std::string distance = this->
buffer_.substr(1, rpos - 1);
54 if (distance.length() == 3) {
55 millimeters = millimeters * 10;
58 float meters = float(millimeters) / 1000.0f;
59 ESP_LOGV(TAG,
"Distance from sensor: %d mm, %f m", millimeters, meters);
62 ESP_LOGW(TAG,
"Invalid data read from sensor: %s", this->
buffer_.c_str());