10 static const char *
const TAG =
"a01nyub.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 float meters = distance / 1000.0;
30 ESP_LOGV(TAG,
"Distance from sensor: %f mm, %f m", distance, meters);
33 ESP_LOGW(TAG,
"Invalid data read from sensor: %s",
format_hex_pretty(this->buffer_).c_str());
36 ESP_LOGW(TAG,
"checksum failed: %02x != %02x", checksum, this->buffer_[3]);
38 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.
void dump_config() override
std::vector< uint8_t > buffer_
bool read_byte(uint8_t *data)
void publish_state(float state)
Publish a new state to the front-end.
Implementation of SPI Controller mode.