ESPHome 2026.11.0-dev
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 do { \
11 char address_buf[format_hex_prefixed_size(sizeof(uint64_t))]; \
12 ESP_LOGCONFIG(TAG, " Address: %s (%s)", format_hex_prefixed_to(address_buf, (this)->address_), \
13 LOG_STR_ARG((this)->bus_->get_model_str((this)->address_ & 0xff))); \
14 } while (0)
15
17 public:
20 void set_address(uint64_t address) { this->address_ = address; }
21
22 void set_index(uint8_t index) { this->index_ = index; }
23
26 void set_one_wire_bus(OneWireBus *bus) { this->bus_ = bus; }
27
28 protected:
29 static constexpr uint8_t INDEX_NOT_SET = 255;
30
31 uint64_t address_{0};
33 OneWireBus *bus_{nullptr};
34
38
41 bool send_command_(uint8_t cmd);
42};
43
44} // 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:22
void set_address(uint64_t address)
store the address of the device
Definition one_wire.h:20
bool send_command_(uint8_t cmd)
send command on the bus
Definition one_wire.cpp:7
void set_one_wire_bus(OneWireBus *bus)
store the pointer to the OneWireBus to use
Definition one_wire.h:26
bool check_address_or_index_()
find an address if necessary should be called from setup
Definition one_wire.cpp:14