10 static const char *
const TAG =
"a01nyub.sensor";
11 static const uint8_t MAX_DATA_LENGTH_BYTES = 4;
24 if (this->
buffer_.size() >= MAX_DATA_LENGTH_BYTES) {
26 for (i = 0; i < this->
buffer_.size(); i++) {
29 if (i + 1 + 3 < this->
buffer_.size()) {
34 if (this->
buffer_[i + 3] == checksum) {
35 float distance = (this->
buffer_[i + 1] << 8) + this->
buffer_[i + 2];
37 float meters = distance / 1000.0;
38 ESP_LOGV(TAG,
"Distance from sensor: %f mm, %f m", distance, meters);
52 ESP_LOGCONFIG(TAG,
"A01nyub Sensor:");
53 LOG_SENSOR(
" ",
"Distance",
this);
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.