ESPHome 2025.5.0
Loading...
Searching...
No Matches
zio_ultrasonic.cpp
Go to the documentation of this file.
1
2#include "zio_ultrasonic.h"
3
4#include "esphome/core/log.h"
5
6namespace esphome {
7namespace zio_ultrasonic {
8
9static const char *const TAG = "zio_ultrasonic";
10
12 ESP_LOGCONFIG(TAG, "Zio Ultrasonic Sensor:");
13 LOG_I2C_DEVICE(this);
14 LOG_UPDATE_INTERVAL(this);
15 LOG_SENSOR(" ", "Sensor:", this);
16}
17
19 uint16_t distance;
20
21 // Read an unsigned two byte integerfrom register 0x01 which gives distance in mm
22 if (!this->read_byte_16(0x01, &distance)) {
23 ESP_LOGE(TAG, "Error reading data from Zio Ultrasonic");
24 this->publish_state(NAN);
25 } else {
26 this->publish_state(distance);
27 }
28}
29
30} // namespace zio_ultrasonic
31} // namespace esphome
bool read_byte_16(uint8_t a_register, uint16_t *data)
Definition i2c.h:250
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:39
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7