From d7e76015cc2d93bbe7b04380ae44b3d5e8d5e217 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 16:18:26 +0100 Subject: [PATCH 01/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 1af51cae1b..3789052a6f 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -8,7 +8,8 @@ namespace esphome { namespace mcp4461 { struct WiperState { - bool update = false; + bool update_level = false; + bool update_terminal = false; bool terminal_a = true; bool terminal_b = true; bool terminal_w = true; From 6a6c9fda60c78a1bd8b5d345169d278de19263a8 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 16:24:08 +0100 Subject: [PATCH 02/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index dabe84613e..756288dfaa 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -136,11 +136,14 @@ void Mcp4461Component::loop() { } uint8_t i; for (i = 0; i < 8; i++) { - if (this->reg_[i].update) { + if (this->reg_[i].update_level) { // set wiper i state if changed if (this->reg_[i].state != this->read_wiper_level_(i)) { this->write_wiper_level_(i, this->reg_[i].state); } + } + this->reg_[i].update_level = false; + if (this->reg_[i].update_terminal) { // terminal register changes only applicable to wipers 0-3 ! if (i < 4) { // set terminal register changes @@ -158,7 +161,7 @@ void Mcp4461Component::loop() { } } } - this->reg_[i].update = false; + this->reg_[i].update_terminal = false; } } @@ -292,7 +295,7 @@ void Mcp4461Component::set_wiper_level(Mcp4461WiperIdx wiper, uint16_t value) { } ESP_LOGV(TAG, "Setting MCP4461 wiper %" PRIu8 " to %" PRIu16 "!", wiper_idx, value); this->reg_[wiper_idx].state = value; - this->reg_[wiper_idx].update = true; + this->reg_[wiper_idx].update_level = true; } void Mcp4461Component::write_wiper_level_(uint8_t wiper, uint16_t value) { @@ -324,7 +327,7 @@ void Mcp4461Component::enable_wiper(Mcp4461WiperIdx wiper) { } ESP_LOGV(TAG, "Enabling wiper %" PRIu8, wiper_idx); this->reg_[wiper_idx].terminal_hw = true; - this->reg_[wiper_idx].update = true; + this->reg_[wiper_idx].update_level = true; } void Mcp4461Component::disable_wiper(Mcp4461WiperIdx wiper) { @@ -343,7 +346,7 @@ void Mcp4461Component::disable_wiper(Mcp4461WiperIdx wiper) { } ESP_LOGV(TAG, "Disabling wiper %" PRIu8, wiper_idx); this->reg_[wiper_idx].terminal_hw = false; - this->reg_[wiper_idx].update = true; + this->reg_[wiper_idx].update_level = true; } bool Mcp4461Component::increase_wiper(Mcp4461WiperIdx wiper) { @@ -481,7 +484,7 @@ void Mcp4461Component::update_terminal_register(Mcp4461TerminalIdx terminal_conn this->reg_[(wiper_index + 1)].terminal_hw = ((terminal_data >> 7) & 0x01); } -bool Mcp4461Component::set_terminal_register(Mcp4461TerminalIdx terminal_connector, uint8_t data) { +bool Mcp4461Component::set_terminal_register_(Mcp4461TerminalIdx terminal_connector, uint8_t data) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return false; @@ -530,7 +533,7 @@ void Mcp4461Component::enable_terminal(Mcp4461WiperIdx wiper, char terminal) { ESP_LOGW(TAG, "Unknown terminal %c specified", terminal); return; } - this->reg_[wiper_idx].update = true; + this->reg_[wiper_idx].update_terminal = false; = true; } void Mcp4461Component::disable_terminal(Mcp4461WiperIdx wiper, char terminal) { @@ -560,7 +563,7 @@ void Mcp4461Component::disable_terminal(Mcp4461WiperIdx wiper, char terminal) { ESP_LOGW(TAG, "Unknown terminal %c specified", terminal); return; } - this->reg_[wiper_idx].update = true; + this->reg_[wiper_idx].update_terminal = false; = true; } uint16_t Mcp4461Component::get_eeprom_value(Mcp4461EepromLocation location) { From 4865d9653101672f83bcd9df44a7ae9bc245b282 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 16:24:45 +0100 Subject: [PATCH 03/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 756288dfaa..fc32ff9119 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -433,7 +433,7 @@ uint8_t Mcp4461Component::calc_terminal_connector_byte_(Mcp4461TerminalIdx termi return static_cast(new_value_byte); } -uint8_t Mcp4461Component::get_terminal_register(Mcp4461TerminalIdx terminal_connector) { +uint8_t Mcp4461Component::get_terminal_register_(Mcp4461TerminalIdx terminal_connector) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return 0; @@ -456,7 +456,7 @@ uint8_t Mcp4461Component::get_terminal_register(Mcp4461TerminalIdx terminal_conn } } -void Mcp4461Component::update_terminal_register(Mcp4461TerminalIdx terminal_connector) { +void Mcp4461Component::update_terminal_register_(Mcp4461TerminalIdx terminal_connector) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return; From ab7adf2a16798b38b40bb9ea29c854d4b3346864 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 16:25:20 +0100 Subject: [PATCH 04/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 3789052a6f..af01befd83 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -86,9 +86,6 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { bool decrease_wiper(Mcp4461WiperIdx wiper); void enable_terminal(Mcp4461WiperIdx wiper, char terminal); void disable_terminal(Mcp4461WiperIdx, char terminal); - void update_terminal_register(Mcp4461TerminalIdx terminal_connector); - uint8_t get_terminal_register(Mcp4461TerminalIdx terminal_connector); - bool set_terminal_register(Mcp4461TerminalIdx terminal_connector, uint8_t data); uint16_t get_eeprom_value(Mcp4461EepromLocation location); bool set_eeprom_value(Mcp4461EepromLocation location, uint16_t value); void set_initial_value(Mcp4461WiperIdx wiper, float initial_value); @@ -117,6 +114,9 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { void write_wiper_level_(uint8_t wiper, uint16_t value); bool mcp4461_write_(uint8_t addr, uint16_t data, bool nonvolatile = false); uint8_t calc_terminal_connector_byte_(Mcp4461TerminalIdx terminal_connector); + void update_terminal_register(Mcp4461TerminalIdx terminal_connector); + uint8_t get_terminal_register(Mcp4461TerminalIdx terminal_connector); + bool set_terminal_register(Mcp4461TerminalIdx terminal_connector, uint8_t data); WiperState reg_[8]; void begin_(); From ee660cea5f7c6e7600f345c525e80561322242be Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 16:25:38 +0100 Subject: [PATCH 05/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index af01befd83..52a073a5ad 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -114,9 +114,9 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { void write_wiper_level_(uint8_t wiper, uint16_t value); bool mcp4461_write_(uint8_t addr, uint16_t data, bool nonvolatile = false); uint8_t calc_terminal_connector_byte_(Mcp4461TerminalIdx terminal_connector); - void update_terminal_register(Mcp4461TerminalIdx terminal_connector); - uint8_t get_terminal_register(Mcp4461TerminalIdx terminal_connector); - bool set_terminal_register(Mcp4461TerminalIdx terminal_connector, uint8_t data); + void update_terminal_register_(Mcp4461TerminalIdx terminal_connector); + uint8_t get_terminal_register_(Mcp4461TerminalIdx terminal_connector); + bool set_terminal_register_(Mcp4461TerminalIdx terminal_connector, uint8_t data); WiperState reg_[8]; void begin_(); From 06bbcf1e4ded1bdf71b51d56d0cfa249c96fde8a Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 16:30:06 +0100 Subject: [PATCH 06/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index fc32ff9119..9ff367c9dd 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -153,10 +153,10 @@ void Mcp4461Component::loop() { terminal_connector = Mcp4461TerminalIdx::MCP4461_TERMINAL_1; } uint8_t new_terminal_value = this->calc_terminal_connector_byte_(terminal_connector); - if (new_terminal_value != this->get_terminal_register(terminal_connector)) { + if (new_terminal_value != this->get_terminal_register_(terminal_connector)) { ESP_LOGV(TAG, "updating terminal %" PRIu8 " to new value %" PRIu8, static_cast(terminal_connector), new_terminal_value); - this->set_terminal_register(terminal_connector, new_terminal_value); + this->set_terminal_register_(terminal_connector, new_terminal_value); } } } @@ -465,7 +465,7 @@ void Mcp4461Component::update_terminal_register_(Mcp4461TerminalIdx terminal_con return; } uint8_t terminal_data; - terminal_data = this->get_terminal_register(terminal_connector); + terminal_data = this->get_terminal_register_(terminal_connector); if (terminal_data == 0) { return; } @@ -533,7 +533,7 @@ void Mcp4461Component::enable_terminal(Mcp4461WiperIdx wiper, char terminal) { ESP_LOGW(TAG, "Unknown terminal %c specified", terminal); return; } - this->reg_[wiper_idx].update_terminal = false; = true; + this->reg_[wiper_idx].update_terminal = false; } void Mcp4461Component::disable_terminal(Mcp4461WiperIdx wiper, char terminal) { @@ -563,7 +563,7 @@ void Mcp4461Component::disable_terminal(Mcp4461WiperIdx wiper, char terminal) { ESP_LOGW(TAG, "Unknown terminal %c specified", terminal); return; } - this->reg_[wiper_idx].update_terminal = false; = true; + this->reg_[wiper_idx].update_terminal = false; } uint16_t Mcp4461Component::get_eeprom_value(Mcp4461EepromLocation location) { From 915861d8b331f21e0b4fe985e4af5f1083872456 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 16:58:37 +0100 Subject: [PATCH 07/54] Update mcp4461_output.h --- .../mcp4461/output/mcp4461_output.h | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index 2167a266f3..9a31243b36 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -19,17 +19,18 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented(wiper); - // update wiper connection state - if (!(this->enable_) && wiper_idx < 4) { - parent->reg_[wiper_idx].enabled = false; - parent->disable_terminal(wiper, 'h'); + if (wiper_idx < 4) { + if (!enable) { + parent->reg_[wiper_idx].enabled = false; + parent->disable_terminal(wiper, 'h'); + } + if (!terminal_a) + parent->disable_terminal_(wiper, 'a'); + if (!terminal_b) + parent->disable_terminal_(wiper, 'b'); + if (!terminal_w) + parent->disable_terminal_(wiper, 'w'); } - if (!terminal_a && wiper_idx < 4) - parent->disable_terminal(wiper, 'a'); - if (!terminal_b && wiper_idx < 4) - parent->disable_terminal(wiper, 'b'); - if (!terminal_w && wiper_idx < 4) - parent->disable_terminal(wiper, 'w'); } uint16_t get_wiper_level(); void save_level(); From ea3b13bf8e19bb92f0ef9becebc748b662bbf036 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:00:37 +0100 Subject: [PATCH 08/54] Update mcp4461_output.cpp --- .../mcp4461/output/mcp4461_output.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 544d83fd4c..6c38e89813 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -34,10 +34,10 @@ void Mcp4461Wiper::write_state(float state) { taps = static_cast(state); ESP_LOGV(TAG, "Setting wiper %" PRIu8 " to value %" PRIu16 "", wiper_idx, taps); this->state_ = state; - this->parent_->set_wiper_level(this->wiper_, taps); + this->parent_->set_wiper_level_(this->wiper_, taps); } -uint16_t Mcp4461Wiper::get_wiper_level() { return this->parent_->get_wiper_level(this->wiper_); } +uint16_t Mcp4461Wiper::get_wiper_level() { return this->parent_->get_wiper_level_(this->wiper_); } void Mcp4461Wiper::save_level() { if (this->parent_->is_failed()) { @@ -52,7 +52,7 @@ void Mcp4461Wiper::save_level() { uint8_t nonvolatile_wiper_idx = wiper_idx + 4; this->parent_->reg_[nonvolatile_wiper_idx].state = this->parent_->reg_[wiper_idx].state; Mcp4461WiperIdx nonvolatile_wiper = static_cast(nonvolatile_wiper_idx); - this->parent_->set_wiper_level(nonvolatile_wiper, this->state_); + this->parent_->set_wiper_level_(nonvolatile_wiper, this->state_); } void Mcp4461Wiper::enable_wiper() { @@ -65,7 +65,7 @@ void Mcp4461Wiper::enable_wiper() { ESP_LOGW(TAG, "Cannot enable nonvolatile wiper %" PRIu8 " !", wiper_idx); return; } - this->parent_->enable_wiper(this->wiper_); + this->parent_->enable_wiper_(this->wiper_); } void Mcp4461Wiper::disable_wiper() { @@ -78,7 +78,7 @@ void Mcp4461Wiper::disable_wiper() { ESP_LOGW(TAG, "Cannot disable nonvolatile wiper %" PRIu8 " !", wiper_idx); return; } - this->parent_->disable_wiper(this->wiper_); + this->parent_->disable_wiper_(this->wiper_); } void Mcp4461Wiper::increase_wiper() { @@ -91,7 +91,7 @@ void Mcp4461Wiper::increase_wiper() { ESP_LOGW(TAG, "Cannot increase nonvolatile wiper %" PRIu8 " !", wiper_idx); return; } - if (this->parent_->increase_wiper(this->wiper_)) { + if (this->parent_->increase_wiper_(this->wiper_)) { this->state_ = this->state_ + 1.0; } } @@ -106,7 +106,7 @@ void Mcp4461Wiper::decrease_wiper() { ESP_LOGW(TAG, "Cannot decrease nonvolatile wiper %" PRIu8 " !", wiper_idx); return; } - if (this->parent_->decrease_wiper(this->wiper_)) { + if (this->parent_->decrease_wiper_(this->wiper_)) { this->state_ = this->state_ - 1.0; } } @@ -121,7 +121,7 @@ void Mcp4461Wiper::enable_terminal(char terminal) { ESP_LOGW(TAG, "Cannot get/set terminals nonvolatile wiper %" PRIu8 " !", wiper_idx); return; } - this->parent_->enable_terminal(this->wiper_, terminal); + this->parent_->enable_terminal_(this->wiper_, terminal); } void Mcp4461Wiper::disable_terminal(char terminal) { @@ -134,7 +134,7 @@ void Mcp4461Wiper::disable_terminal(char terminal) { ESP_LOGW(TAG, "Cannot get/set terminals for nonvolatile wiper %" PRIu8 " !", wiper_idx); return; } - this->parent_->disable_terminal(this->wiper_, terminal); + this->parent_->disable_terminal_(this->wiper_, terminal); } } // namespace mcp4461 From b18d208f3904d0ffceda9ae79e08d981faec0a65 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:03:11 +0100 Subject: [PATCH 09/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 9ff367c9dd..bc8b60fac8 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -76,7 +76,7 @@ void Mcp4461Component::set_initial_value(Mcp4461WiperIdx wiper, float initial_va void Mcp4461Component::update_write_protection_status_() { uint8_t status_register_value; - status_register_value = this->get_status_register(); + status_register_value = this->get_status_register_(); this->write_protected_ = static_cast((status_register_value >> 0) & 0x01); this->reg_[0].wiper_lock_active = static_cast((status_register_value >> 2) & 0x01); this->reg_[1].wiper_lock_active = static_cast((status_register_value >> 3) & 0x01); @@ -117,10 +117,10 @@ void Mcp4461Component::dump_config() { // Bit 7+8 are referenced in datasheet as D7 + D8 and both locked to 1 // Default status register reading should be 0x182h or 386 decimal // "Default" means without any WiperLocks or WriteProtection enabled and EEPRom not active writing - // get_status_register() will automatically check, if D8, D7 & R1 bits (locked to 1) are 1 + // get_status_register_() will automatically check, if D8, D7 & R1 bits (locked to 1) are 1 // and bail out using error-routine otherwise uint8_t status_register_value; - status_register_value = this->get_status_register(); + status_register_value = this->get_status_register_(); ESP_LOGCONFIG(TAG, " └── Status register: D7: %" PRIu8 ", WL3: %" PRIu8 ", WL2: %" PRIu8 ", EEWA: %" PRIu8 ", WL1: %" PRIu8 ", WL0: %" PRIu8 ", R1: %" PRIu8 ", WP: %" PRIu8 "", @@ -132,7 +132,7 @@ void Mcp4461Component::dump_config() { void Mcp4461Component::loop() { if (status_has_warning()) { - this->get_status_register(); + this->get_status_register_(); } uint8_t i; for (i = 0; i < 8; i++) { @@ -165,7 +165,7 @@ void Mcp4461Component::loop() { } } -uint8_t Mcp4461Component::get_status_register() { +uint8_t Mcp4461Component::get_status_register_() { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return 0; @@ -223,7 +223,7 @@ uint8_t Mcp4461Component::get_wiper_address_(uint8_t wiper) { return addr; } -uint16_t Mcp4461Component::get_wiper_level(Mcp4461WiperIdx wiper) { +uint16_t Mcp4461Component::get_wiper_level_(Mcp4461WiperIdx wiper) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return 0; @@ -259,7 +259,7 @@ uint16_t Mcp4461Component::read_wiper_level_(uint8_t wiper) { return buf; } -void Mcp4461Component::update_wiper_level(Mcp4461WiperIdx wiper) { +void Mcp4461Component::update_wiper_level_(Mcp4461WiperIdx wiper) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return; @@ -275,7 +275,7 @@ void Mcp4461Component::update_wiper_level(Mcp4461WiperIdx wiper) { this->reg_[wiper_idx].state = data; } -void Mcp4461Component::set_wiper_level(Mcp4461WiperIdx wiper, uint16_t value) { +void Mcp4461Component::set_wiper_level_(Mcp4461WiperIdx wiper, uint16_t value) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return; @@ -311,7 +311,7 @@ void Mcp4461Component::write_wiper_level_(uint8_t wiper, uint16_t value) { } } -void Mcp4461Component::enable_wiper(Mcp4461WiperIdx wiper) { +void Mcp4461Component::enable_wiper_(Mcp4461WiperIdx wiper) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return; @@ -330,7 +330,7 @@ void Mcp4461Component::enable_wiper(Mcp4461WiperIdx wiper) { this->reg_[wiper_idx].update_level = true; } -void Mcp4461Component::disable_wiper(Mcp4461WiperIdx wiper) { +void Mcp4461Component::disable_wiper_(Mcp4461WiperIdx wiper) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return; @@ -349,7 +349,7 @@ void Mcp4461Component::disable_wiper(Mcp4461WiperIdx wiper) { this->reg_[wiper_idx].update_level = true; } -bool Mcp4461Component::increase_wiper(Mcp4461WiperIdx wiper) { +bool Mcp4461Component::increase_wiper_(Mcp4461WiperIdx wiper) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return false; @@ -379,7 +379,7 @@ bool Mcp4461Component::increase_wiper(Mcp4461WiperIdx wiper) { return true; } -bool Mcp4461Component::decrease_wiper(Mcp4461WiperIdx wiper) { +bool Mcp4461Component::decrease_wiper_(Mcp4461WiperIdx wiper) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return false; @@ -506,7 +506,7 @@ bool Mcp4461Component::set_terminal_register_(Mcp4461TerminalIdx terminal_connec return true; } -void Mcp4461Component::enable_terminal(Mcp4461WiperIdx wiper, char terminal) { +void Mcp4461Component::enable_terminal_(Mcp4461WiperIdx wiper, char terminal) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return; @@ -536,7 +536,7 @@ void Mcp4461Component::enable_terminal(Mcp4461WiperIdx wiper, char terminal) { this->reg_[wiper_idx].update_terminal = false; } -void Mcp4461Component::disable_terminal(Mcp4461WiperIdx wiper, char terminal) { +void Mcp4461Component::disable_terminal_(Mcp4461WiperIdx wiper, char terminal) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); return; @@ -625,7 +625,7 @@ bool Mcp4461Component::set_eeprom_value(Mcp4461EepromLocation location, uint16_t */ bool Mcp4461Component::is_writing_() { /* Read the EEPROM write-active status from the status register */ - bool writing = static_cast((this->get_status_register() >> 4) & 0x01); + bool writing = static_cast((this->get_status_register_() >> 4) & 0x01); /* If EEPROM is no longer writing, reset the timeout flag */ if (!writing) { From 465cff746b20bbc1819ebeaefd519bc5a2abec2e Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:05:23 +0100 Subject: [PATCH 10/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 52a073a5ad..a8b6f5c70e 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -20,7 +20,7 @@ struct WiperState { optional initial_value; }; -enum class Mcp4461Defaults : uint8_t { WIPER_VALUE = 0x80 }; +// default wiper state is 128 / 0x80h enum class Mcp4461Commands : uint8_t { WRITE = 0x00, INCREMENT = 0x04, DECREMENT = 0x08, READ = 0x0C }; enum class Mcp4461Addresses : uint8_t { @@ -75,17 +75,6 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { void dump_config() override; float get_setup_priority() const override { return setup_priority::HARDWARE; } void loop() override; - - uint8_t get_status_register(); - uint16_t get_wiper_level(Mcp4461WiperIdx wiper); - void set_wiper_level(Mcp4461WiperIdx wiper, uint16_t value); - void update_wiper_level(Mcp4461WiperIdx wiper); - void enable_wiper(Mcp4461WiperIdx wiper); - void disable_wiper(Mcp4461WiperIdx wiper); - bool increase_wiper(Mcp4461WiperIdx wiper); - bool decrease_wiper(Mcp4461WiperIdx wiper); - void enable_terminal(Mcp4461WiperIdx wiper, char terminal); - void disable_terminal(Mcp4461WiperIdx, char terminal); uint16_t get_eeprom_value(Mcp4461EepromLocation location); bool set_eeprom_value(Mcp4461EepromLocation location, uint16_t value); void set_initial_value(Mcp4461WiperIdx wiper, float initial_value); @@ -109,6 +98,16 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { void update_write_protection_status_(); uint8_t get_wiper_address_(uint8_t wiper); uint16_t read_wiper_level_(uint8_t wiper); + uint8_t get_status_register_(); + uint16_t get_wiper_level_(Mcp4461WiperIdx wiper); + void set_wiper_level_(Mcp4461WiperIdx wiper, uint16_t value); + void update_wiper_level_(Mcp4461WiperIdx wiper); + void enable_wiper_(Mcp4461WiperIdx wiper); + void disable_wiper_(Mcp4461WiperIdx wiper); + bool increase_wiper_(Mcp4461WiperIdx wiper); + bool decrease_wiper_(Mcp4461WiperIdx wiper); + void enable_terminal_(Mcp4461WiperIdx wiper, char terminal); + void disable_terminal_(Mcp4461WiperIdx, char terminal); bool is_writing_(); bool is_eeprom_ready_for_writing_(bool wait_if_not_ready); void write_wiper_level_(uint8_t wiper, uint16_t value); From 1bb865b2ddffd0ede2d321208b16217202c59fbc Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:07:56 +0100 Subject: [PATCH 11/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index bc8b60fac8..de6855c4f9 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -32,7 +32,7 @@ void Mcp4461Component::begin_() { if (this->reg_[i].enabled) { this->reg_[i].state = this->read_wiper_level_(i); } else { - // only volatile wipers can be disabled + // only volatile wipers can be set disabled on hw level if (i < 4) { this->reg_[i].state = 0; Mcp4461WiperIdx wiper_idx; From 9993fd2434195ba285b01595a0c1c8f910dff651 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:09:25 +0100 Subject: [PATCH 12/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index de6855c4f9..aaa8c7fb18 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -104,21 +104,7 @@ void Mcp4461Component::dump_config() { ESP_LOGCONFIG(TAG, " ├── Nonvolatile wiper [%" PRIu8 "] level: %" PRIu16 "", i, this->reg_[i].state); } } - // log current device status register at start - // from datasheet: - // (1) means, bit is hard-locked to value 1 - // Bit 0 is WP status (=>pin) - // Bit 1 is named "R-1"-pin in datasheet an declared "reserved" and forced/locked to 1 - // Bit 2 is WiperLock-Status resistor-network 0 - // Bit 3 is WiperLock-Status resistor-network 1 - // Bit 4 is EEPROM-Write-Active-Status bit - // Bit 5 is WiperLock-Status resistor-network 2 - // Bit 6 is WiperLock-Status resistor-network 3 - // Bit 7+8 are referenced in datasheet as D7 + D8 and both locked to 1 - // Default status register reading should be 0x182h or 386 decimal - // "Default" means without any WiperLocks or WriteProtection enabled and EEPRom not active writing - // get_status_register_() will automatically check, if D8, D7 & R1 bits (locked to 1) are 1 - // and bail out using error-routine otherwise + uint8_t status_register_value; status_register_value = this->get_status_register_(); ESP_LOGCONFIG(TAG, @@ -270,7 +256,7 @@ void Mcp4461Component::update_wiper_level_(Mcp4461WiperIdx wiper) { return; } uint16_t data; - data = this->get_wiper_level(wiper); + data = this->get_wiper_level_(wiper); ESP_LOGV(TAG, "Got value %" PRIu16 " from wiper %" PRIu8, data, wiper_idx); this->reg_[wiper_idx].state = data; } From 7606a0d4b02188b0c8f2bb0e0f22ec074380e013 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:12:35 +0100 Subject: [PATCH 13/54] Update mcp4461_output.h --- esphome/components/mcp4461/output/mcp4461_output.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index 9a31243b36..79a3ff84d0 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -10,18 +10,16 @@ namespace mcp4461 { class Mcp4461Wiper : public output::FloatOutput, public Parented { public: - Mcp4461Wiper(Mcp4461Component *parent, Mcp4461WiperIdx wiper, bool enable, bool terminal_a, bool terminal_b, + Mcp4461Wiper(Mcp4461Component *parent, Mcp4461WiperIdx wiper, bool terminal_a, bool terminal_b, bool terminal_w) : parent_(parent), wiper_(wiper), - enable_(enable), terminal_a_(terminal_a), terminal_b_(terminal_b), terminal_w_(terminal_w) { uint8_t wiper_idx = static_cast(wiper); if (wiper_idx < 4) { - if (!enable) { - parent->reg_[wiper_idx].enabled = false; + if (!parent->reg_[wiper_idx].enabled) { parent->disable_terminal(wiper, 'h'); } if (!terminal_a) @@ -45,7 +43,6 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented initial_value_; bool terminal_a_; From ab9e69019dcd911530c46c41ed331cd4ed2348ae Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:13:55 +0100 Subject: [PATCH 14/54] Update mcp4461_output.h --- .../components/mcp4461/output/mcp4461_output.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index 79a3ff84d0..c9ca54ae97 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -19,15 +19,14 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented(wiper); if (wiper_idx < 4) { - if (!parent->reg_[wiper_idx].enabled) { - parent->disable_terminal(wiper, 'h'); + if (parent->reg_[wiper_idx].enabled) { + if (!terminal_a) + parent->disable_terminal_(wiper, 'a'); + if (!terminal_b) + parent->disable_terminal_(wiper, 'b'); + if (!terminal_w) + parent->disable_terminal_(wiper, 'w'); } - if (!terminal_a) - parent->disable_terminal_(wiper, 'a'); - if (!terminal_b) - parent->disable_terminal_(wiper, 'b'); - if (!terminal_w) - parent->disable_terminal_(wiper, 'w'); } } uint16_t get_wiper_level(); From 41a4f476014ed23867298b676138b7209ec2a124 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:15:28 +0100 Subject: [PATCH 15/54] Update __init__.py --- esphome/components/mcp4461/output/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/esphome/components/mcp4461/output/__init__.py b/esphome/components/mcp4461/output/__init__.py index 0ffb1bb75d..a337c8d579 100644 --- a/esphome/components/mcp4461/output/__init__.py +++ b/esphome/components/mcp4461/output/__init__.py @@ -22,7 +22,6 @@ CHANNEL_OPTIONS = { "H": Mcp4461WiperIdx.MCP4461_WIPER_7, } -CONF_ENABLE = "enable" CONF_TERMINAL_A = "terminal_a" CONF_TERMINAL_B = "terminal_b" CONF_TERMINAL_W = "terminal_w" @@ -32,7 +31,6 @@ CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend( cv.Required(CONF_ID): cv.declare_id(Mcp4461Wiper), cv.GenerateID(CONF_MCP4461_ID): cv.use_id(Mcp4461Component), cv.Required(CONF_CHANNEL): cv.enum(CHANNEL_OPTIONS, upper=True), - cv.Optional(CONF_ENABLE, default=True): cv.boolean, cv.Optional(CONF_TERMINAL_A, default=True): cv.boolean, cv.Optional(CONF_TERMINAL_B, default=True): cv.boolean, cv.Optional(CONF_TERMINAL_W, default=True): cv.boolean, @@ -47,7 +45,6 @@ async def to_code(config): config[CONF_ID], parent, config[CONF_CHANNEL], - config[CONF_ENABLE], config[CONF_TERMINAL_A], config[CONF_TERMINAL_B], config[CONF_TERMINAL_W], From 30f91af1056bbcf6527b415d71585c9df062d71a Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:19:15 +0100 Subject: [PATCH 16/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 6c38e89813..6d9328d986 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -37,7 +37,9 @@ void Mcp4461Wiper::write_state(float state) { this->parent_->set_wiper_level_(this->wiper_, taps); } -uint16_t Mcp4461Wiper::get_wiper_level() { return this->parent_->get_wiper_level_(this->wiper_); } +uint16_t Mcp4461Wiper::read_state() { return this->parent_->get_wiper_level_(this->wiper_); } + +uint16_t Mcp4461Wiper::update_state() { return this->parent_->update_wiper_level_(this->wiper_); } void Mcp4461Wiper::save_level() { if (this->parent_->is_failed()) { From a72fa9c5ab8c98e7398658174acacb272ef703f0 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:19:56 +0100 Subject: [PATCH 17/54] Update mcp4461_output.h --- esphome/components/mcp4461/output/mcp4461_output.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index c9ca54ae97..3f7f8f9418 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -29,7 +29,8 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented Date: Sun, 9 Feb 2025 17:22:01 +0100 Subject: [PATCH 18/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 6d9328d986..55c278d86a 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -39,7 +39,7 @@ void Mcp4461Wiper::write_state(float state) { uint16_t Mcp4461Wiper::read_state() { return this->parent_->get_wiper_level_(this->wiper_); } -uint16_t Mcp4461Wiper::update_state() { return this->parent_->update_wiper_level_(this->wiper_); } +void Mcp4461Wiper::update_state() { this->state = this->read_state(this->wiper_); } void Mcp4461Wiper::save_level() { if (this->parent_->is_failed()) { From de79c90b72cb36d4b7f4392b1ca461b574f06824 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:22:18 +0100 Subject: [PATCH 19/54] Update mcp4461_output.h --- esphome/components/mcp4461/output/mcp4461_output.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index 3f7f8f9418..cf9b1f28a4 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -30,7 +30,7 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented Date: Sun, 9 Feb 2025 17:24:22 +0100 Subject: [PATCH 20/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index aaa8c7fb18..df2f78a0f0 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -37,7 +37,7 @@ void Mcp4461Component::begin_() { this->reg_[i].state = 0; Mcp4461WiperIdx wiper_idx; wiper_idx = static_cast(i); - this->disable_wiper(wiper_idx); + this->disable_wiper_(wiper_idx); } } } From b9892aa72dfd31726531c7ff5d387899f7aaf2ca Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:26:26 +0100 Subject: [PATCH 21/54] Update mcp4461_output.h --- esphome/components/mcp4461/output/mcp4461_output.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index cf9b1f28a4..3f7f8f9418 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -30,7 +30,7 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented Date: Sun, 9 Feb 2025 17:27:22 +0100 Subject: [PATCH 22/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 55c278d86a..5475794c6e 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -39,7 +39,10 @@ void Mcp4461Wiper::write_state(float state) { uint16_t Mcp4461Wiper::read_state() { return this->parent_->get_wiper_level_(this->wiper_); } -void Mcp4461Wiper::update_state() { this->state = this->read_state(this->wiper_); } +uint16_t Mcp4461Wiper::update_state() { + this->state = this->read_state(this->wiper_); + return this->state +} void Mcp4461Wiper::save_level() { if (this->parent_->is_failed()) { From 69e291c53b02b10fd865f16dfe44a9c5642c6be4 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:29:32 +0100 Subject: [PATCH 23/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 5475794c6e..3762f77ada 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -40,8 +40,8 @@ void Mcp4461Wiper::write_state(float state) { uint16_t Mcp4461Wiper::read_state() { return this->parent_->get_wiper_level_(this->wiper_); } uint16_t Mcp4461Wiper::update_state() { - this->state = this->read_state(this->wiper_); - return this->state + this->state_ = this->read_state(this->wiper_); + return this->state_; } void Mcp4461Wiper::save_level() { From 8ad2cbf439df20c765d70079ee5b768277704da9 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:32:34 +0100 Subject: [PATCH 24/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 3762f77ada..fa36a20b22 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -66,10 +66,6 @@ void Mcp4461Wiper::enable_wiper() { return; } uint8_t wiper_idx = static_cast(this->wiper_); - if (wiper_idx > 3) { - ESP_LOGW(TAG, "Cannot enable nonvolatile wiper %" PRIu8 " !", wiper_idx); - return; - } this->parent_->enable_wiper_(this->wiper_); } @@ -79,10 +75,6 @@ void Mcp4461Wiper::disable_wiper() { return; } uint8_t wiper_idx = static_cast(this->wiper_); - if (wiper_idx > 3) { - ESP_LOGW(TAG, "Cannot disable nonvolatile wiper %" PRIu8 " !", wiper_idx); - return; - } this->parent_->disable_wiper_(this->wiper_); } From 174d0414ef1d873b3ecf1db67156f9dd230c0f93 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:35:38 +0100 Subject: [PATCH 25/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index df2f78a0f0..0eb99a5361 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -312,8 +312,11 @@ void Mcp4461Component::enable_wiper_(Mcp4461WiperIdx wiper) { return; } ESP_LOGV(TAG, "Enabling wiper %" PRIu8, wiper_idx); - this->reg_[wiper_idx].terminal_hw = true; - this->reg_[wiper_idx].update_level = true; + this->reg_[wiper_idx].enabled = true; + if (wiper_idx < 4) { + this->reg_[wiper_idx].terminal_hw = true; + this->reg_[wiper_idx].update_terminal = true; + } } void Mcp4461Component::disable_wiper_(Mcp4461WiperIdx wiper) { @@ -331,8 +334,11 @@ void Mcp4461Component::disable_wiper_(Mcp4461WiperIdx wiper) { return; } ESP_LOGV(TAG, "Disabling wiper %" PRIu8, wiper_idx); - this->reg_[wiper_idx].terminal_hw = false; - this->reg_[wiper_idx].update_level = true; + this->reg_[wiper_idx].enabled = true; + if (wiper_idx < 4) { + this->reg_[wiper_idx].terminal_hw = true; + this->reg_[wiper_idx].update_terminal = true; + } } bool Mcp4461Component::increase_wiper_(Mcp4461WiperIdx wiper) { From 63b26623d8a7df02c7dee3c04f216c8f5dcd1364 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:37:23 +0100 Subject: [PATCH 26/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index a8b6f5c70e..9c4fe46f34 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -8,16 +8,16 @@ namespace esphome { namespace mcp4461 { struct WiperState { - bool update_level = false; - bool update_terminal = false; + bool enabled = true; + uint16_t state = 0; + optional initial_value; bool terminal_a = true; bool terminal_b = true; bool terminal_w = true; bool terminal_hw = true; - uint16_t state = 0; - bool enabled = true; bool wiper_lock_active = false; - optional initial_value; + bool update_level = false; + bool update_terminal = false; }; // default wiper state is 128 / 0x80h From 0609d6ed3d41a79522dee7ea176c9c6a59ccf0b3 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:52:38 +0100 Subject: [PATCH 27/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 27 ++++++++++++-------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 0eb99a5361..811dab8541 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -130,22 +130,17 @@ void Mcp4461Component::loop() { } this->reg_[i].update_level = false; if (this->reg_[i].update_terminal) { - // terminal register changes only applicable to wipers 0-3 ! - if (i < 4) { - // set terminal register changes - if (i == 0 || i == 2) { - Mcp4461TerminalIdx terminal_connector = Mcp4461TerminalIdx::MCP4461_TERMINAL_0; - if (i > 0) { - terminal_connector = Mcp4461TerminalIdx::MCP4461_TERMINAL_1; - } - uint8_t new_terminal_value = this->calc_terminal_connector_byte_(terminal_connector); - if (new_terminal_value != this->get_terminal_register_(terminal_connector)) { - ESP_LOGV(TAG, "updating terminal %" PRIu8 " to new value %" PRIu8, static_cast(terminal_connector), - new_terminal_value); - this->set_terminal_register_(terminal_connector, new_terminal_value); - } - } + // set terminal register changes + if (i < 2) { + Mcp4461TerminalIdx terminal_connector = Mcp4461TerminalIdx::MCP4461_TERMINAL_0; } + if (i > 1) { + terminal_connector = Mcp4461TerminalIdx::MCP4461_TERMINAL_1; + } + uint8_t new_terminal_value = this->calc_terminal_connector_byte_(terminal_connector); + ESP_LOGV(TAG, "updating terminal %" PRIu8 " to new value %" PRIu8, static_cast(terminal_connector), + new_terminal_value); + this->set_terminal_register_(terminal_connector, new_terminal_value); } this->reg_[i].update_terminal = false; } @@ -505,6 +500,7 @@ void Mcp4461Component::enable_terminal_(Mcp4461WiperIdx wiper, char terminal) { } uint8_t wiper_idx = static_cast(wiper); if (wiper_idx > 3) { + ESP_LOGV(TAG, "Cannot enable/disable terminals of nonvolatile wiper %" PRIu8 "", terminal, wiper_idx); return; } ESP_LOGV(TAG, "Enabling terminal %c of wiper %" PRIu8 "", terminal, wiper_idx); @@ -535,6 +531,7 @@ void Mcp4461Component::disable_terminal_(Mcp4461WiperIdx wiper, char terminal) { } uint8_t wiper_idx = static_cast(wiper); if (wiper_idx > 3) { + ESP_LOGV(TAG, "Cannot enable/disable terminals of nonvolatile wiper %" PRIu8 "", terminal, wiper_idx); return; } ESP_LOGV(TAG, "Disabling terminal %c of wiper %" PRIu8 "", terminal, wiper_idx); From 613bfa7ab1dcbef21a3f93c9ebf7fd6cf0a7da02 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:53:48 +0100 Subject: [PATCH 28/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 811dab8541..b89722b9d9 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -499,10 +499,6 @@ void Mcp4461Component::enable_terminal_(Mcp4461WiperIdx wiper, char terminal) { return; } uint8_t wiper_idx = static_cast(wiper); - if (wiper_idx > 3) { - ESP_LOGV(TAG, "Cannot enable/disable terminals of nonvolatile wiper %" PRIu8 "", terminal, wiper_idx); - return; - } ESP_LOGV(TAG, "Enabling terminal %c of wiper %" PRIu8 "", terminal, wiper_idx); switch (terminal) { case 'h': @@ -530,10 +526,6 @@ void Mcp4461Component::disable_terminal_(Mcp4461WiperIdx wiper, char terminal) { return; } uint8_t wiper_idx = static_cast(wiper); - if (wiper_idx > 3) { - ESP_LOGV(TAG, "Cannot enable/disable terminals of nonvolatile wiper %" PRIu8 "", terminal, wiper_idx); - return; - } ESP_LOGV(TAG, "Disabling terminal %c of wiper %" PRIu8 "", terminal, wiper_idx); switch (terminal) { case 'h': From 132a366801dd93189307adb070a4e8911e36bc21 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 17:58:08 +0100 Subject: [PATCH 29/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index fa36a20b22..403b4c9942 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -12,6 +12,8 @@ static const LogString *get_wiper_message_string(int status) { switch (status) { case Mcp4461Component::MCP4461_FAILED: return LOG_STR("Parent MCP4461 component failed"); + case Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE: + return LOG_STR("Action prohibited for nonvolatile wiper"); default: return LOG_STR("Unknown error"); } @@ -51,7 +53,7 @@ void Mcp4461Wiper::save_level() { } uint8_t wiper_idx = static_cast(this->wiper_); if (wiper_idx > 3) { - ESP_LOGW(TAG, "Cannot save level for nonvolatile wiper %" PRIu8 " !", wiper_idx); + ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); return; } uint8_t nonvolatile_wiper_idx = wiper_idx + 4; @@ -85,7 +87,7 @@ void Mcp4461Wiper::increase_wiper() { } uint8_t wiper_idx = static_cast(this->wiper_); if (wiper_idx > 3) { - ESP_LOGW(TAG, "Cannot increase nonvolatile wiper %" PRIu8 " !", wiper_idx); + ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); return; } if (this->parent_->increase_wiper_(this->wiper_)) { @@ -100,7 +102,7 @@ void Mcp4461Wiper::decrease_wiper() { } uint8_t wiper_idx = static_cast(this->wiper_); if (wiper_idx > 3) { - ESP_LOGW(TAG, "Cannot decrease nonvolatile wiper %" PRIu8 " !", wiper_idx); + ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); return; } if (this->parent_->decrease_wiper_(this->wiper_)) { @@ -115,7 +117,7 @@ void Mcp4461Wiper::enable_terminal(char terminal) { } uint8_t wiper_idx = static_cast(this->wiper_); if (wiper_idx > 3) { - ESP_LOGW(TAG, "Cannot get/set terminals nonvolatile wiper %" PRIu8 " !", wiper_idx); + ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); return; } this->parent_->enable_terminal_(this->wiper_, terminal); @@ -128,7 +130,7 @@ void Mcp4461Wiper::disable_terminal(char terminal) { } uint8_t wiper_idx = static_cast(this->wiper_); if (wiper_idx > 3) { - ESP_LOGW(TAG, "Cannot get/set terminals for nonvolatile wiper %" PRIu8 " !", wiper_idx); + ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); return; } this->parent_->disable_terminal_(this->wiper_, terminal); From 4fbef5be4b0ee507f083f32275c95d0ad58c58cd Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:01:04 +0100 Subject: [PATCH 30/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 9c4fe46f34..f75513f590 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -80,12 +80,13 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { void set_initial_value(Mcp4461WiperIdx wiper, float initial_value); enum ErrorCode { - MCP4461_STATUS_OK = 0, // CMD completed successfully - MCP4461_FAILED, // component failed - MCP4461_STATUS_I2C_ERROR, // Unable to communicate with device - MCP4461_STATUS_REGISTER_INVALID, // Status register value was invalid - MCP4461_STATUS_REGISTER_ERROR, // Error fetching status register - MCP4461_VALUE_INVALID, // Invalid value given for wiper / eeprom + MCP4461_STATUS_OK = 0, // CMD completed successfully + MCP4461_FAILED, // component failed + MCP4461_STATUS_I2C_ERROR, // Unable to communicate with device + MCP4461_STATUS_REGISTER_INVALID, // Status register value was invalid + MCP4461_STATUS_REGISTER_ERROR, // Error fetching status register + MCP4461_PROHIBITED_FOR_NONVOLATILE, // + MCP4461_VALUE_INVALID, // Invalid value given for wiper / eeprom MCP4461_WRITE_PROTECTED, // The value was read, but the CRC over the payload (valid and data) does not match MCP4461_WIPER_ENABLED, // The wiper is enabled, discard additional enabling actions MCP4461_WIPER_DISABLED, // The wiper is disabled - all actions for this wiper will be aborted/discarded From f554500a3959c79b0e92d255de9a3b2599a05778 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:03:12 +0100 Subject: [PATCH 31/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 403b4c9942..daa032f7fd 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -42,7 +42,7 @@ void Mcp4461Wiper::write_state(float state) { uint16_t Mcp4461Wiper::read_state() { return this->parent_->get_wiper_level_(this->wiper_); } uint16_t Mcp4461Wiper::update_state() { - this->state_ = this->read_state(this->wiper_); + this->state_ = this->read_state(); return this->state_; } From 8731957b6d0edb8c510b3939b7a6f010fc30abd5 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:07:54 +0100 Subject: [PATCH 32/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index b89722b9d9..7512897b57 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -131,10 +131,11 @@ void Mcp4461Component::loop() { this->reg_[i].update_level = false; if (this->reg_[i].update_terminal) { // set terminal register changes + Mcp4461TerminalIdx terminal_connector; if (i < 2) { - Mcp4461TerminalIdx terminal_connector = Mcp4461TerminalIdx::MCP4461_TERMINAL_0; + terminal_connector = Mcp4461TerminalIdx::MCP4461_TERMINAL_0; } - if (i > 1) { + else { terminal_connector = Mcp4461TerminalIdx::MCP4461_TERMINAL_1; } uint8_t new_terminal_value = this->calc_terminal_connector_byte_(terminal_connector); From 6df7f5673652a0b1dff8d02230839940f187d7e5 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:09:37 +0100 Subject: [PATCH 33/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 7512897b57..0cb06165f8 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -129,6 +129,9 @@ void Mcp4461Component::loop() { } } this->reg_[i].update_level = false; + // can be true only for wipers 0-3 + // setting changes for terminals of nonvolatile wipers + // is prohibited in public methods if (this->reg_[i].update_terminal) { // set terminal register changes Mcp4461TerminalIdx terminal_connector; From a632867f7fd7e518c7810ced0480cbe8e8fc1ca0 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:21:35 +0100 Subject: [PATCH 34/54] Update mcp4461_output.h --- .../mcp4461/output/mcp4461_output.h | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index 3f7f8f9418..f4bac93eba 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -10,24 +10,7 @@ namespace mcp4461 { class Mcp4461Wiper : public output::FloatOutput, public Parented { public: - Mcp4461Wiper(Mcp4461Component *parent, Mcp4461WiperIdx wiper, bool terminal_a, bool terminal_b, - bool terminal_w) - : parent_(parent), - wiper_(wiper), - terminal_a_(terminal_a), - terminal_b_(terminal_b), - terminal_w_(terminal_w) { - uint8_t wiper_idx = static_cast(wiper); - if (wiper_idx < 4) { - if (parent->reg_[wiper_idx].enabled) { - if (!terminal_a) - parent->disable_terminal_(wiper, 'a'); - if (!terminal_b) - parent->disable_terminal_(wiper, 'b'); - if (!terminal_w) - parent->disable_terminal_(wiper, 'w'); - } - } + Mcp4461Wiper(Mcp4461Component *parent, Mcp4461WiperIdx wiper) : parent_(parent), wiper_(wiper) {} } uint16_t read_state(); uint16_t update_state(); @@ -45,9 +28,6 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented initial_value_; - bool terminal_a_; - bool terminal_b_; - bool terminal_w_; }; } // namespace mcp4461 From 3e7f2924e00cc377273b2f4d445f0ee47cc4deec Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:22:48 +0100 Subject: [PATCH 35/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index daa032f7fd..1eef9f95a5 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -46,7 +46,7 @@ uint16_t Mcp4461Wiper::update_state() { return this->state_; } -void Mcp4461Wiper::save_level() { +/* void Mcp4461Wiper::save_level() { if (this->parent_->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); return; @@ -60,7 +60,7 @@ void Mcp4461Wiper::save_level() { this->parent_->reg_[nonvolatile_wiper_idx].state = this->parent_->reg_[wiper_idx].state; Mcp4461WiperIdx nonvolatile_wiper = static_cast(nonvolatile_wiper_idx); this->parent_->set_wiper_level_(nonvolatile_wiper, this->state_); -} +} */ void Mcp4461Wiper::enable_wiper() { if (this->parent_->is_failed()) { From 13af165d99dcfa5ec18e64c4858f3758e84507fe Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:23:09 +0100 Subject: [PATCH 36/54] Update mcp4461_output.h --- esphome/components/mcp4461/output/mcp4461_output.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index f4bac93eba..37aae1ae0f 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -14,7 +14,7 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented Date: Sun, 9 Feb 2025 18:28:29 +0100 Subject: [PATCH 37/54] Update mcp4461_output.cpp --- .../mcp4461/output/mcp4461_output.cpp | 93 +------------------ 1 file changed, 5 insertions(+), 88 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 1eef9f95a5..65cab2f831 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -8,35 +8,14 @@ namespace esphome { namespace mcp4461 { static const char *const TAG = "mcp4461.output"; -static const LogString *get_wiper_message_string(int status) { - switch (status) { - case Mcp4461Component::MCP4461_FAILED: - return LOG_STR("Parent MCP4461 component failed"); - case Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE: - return LOG_STR("Action prohibited for nonvolatile wiper"); - default: - return LOG_STR("Unknown error"); - } -} void Mcp4461Wiper::write_state(float state) { - if (this->parent_->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); - return; - } uint8_t wiper_idx = static_cast(this->wiper_); - ESP_LOGV(TAG, "Got value %02f from frontend", state); - const float max_taps = 256.0; state = state * 1000.0; - if (state > max_taps) { - ESP_LOGW(TAG, "Cannot set taps > 0.256 for wiper %" PRIu8 ", clamping to 0.256 !", wiper_idx); - state = 256.0; + uint16_t taps = static_cast(state); + if (this->parent_->set_wiper_level_(this->wiper_, taps)( { + this->state_ = state; } - uint16_t taps; - taps = static_cast(state); - ESP_LOGV(TAG, "Setting wiper %" PRIu8 " to value %" PRIu16 "", wiper_idx, taps); - this->state_ = state; - this->parent_->set_wiper_level_(this->wiper_, taps); } uint16_t Mcp4461Wiper::read_state() { return this->parent_->get_wiper_level_(this->wiper_); } @@ -46,93 +25,31 @@ uint16_t Mcp4461Wiper::update_state() { return this->state_; } -/* void Mcp4461Wiper::save_level() { - if (this->parent_->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); - return; - } - uint8_t wiper_idx = static_cast(this->wiper_); - if (wiper_idx > 3) { - ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); - return; - } - uint8_t nonvolatile_wiper_idx = wiper_idx + 4; - this->parent_->reg_[nonvolatile_wiper_idx].state = this->parent_->reg_[wiper_idx].state; - Mcp4461WiperIdx nonvolatile_wiper = static_cast(nonvolatile_wiper_idx); - this->parent_->set_wiper_level_(nonvolatile_wiper, this->state_); -} */ - void Mcp4461Wiper::enable_wiper() { - if (this->parent_->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); - return; - } - uint8_t wiper_idx = static_cast(this->wiper_); - this->parent_->enable_wiper_(this->wiper_); + this->parent_->enable_wiper_(static_cast(this->wiper_)); } void Mcp4461Wiper::disable_wiper() { - if (this->parent_->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); - return; - } - uint8_t wiper_idx = static_cast(this->wiper_); - this->parent_->disable_wiper_(this->wiper_); + this->parent_->disable_wiper_(static_cast(this->wiper_)); } void Mcp4461Wiper::increase_wiper() { - if (this->parent_->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); - return; - } - uint8_t wiper_idx = static_cast(this->wiper_); - if (wiper_idx > 3) { - ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); - return; - } if (this->parent_->increase_wiper_(this->wiper_)) { this->state_ = this->state_ + 1.0; } } void Mcp4461Wiper::decrease_wiper() { - if (this->parent_->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); - return; - } - uint8_t wiper_idx = static_cast(this->wiper_); - if (wiper_idx > 3) { - ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); - return; - } if (this->parent_->decrease_wiper_(this->wiper_)) { this->state_ = this->state_ - 1.0; } } void Mcp4461Wiper::enable_terminal(char terminal) { - if (this->parent_->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); - return; - } - uint8_t wiper_idx = static_cast(this->wiper_); - if (wiper_idx > 3) { - ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); - return; - } this->parent_->enable_terminal_(this->wiper_, terminal); } void Mcp4461Wiper::disable_terminal(char terminal) { - if (this->parent_->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED))); - return; - } - uint8_t wiper_idx = static_cast(this->wiper_); - if (wiper_idx > 3) { - ESP_LOGW(TAG, LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_PROHIBITED_FOR_NONVOLATILE))); - return; - } this->parent_->disable_terminal_(this->wiper_, terminal); } From 577b3e996d333e2dd0942cdf073b5eb927b21dcf Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:30:26 +0100 Subject: [PATCH 38/54] Update __init__.py --- esphome/components/mcp4461/output/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/mcp4461/output/__init__.py b/esphome/components/mcp4461/output/__init__.py index a337c8d579..e535037157 100644 --- a/esphome/components/mcp4461/output/__init__.py +++ b/esphome/components/mcp4461/output/__init__.py @@ -45,10 +45,10 @@ async def to_code(config): config[CONF_ID], parent, config[CONF_CHANNEL], - config[CONF_TERMINAL_A], - config[CONF_TERMINAL_B], - config[CONF_TERMINAL_W], ) + cg.add(parent.set_initial_terminal_state(config[CONF_CHANNEL], config[CONF_TERMINAL_A])) + cg.add(parent.set_initial_terminal_state(config[CONF_CHANNEL], config[CONF_TERMINAL_B])) + cg.add(parent.set_initial_terminal_state(config[CONF_CHANNEL], config[CONF_TERMINAL_W])) if CONF_INITIAL_VALUE in config: cg.add( parent.set_initial_value(config[CONF_CHANNEL], config[CONF_INITIAL_VALUE]) From 7140ff0645e5b84bdca0fdeacc3f756ea3a22f60 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:31:54 +0100 Subject: [PATCH 39/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 1 + 1 file changed, 1 insertion(+) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index f75513f590..ba7635eed8 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -78,6 +78,7 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { uint16_t get_eeprom_value(Mcp4461EepromLocation location); bool set_eeprom_value(Mcp4461EepromLocation location, uint16_t value); void set_initial_value(Mcp4461WiperIdx wiper, float initial_value); + void set_terminal_disabled(Mcp4461WiperIdx wiper, char terminal); enum ErrorCode { MCP4461_STATUS_OK = 0, // CMD completed successfully From fe11db696f67a03714df04eafa252e8ab6b3d0e4 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:35:01 +0100 Subject: [PATCH 40/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 0cb06165f8..0714680390 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -70,8 +70,20 @@ static const LogString *mcp4461_get_message_string(int status) { } void Mcp4461Component::set_initial_value(Mcp4461WiperIdx wiper, float initial_value) { - uint8_t wiper_id = static_cast(wiper); - this->reg_[wiper_id].initial_value = initial_value; + uint8_t wiper_idx = static_cast(wiper); + this->reg_[wiper_idx].initial_value = initial_value; +} + +void Mcp4461Component::set_terminal_disabled_on_start(Mcp4461WiperIdx wiper, char terminal) { + uint8_t wiper_idx = static_cast(wiper); + switch (terminal) { + case 'a': + this->reg_[wiper_idx].terminal_a = false; + case 'b': + this->reg_[wiper_idx].terminal_b = false; + case 'w': + this->reg_[wiper_idx].terminal_w = false; + } } void Mcp4461Component::update_write_protection_status_() { From 608304592d1f0fc655ecacb9643cb87d13b41d6a Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:35:19 +0100 Subject: [PATCH 41/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index ba7635eed8..6950711181 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -78,7 +78,7 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { uint16_t get_eeprom_value(Mcp4461EepromLocation location); bool set_eeprom_value(Mcp4461EepromLocation location, uint16_t value); void set_initial_value(Mcp4461WiperIdx wiper, float initial_value); - void set_terminal_disabled(Mcp4461WiperIdx wiper, char terminal); + void set_terminal_disabled_on_start(Mcp4461WiperIdx wiper, char terminal); enum ErrorCode { MCP4461_STATUS_OK = 0, // CMD completed successfully From 044eabe7f8dad70d1fbfc962457031cd6531eb47 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:35:50 +0100 Subject: [PATCH 42/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 6950711181..8928ee6a77 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -78,7 +78,7 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { uint16_t get_eeprom_value(Mcp4461EepromLocation location); bool set_eeprom_value(Mcp4461EepromLocation location, uint16_t value); void set_initial_value(Mcp4461WiperIdx wiper, float initial_value); - void set_terminal_disabled_on_start(Mcp4461WiperIdx wiper, char terminal); + void initialize_terminal_disabled(Mcp4461WiperIdx wiper, char terminal); enum ErrorCode { MCP4461_STATUS_OK = 0, // CMD completed successfully From ce5b192550c7c483f968361b4a83239c97913cbe Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:36:02 +0100 Subject: [PATCH 43/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 0714680390..ee39a2db6f 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -74,7 +74,7 @@ void Mcp4461Component::set_initial_value(Mcp4461WiperIdx wiper, float initial_va this->reg_[wiper_idx].initial_value = initial_value; } -void Mcp4461Component::set_terminal_disabled_on_start(Mcp4461WiperIdx wiper, char terminal) { +void Mcp4461Component::initialize_terminal_disabled(Mcp4461WiperIdx wiper, char terminal) { uint8_t wiper_idx = static_cast(wiper); switch (terminal) { case 'a': From 18242b71d762486bddedcafaef9575de51d44da7 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:38:36 +0100 Subject: [PATCH 44/54] Update __init__.py --- esphome/components/mcp4461/output/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/esphome/components/mcp4461/output/__init__.py b/esphome/components/mcp4461/output/__init__.py index e535037157..49ff806f0f 100644 --- a/esphome/components/mcp4461/output/__init__.py +++ b/esphome/components/mcp4461/output/__init__.py @@ -46,9 +46,12 @@ async def to_code(config): parent, config[CONF_CHANNEL], ) - cg.add(parent.set_initial_terminal_state(config[CONF_CHANNEL], config[CONF_TERMINAL_A])) - cg.add(parent.set_initial_terminal_state(config[CONF_CHANNEL], config[CONF_TERMINAL_B])) - cg.add(parent.set_initial_terminal_state(config[CONF_CHANNEL], config[CONF_TERMINAL_W])) + if not config[CONF_TERMINAL_A]: + cg.add(parent.initialize_terminal_disabled(config[CONF_CHANNEL], 'a')) + if not config[CONF_TERMINAL_B]: + cg.add(parent.initialize_terminal_disabled(config[CONF_CHANNEL], 'b')) + if not config[CONF_TERMINAL_W]: + cg.add(parent.initialize_terminal_disabled(config[CONF_CHANNEL], 'w')) if CONF_INITIAL_VALUE in config: cg.add( parent.set_initial_value(config[CONF_CHANNEL], config[CONF_INITIAL_VALUE]) From 87b9f67134aa4601b37565af6c7471b97623e7c9 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:41:56 +0100 Subject: [PATCH 45/54] Update mcp4461_output.h --- esphome/components/mcp4461/output/mcp4461_output.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index 37aae1ae0f..edc8f0071c 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -11,7 +11,7 @@ namespace mcp4461 { class Mcp4461Wiper : public output::FloatOutput, public Parented { public: Mcp4461Wiper(Mcp4461Component *parent, Mcp4461WiperIdx wiper) : parent_(parent), wiper_(wiper) {} - } + uint16_t read_state(); uint16_t update_state(); //void save_level(); From d6c3dbe1758091bcfad4f1a27d55f76bb1532124 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:46:34 +0100 Subject: [PATCH 46/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 65cab2f831..1eb238593d 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -10,10 +10,7 @@ namespace mcp4461 { static const char *const TAG = "mcp4461.output"; void Mcp4461Wiper::write_state(float state) { - uint8_t wiper_idx = static_cast(this->wiper_); - state = state * 1000.0; - uint16_t taps = static_cast(state); - if (this->parent_->set_wiper_level_(this->wiper_, taps)( { + if (this->parent_->set_wiper_level_(this->wiper_, static_cast(state * 1000))) { this->state_ = state; } } From 0b1a5fdeb8fcf1bcd5c842c5fd7ea4cc2ce96b9a Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:51:49 +0100 Subject: [PATCH 47/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 1eb238593d..880019c6e0 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -15,7 +15,7 @@ void Mcp4461Wiper::write_state(float state) { } } -uint16_t Mcp4461Wiper::read_state() { return this->parent_->get_wiper_level_(this->wiper_); } +float Mcp4461Wiper::read_state() { return (static_cast(this->parent_->get_wiper_level_(this->wiper_)) / 1000.0); } uint16_t Mcp4461Wiper::update_state() { this->state_ = this->read_state(); From 59ecddfe2a3aa2866daa2efbd6b023c306ff3b2f Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:53:47 +0100 Subject: [PATCH 48/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 880019c6e0..8362b4bb59 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -31,14 +31,16 @@ void Mcp4461Wiper::disable_wiper() { } void Mcp4461Wiper::increase_wiper() { + if (this->state_ == 0.256) { return; } if (this->parent_->increase_wiper_(this->wiper_)) { - this->state_ = this->state_ + 1.0; + this->state_ = this->state_ + 0.001; } } void Mcp4461Wiper::decrease_wiper() { + if (this->state_ == 0.000) { return; } if (this->parent_->decrease_wiper_(this->wiper_)) { - this->state_ = this->state_ - 1.0; + this->state_ = this->state_ - 0.001; } } From 0c7b644f268e2ffe248ead58f2a6d5dcb272cfc5 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:54:19 +0100 Subject: [PATCH 49/54] Update mcp4461_output.cpp --- esphome/components/mcp4461/output/mcp4461_output.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 8362b4bb59..1d53d3d659 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -31,14 +31,12 @@ void Mcp4461Wiper::disable_wiper() { } void Mcp4461Wiper::increase_wiper() { - if (this->state_ == 0.256) { return; } if (this->parent_->increase_wiper_(this->wiper_)) { this->state_ = this->state_ + 0.001; } } void Mcp4461Wiper::decrease_wiper() { - if (this->state_ == 0.000) { return; } if (this->parent_->decrease_wiper_(this->wiper_)) { this->state_ = this->state_ - 0.001; } From f897295db50093d868adee84e057edc548d77d84 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 18:58:26 +0100 Subject: [PATCH 50/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index ee39a2db6f..23809f85c5 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -366,6 +366,10 @@ bool Mcp4461Component::increase_wiper_(Mcp4461WiperIdx wiper) { ESP_LOGW(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(MCP4461_WIPER_LOCKED))); return false; } + if (this->reg_[wiper_idx].state == 256) { + ESP_LOGV(TAG, "%s", "Maximum wiper level reached, further increase of wiper %" PRIu8 " prohibited", wiper_idx); + return false; + } ESP_LOGV(TAG, "Increasing wiper %" PRIu8 "", wiper_idx); uint8_t reg = 0; uint8_t addr; @@ -396,6 +400,10 @@ bool Mcp4461Component::decrease_wiper_(Mcp4461WiperIdx wiper) { ESP_LOGW(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(MCP4461_WIPER_LOCKED))); return false; } + if (this->reg_[wiper_idx].state == 0) { + ESP_LOGV(TAG, "%s", "Minimum wiper level reached, further decrease of wiper %" PRIu8 " prohibited", wiper_idx); + return false; + } ESP_LOGV(TAG, "Decreasing wiper %" PRIu8 "", wiper_idx); uint8_t reg = 0; uint8_t addr; From 81871ecb9b66c62b0437616b95471ff0342de192 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 19:03:02 +0100 Subject: [PATCH 51/54] Update mcp4461_output.h --- esphome/components/mcp4461/output/mcp4461_output.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index edc8f0071c..226d01849e 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -12,8 +12,8 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented Date: Sun, 9 Feb 2025 19:06:09 +0100 Subject: [PATCH 52/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 23809f85c5..704e4245ae 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -256,43 +256,45 @@ uint16_t Mcp4461Component::read_wiper_level_(uint8_t wiper) { return buf; } -void Mcp4461Component::update_wiper_level_(Mcp4461WiperIdx wiper) { +bool Mcp4461Component::update_wiper_level_(Mcp4461WiperIdx wiper) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); - return; + return false; } uint8_t wiper_idx = static_cast(wiper); if (!(this->reg_[wiper_idx].enabled)) { ESP_LOGW(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(MCP4461_WIPER_DISABLED))); - return; + return false; } uint16_t data; data = this->get_wiper_level_(wiper); ESP_LOGV(TAG, "Got value %" PRIu16 " from wiper %" PRIu8, data, wiper_idx); this->reg_[wiper_idx].state = data; + return true; } -void Mcp4461Component::set_wiper_level_(Mcp4461WiperIdx wiper, uint16_t value) { +bool Mcp4461Component::set_wiper_level_(Mcp4461WiperIdx wiper, uint16_t value) { if (this->is_failed()) { ESP_LOGE(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(this->error_code_))); - return; + return false; } uint8_t wiper_idx = static_cast(wiper); if (value > 0x100) { ESP_LOGW(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(MCP4461_VALUE_INVALID))); - return; + return false; } if (!(this->reg_[wiper_idx].enabled)) { ESP_LOGW(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(MCP4461_WIPER_DISABLED))); - return; + return false; } if (this->reg_[wiper_idx].wiper_lock_active) { ESP_LOGW(TAG, "%s", LOG_STR_ARG(mcp4461_get_message_string(MCP4461_WIPER_LOCKED))); - return; + return false; } ESP_LOGV(TAG, "Setting MCP4461 wiper %" PRIu8 " to %" PRIu16 "!", wiper_idx, value); this->reg_[wiper_idx].state = value; this->reg_[wiper_idx].update_level = true; + return true; } void Mcp4461Component::write_wiper_level_(uint8_t wiper, uint16_t value) { From 48c67e96e87ef2f7c06c1dc51c225049c11c9d63 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 19:07:00 +0100 Subject: [PATCH 53/54] Update mcp4461.h --- esphome/components/mcp4461/mcp4461.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 8928ee6a77..6e53aa4a66 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -102,8 +102,8 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { uint16_t read_wiper_level_(uint8_t wiper); uint8_t get_status_register_(); uint16_t get_wiper_level_(Mcp4461WiperIdx wiper); - void set_wiper_level_(Mcp4461WiperIdx wiper, uint16_t value); - void update_wiper_level_(Mcp4461WiperIdx wiper); + bool set_wiper_level_(Mcp4461WiperIdx wiper, uint16_t value); + bool update_wiper_level_(Mcp4461WiperIdx wiper); void enable_wiper_(Mcp4461WiperIdx wiper); void disable_wiper_(Mcp4461WiperIdx wiper); bool increase_wiper_(Mcp4461WiperIdx wiper); From d377e768c750b4b4dfcc7e1ce4cb6a436b7e4cc9 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 9 Feb 2025 19:11:01 +0100 Subject: [PATCH 54/54] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 37 -------------------------- 1 file changed, 37 deletions(-) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 704e4245ae..36b2c245f2 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -616,20 +616,6 @@ bool Mcp4461Component::set_eeprom_value(Mcp4461EepromLocation location, uint16_t return true; } -/** - * @brief Checks if the EEPROM is currently writing. - * - * This function reads the MCP4461 status register to determine if an EEPROM write operation is in progress. - * If the EEPROM is no longer writing, the timeout flag (`last_eeprom_write_timed_out_`) - * is reset to allow normal operation in future calls of `is_eeprom_ready_for_writing_()`. - * - * Behavior: - * - If the EEPROM is **writing**, the function returns `true`. - * - If the EEPROM is **not writing**, the function returns `false` and resets `last_eeprom_write_timed_out_`. - * - * @return `true` if the EEPROM is currently writing. - * @return `false` if the EEPROM is not writing (also resets the timeout flag). - */ bool Mcp4461Component::is_writing_() { /* Read the EEPROM write-active status from the status register */ bool writing = static_cast((this->get_status_register_() >> 4) & 0x01); @@ -643,29 +629,6 @@ bool Mcp4461Component::is_writing_() { return writing; } -/** - * @brief Checks if the EEPROM is ready for a new write operation. - * - * This function ensures that the EEPROM is not actively writing. - * It can either return the current status immediately or wait until the EEPROM becomes ready. - * - * Behavior: - * - If `wait_if_not_ready` is `false`, the function returns the current readiness status immediately. - * - If `wait_if_not_ready` is `true`: - * - The function waits up to `EEPROM_WRITE_TIMEOUT_MS` for the EEPROM to become ready. - * - If the EEPROM remains busy after the timeout, the `last_eeprom_write_timed_out_` flag is set to `true`, - * preventing unnecessary waits in future calls. - * - If the EEPROM becomes ready within the timeout, the function returns `true`. - * - * @param[in] wait_if_not_ready Specifies whether to wait for EEPROM readiness if it is currently busy. - * - `true` → Waits for completion (up to `EEPROM_WRITE_TIMEOUT_MS`). - * - `false` → Returns the current readiness status without waiting. - * - * @return `true` if the EEPROM is ready for a new write. - * @return `false` if: - * - The last write attempt **timed out** (`wait_if_not_ready = true`). - * - The EEPROM is still busy (`wait_if_not_ready = false`). - */ bool Mcp4461Component::is_eeprom_ready_for_writing_(bool wait_if_not_ready) { /* Check initial write status */ bool ready_for_write = !this->is_writing_();