ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
one_wire.h
Go to the documentation of this file.
1#pragma once
2
3#include "one_wire_bus.h"
5#include "esphome/core/log.h"
6
7namespace esphome::one_wire {
8
9#define LOG_ONE_WIRE_DEVICE(this) \
10 ESP_LOGCONFIG(TAG, " Address: %s (%s)", this->get_address_name().c_str(), \
11 LOG_STR_ARG(this->bus_->get_model_str(this->address_ & 0xff)));
12
14 public:
17 void set_address(uint64_t address);
18
19 void set_index(uint8_t index) { this->index_ = index; }
20
23 void set_one_wire_bus(OneWireBus *bus) { this->bus_ = bus; }
24
26 const std::string &get_address_name();
27
28 protected:
29 static constexpr uint8_t INDEX_NOT_SET = 255;
30
31 uint64_t address_{0};
33 OneWireBus *bus_{nullptr};
34 std::string address_name_;
35
39
42 bool send_command_(uint8_t cmd);
43};
44
45} // namespace esphome::one_wire
uint8_t address
Definition bl0906.h:4
static constexpr uint8_t INDEX_NOT_SET
Definition one_wire.h:29
OneWireBus * bus_
pointer to OneWireBus instance
Definition one_wire.h:33
void set_index(uint8_t index)
Definition one_wire.h:19
void set_address(uint64_t address)
store the address of the device
Definition one_wire.cpp:15
bool send_command_(uint8_t cmd)
send command on the bus
Definition one_wire.cpp:20
void set_one_wire_bus(OneWireBus *bus)
store the pointer to the OneWireBus to use
Definition one_wire.h:23
const std::string & get_address_name()
Helper to create (and cache) the name for this sensor. For example "0xfe0000031f1eaf29".
Definition one_wire.cpp:7
bool check_address_or_index_()
find an address if necessary should be called from setup
Definition one_wire.cpp:27