ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
one_wire.cpp
Go to the documentation of this file.
1#include "one_wire.h"
2
4
5ESPHOME_LOG_TAG(TAG, "one_wire");
6
7bool OneWireDevice::send_command_(uint8_t cmd) {
8 if (!this->bus_->select(this->address_))
9 return false;
10 this->bus_->write8(cmd);
11 return true;
12}
13
15 if (this->address_ != 0)
16 return true;
17 auto devices = this->bus_->get_devices();
18
19 if (this->index_ != INDEX_NOT_SET) {
20 if (this->index_ >= devices.size()) {
21 ESP_LOGE(TAG, "Index %d out of range, only %d devices found", this->index_, devices.size());
22 return false;
23 }
24 this->address_ = devices[this->index_];
25 return true;
26 }
27
28 if (devices.empty()) {
29 ESP_LOGE(TAG, "No devices, can't auto-select address");
30 return false;
31 }
32 if (devices.size() > 1) {
33 ESP_LOGE(TAG, "More than one device, can't auto-select address");
34 return false;
35 }
36 this->address_ = devices[0];
37 return true;
38}
39
40} // namespace esphome::one_wire
const std::vector< uint64_t > & get_devices()
Return the list of found devices.
bool select(uint64_t address)
Select a specific address on the bus for the following command.
virtual void write8(uint8_t val)=0
Write a word to the bus. LSB first.
static constexpr uint8_t INDEX_NOT_SET
Definition one_wire.h:29
OneWireBus * bus_
pointer to OneWireBus instance
Definition one_wire.h:33
bool send_command_(uint8_t cmd)
send command on the bus
Definition one_wire.cpp:7
bool check_address_or_index_()
find an address if necessary should be called from setup
Definition one_wire.cpp:14
ESPHOME_LOG_TAG(TAG, "one_wire")