11 ESP_LOGCONFIG(TAG,
"Setting up DS248x 1-Wire Bus (Channel %d)...", this->
channel_);
16 ESP_LOGE(TAG,
"Failed to select channel %d during setup", this->
channel_);
24 ESP_LOGCONFIG(TAG,
"Found %zu devices on channel %d", this->
devices_.size(), this->channel_);
28 ESP_LOGCONFIG(TAG,
"DS248x 1-Wire Bus (Channel %d):", this->
channel_);
34 ESP_LOGE(TAG,
"Parent not set!");
45 bool presence =
false;
49 return presence ? 1 : 0;
57 ESP_LOGE(TAG,
"Failed to write byte 0x%02X on channel %d",
val, this->
channel_);
65 for (uint8_t i = 0; i < 8; i++) {
66 uint8_t
byte =
static_cast<uint8_t
>(
val >> (i * 8));
68 ESP_LOGE(TAG,
"Failed to write byte %d/8 (0x%02X) on channel %d - aborting write64", i + 1,
byte, this->
channel_);
80 ESP_LOGE(TAG,
"Failed to read byte on channel %d", this->
channel_);
90 for (uint8_t i = 0; i < 8; i++) {
93 ESP_LOGE(TAG,
"Failed to read byte %d/8 on channel %d - returning partial data", i + 1, this->
channel_);
96 value |= (
static_cast<uint64_t
>(byte) << (i * 8));
116 uint8_t last_zero = 0;
120 for (uint8_t bit_number = 1; bit_number <= 64; bit_number++) {
121 uint64_t bit_mask = 1ULL << (bit_number - 1);
124 bool search_direction;
126 search_direction = (
address & bit_mask) != 0;
134 ESP_LOGW(TAG,
"1-Wire triplet failed at bit %d on channel %d - aborting search", bit_number, this->
channel_);
139 bool id_bit = (
status & DS248X_STATUS_SBR) != 0;
140 bool cmp_id_bit = (
status & DS248X_STATUS_TSB) != 0;
141 bool dir_taken = (
status & DS248X_STATUS_DIR) != 0;
143 if (id_bit && cmp_id_bit) {
149 if (!id_bit && !cmp_id_bit && !dir_taken) {
151 last_zero = bit_number;
160 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.
ESPHOME_LOG_TAG(TAG, "ds248x")
ESPHOME_ALWAYS_INLINE constexpr void assign_bits(T &value, std::type_identity_t< T > mask, bool on)
Set the bits of mask in value when on is true, clear them otherwise.