Fix: suggested changes

This commit is contained in:
limengdu 2024-10-12 11:05:46 +08:00
parent e0018288e1
commit b741a04659

View file

@ -145,7 +145,8 @@ void MR60BHA2Component::split_frame_(uint8_t buffer) {
this->current_frame_len_++;
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
this->current_frame_locate_++;
// ESP_LOGD(TAG, "GET CURRENT_FRAME_TYPE: 0x%02x 0x%02x", this->current_frame_buf_[this->current_frame_len_ - 2],
// ESP_LOGD(TAG, "GET CURRENT_FRAME_TYPE: 0x%02x 0x%02x", this->current_frame_buf_[this->current_frame_len_ -
// 2],
// this->current_frame_buf_[this->current_frame_len_ - 1]);
} else {
// ESP_LOGD(TAG, "CURRENT_FRAME_TYPE NOT FOUND: 0x%02x 0x%02x",
@ -228,9 +229,10 @@ void MR60BHA2Component::process_frame_() {
if (!current_data_buf_[0]) {
// ESP_LOGD(TAG, "Successfully set the mounting height");
if (this->distance_sensor_ != nullptr) {
this->current_distance_int_ =
(static_cast<uint32_t>(current_data_buf_[7]) << 24) | (static_cast<uint32_t>(current_data_buf_[6]) << 16) |
(static_cast<uint32_t>(current_data_buf_[5]) << 8) | static_cast<uint32_t>(current_data_buf_[4]);
this->current_distance_int_ = (static_cast<uint32_t>(current_data_buf_[7]) << 24) |
(static_cast<uint32_t>(current_data_buf_[6]) << 16) |
(static_cast<uint32_t>(current_data_buf_[5]) << 8) |
static_cast<uint32_t>(current_data_buf_[4]);
float distance_float;
memcpy(&distance_float, &current_distance_int_, sizeof(float));
this->distance_sensor_->publish_state(distance_float);