10 static const char *
const TAG =
"a02yyuw.sensor";
16 if (this->
buffer_.empty() && (data != 0xff))
26 if (this->buffer_[3] == checksum) {
27 float distance = (this->buffer_[1] << 8) + this->buffer_[2];
29 ESP_LOGV(TAG,
"Distance from sensor: %f mm", distance);
32 ESP_LOGW(TAG,
"Invalid data read from sensor: %s",
format_hex_pretty(this->buffer_).c_str());
35 ESP_LOGW(TAG,
"checksum failed: %02x != %02x", checksum, this->buffer_[3]);
37 this->buffer_.clear();
std::string format_hex_pretty(const uint8_t *data, size_t length)
Format the byte array data of length len in pretty-printed, human-readable hex.
std::vector< uint8_t > buffer_
void dump_config() override
bool read_byte(uint8_t *data)
void publish_state(float state)
Publish a new state to the front-end.
Implementation of SPI Controller mode.