From 12420b2482d54edf5fa51cad12d1a7c1ab04950e Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Thu, 6 Feb 2025 15:58:09 +0100 Subject: [PATCH] Update mcp4461.cpp --- esphome/components/mcp4461/mcp4461.cpp | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 7436aca58e..a9c8df71d2 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -131,6 +131,10 @@ void Mcp4461Component::loop() { } uint8_t Mcp4461Component::get_status_register() { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Returning 0"); + return 0; + } uint8_t reg = 0; reg |= static_cast(Mcp4461Addresses::MCP4461_STATUS); reg |= static_cast(Mcp4461Commands::READ); @@ -183,6 +187,10 @@ uint8_t Mcp4461Component::get_wiper_address_(uint8_t wiper) { } uint16_t Mcp4461Component::get_wiper_level(Mcp4461WiperIdx wiper) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Returning 0"); + return 0; + } uint8_t wiper_idx = static_cast(wiper); if (!(this->reg_[wiper_idx].enabled)) { ESP_LOGW(TAG, "reading from disabled volatile wiper %" PRIu8 ", returning 0", wiper_idx); @@ -220,6 +228,10 @@ void Mcp4461Component::update_wiper_level(Mcp4461WiperIdx wiper) { } void Mcp4461Component::set_wiper_level(Mcp4461WiperIdx wiper, uint16_t value) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting write."); + return; + } uint8_t wiper_idx = static_cast(wiper); if (this->reg_[wiper_idx].wiper_lock_active) { ESP_LOGW(TAG, "Ignoring request to set the state for wiper %" PRIu8 " as it is locked by WiperLock", wiper_idx); @@ -252,6 +264,10 @@ void Mcp4461Component::write_wiper_level_(uint8_t wiper, uint16_t value) { } void Mcp4461Component::enable_wiper(Mcp4461WiperIdx wiper) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting"); + return; + } uint8_t wiper_idx = static_cast(wiper); ESP_LOGV(TAG, "Enabling wiper %" PRIu8, wiper_idx); this->reg_[wiper_idx].terminal_hw = true; @@ -259,6 +275,10 @@ void Mcp4461Component::enable_wiper(Mcp4461WiperIdx wiper) { } void Mcp4461Component::disable_wiper(Mcp4461WiperIdx wiper) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting"); + return; + } uint8_t wiper_idx = static_cast(wiper); ESP_LOGV(TAG, "Disabling wiper %" PRIu8, wiper_idx); this->reg_[wiper_idx].terminal_hw = false; @@ -266,6 +286,10 @@ void Mcp4461Component::disable_wiper(Mcp4461WiperIdx wiper) { } void Mcp4461Component::increase_wiper(Mcp4461WiperIdx wiper) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting"); + return; + } uint8_t wiper_idx = static_cast(wiper); if (this->reg_[wiper_idx].wiper_lock_active) { ESP_LOGW(TAG, "Ignoring request to increase wiper %" PRIu8 " as it is locked by WiperLock", wiper_idx); @@ -286,6 +310,10 @@ void Mcp4461Component::increase_wiper(Mcp4461WiperIdx wiper) { } void Mcp4461Component::decrease_wiper(Mcp4461WiperIdx wiper) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting"); + return; + } uint8_t wiper_idx = static_cast(wiper); if (this->reg_[wiper_idx].wiper_lock_active) { ESP_LOGW(TAG, "Ignoring request to decrease wiper %" PRIu8 " as it is locked by WiperLock", wiper_idx); @@ -330,6 +358,10 @@ uint8_t Mcp4461Component::calc_terminal_connector_byte_(Mcp4461TerminalIdx termi } uint8_t Mcp4461Component::get_terminal_register(Mcp4461TerminalIdx terminal_connector) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Returning 0"); + return 0; + } uint8_t reg = 0; if (static_cast(terminal_connector) == 0) { reg |= static_cast(Mcp4461Addresses::MCP4461_TCON0); @@ -373,6 +405,10 @@ void Mcp4461Component::update_terminal_register(Mcp4461TerminalIdx terminal_conn } void Mcp4461Component::set_terminal_register(Mcp4461TerminalIdx terminal_connector, uint8_t data) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting"); + return; + } uint8_t addr; if (static_cast(terminal_connector) == 0) { addr = static_cast(Mcp4461Addresses::MCP4461_TCON0); @@ -390,6 +426,10 @@ void Mcp4461Component::set_terminal_register(Mcp4461TerminalIdx terminal_connect } void Mcp4461Component::enable_terminal(Mcp4461WiperIdx wiper, char terminal) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting"); + return; + } uint8_t wiper_idx = static_cast(wiper); if (wiper_idx > 3) { return; @@ -417,6 +457,10 @@ void Mcp4461Component::enable_terminal(Mcp4461WiperIdx wiper, char terminal) { } void Mcp4461Component::disable_terminal(Mcp4461WiperIdx wiper, char terminal) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting"); + return; + } uint8_t wiper_idx = static_cast(wiper); if (wiper_idx > 3) { return; @@ -444,6 +488,10 @@ void Mcp4461Component::disable_terminal(Mcp4461WiperIdx wiper, char terminal) { } uint16_t Mcp4461Component::get_eeprom_value(Mcp4461EepromLocation location) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Returning 0"); + return 0; + } uint8_t reg = 0; reg |= static_cast(Mcp4461EepromLocation::MCP4461_EEPROM_1) + (static_cast(location) * 0x10); reg |= static_cast(Mcp4461Commands::READ); @@ -460,6 +508,10 @@ uint16_t Mcp4461Component::get_eeprom_value(Mcp4461EepromLocation location) { } void Mcp4461Component::set_eeprom_value(Mcp4461EepromLocation location, uint16_t value) { + if (this->parent_->is_failed()) { + ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting"); + return; + } uint8_t addr = 0; if (value > 511) { return;