7static const char *
const TAG =
"ds248x.one_wire";
10 ESP_LOGCONFIG(TAG,
"Setting up DS248x 1-Wire Bus (Channel %d)...", this->
channel_);
15 ESP_LOGE(TAG,
"Failed to select channel %d during setup", this->
channel_);
23 ESP_LOGCONFIG(TAG,
"Found %zu devices on channel %d", this->
devices_.size(), this->channel_);
27 ESP_LOGCONFIG(TAG,
"DS248x 1-Wire Bus (Channel %d):", this->
channel_);
33 ESP_LOGE(TAG,
"Parent not set!");
44 bool presence =
false;
48 return presence ? 1 : 0;
56 ESP_LOGE(TAG,
"Failed to write byte 0x%02X on channel %d",
val, this->
channel_);
64 for (uint8_t i = 0; i < 8; i++) {
65 uint8_t
byte =
static_cast<uint8_t
>(
val >> (i * 8));
67 ESP_LOGE(TAG,
"Failed to write byte %d/8 (0x%02X) on channel %d - aborting write64", i + 1,
byte, this->
channel_);
79 ESP_LOGE(TAG,
"Failed to read byte on channel %d", this->
channel_);
89 for (uint8_t i = 0; i < 8; i++) {
92 ESP_LOGE(TAG,
"Failed to read byte %d/8 on channel %d - returning partial data", i + 1, this->
channel_);
95 value |= (
static_cast<uint64_t
>(byte) << (i * 8));
115 uint8_t last_zero = 0;
119 for (uint8_t bit_number = 1; bit_number <= 64; bit_number++) {
120 uint64_t bit_mask = 1ULL << (bit_number - 1);
123 bool search_direction;
125 search_direction = (
address & bit_mask) != 0;
133 ESP_LOGW(TAG,
"1-Wire triplet failed at bit %d on channel %d - aborting search", bit_number, this->
channel_);
138 bool id_bit = (
status & DS248X_STATUS_SBR) != 0;
139 bool cmp_id_bit = (
status & DS248X_STATUS_TSB) != 0;
140 bool dir_taken = (
status & DS248X_STATUS_DIR) != 0;
142 if (id_bit && cmp_id_bit) {
148 if (!id_bit && !cmp_id_bit && !dir_taken) {
150 last_zero = bit_number;
163 if (last_zero == 0) {
void mark_failed()
Mark this component as failed.
bool select_channel(uint8_t channel)
bool ow_reset(bool &presence)
bool ow_read_byte(uint8_t &byte)
bool ow_write_byte(uint8_t byte)
bool search_triplet(bool search_direction, uint8_t &status)
void dump_config() override
void write8(uint8_t val) override
void write64(uint64_t val) override
uint64_t search_int() override
DS248xComponent * parent_
bool ensure_channel_()
Select the channel on the DS248x before any 1-Wire operation.
bool search_last_device_flag_
void reset_search() override
uint8_t search_last_discrepancy_
uint64_t read64() override
std::vector< uint64_t > devices_
void dump_devices_(const char *tag)
log the found devices
void search()
Search for 1-Wire devices on the bus.