11 static const char *
const TAG =
"tof10120";
12 static const uint8_t TOF10120_READ_DISTANCE_CMD[] = {0x00};
13 static const uint8_t TOF10120_DEFAULT_DELAY = 30;
15 static const uint8_t TOF10120_DIR_SEND_REGISTER = 0x0e;
16 static const uint8_t TOF10120_DISTANCE_REGISTER = 0x00;
18 static const uint16_t TOF10120_OUT_OF_RANGE_VALUE = 2000;
21 LOG_SENSOR(
"",
"TOF10120",
this);
22 LOG_UPDATE_INTERVAL(
this);
29 if (!this->
write_bytes(TOF10120_DISTANCE_REGISTER, TOF10120_READ_DISTANCE_CMD,
sizeof(TOF10120_READ_DISTANCE_CMD))) {
30 ESP_LOGE(TAG,
"Communication with TOF10120 failed on write");
40 delay(TOF10120_DEFAULT_DELAY);
42 ESP_LOGE(TAG,
"Communication with TOF10120 failed on read");
47 uint32_t distance_mm = (data[0] << 8) | data[1];
48 ESP_LOGI(TAG,
"Data read: %" PRIu32
"mm", distance_mm);
50 if (distance_mm == TOF10120_OUT_OF_RANGE_VALUE) {
51 ESP_LOGW(TAG,
"Distance measurement out of range");
void status_set_warning(const char *message="unspecified")
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
void dump_config() override
No error found during execution of method.
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delay(uint32_t ms)
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)