ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
one_wire.cpp
Go to the documentation of this file.
1#include "one_wire.h"
2
3namespace esphome {
4namespace one_wire {
5
6static const char *const TAG = "one_wire";
7
8const std::string &OneWireDevice::get_address_name() {
9 if (this->address_name_.empty())
10 this->address_name_ = std::string("0x") + format_hex(this->address_);
11 return this->address_name_;
12}
13
15 if (!this->bus_->select(this->address_))
16 return false;
17 this->bus_->write8(cmd);
18 return true;
19}
20
22 if (this->address_ != 0)
23 return true;
24 auto devices = this->bus_->get_devices();
25 if (devices.empty()) {
26 ESP_LOGE(TAG, "No devices, can't auto-select address");
27 return false;
28 }
29 if (devices.size() > 1) {
30 ESP_LOGE(TAG, "More than one device, can't auto-select address");
31 return false;
32 }
33 this->address_ = devices[0];
34 return true;
35}
36
37} // namespace one_wire
38} // namespace esphome
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.
bool check_address_()
find an address if necessary should be called from setup
Definition one_wire.cpp:21
OneWireBus * bus_
pointer to OneWireBus instance
Definition one_wire.h:29
bool send_command_(uint8_t cmd)
send command on the bus
Definition one_wire.cpp:14
const std::string & get_address_name()
Helper to create (and cache) the name for this sensor. For example "0xfe0000031f1eaf29".
Definition one_wire.cpp:8
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string format_hex(const uint8_t *data, size_t length)
Format the byte array data of length len in lowercased hex.
Definition helpers.cpp:249