1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-26 04:28:17 +00:00

Update mcp4461.cpp

This commit is contained in:
Oliver Kleinecke 2025-02-08 15:56:06 +01:00 committed by GitHub
parent f762d2c315
commit 1deba54baa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,7 +22,6 @@ void Mcp4461Component::setup() {
void Mcp4461Component::begin_() { void Mcp4461Component::begin_() {
// save WP/WL status // save WP/WL status
this->set_write_protection_status_(); this->set_write_protection_status_();
this->previous_write_exec_time_ = 0;
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
if (this->reg_[i].initial_value.has_value()) { if (this->reg_[i].initial_value.has_value()) {
uint16_t initial_state; uint16_t initial_state;
@ -212,7 +211,7 @@ uint16_t Mcp4461Component::read_wiper_level_(uint8_t wiper) {
reg |= this->get_wiper_address_(wiper); reg |= this->get_wiper_address_(wiper);
reg |= static_cast<uint8_t>(Mcp4461Commands::READ); reg |= static_cast<uint8_t>(Mcp4461Commands::READ);
if (wiper > 3) { if (wiper > 3) {
if (this->is_eeprom_ready_for_writing_(true)) { if (!this->is_eeprom_ready_for_writing_(true)) {
return 0; return 0;
} }
} }
@ -511,7 +510,7 @@ uint16_t Mcp4461Component::get_eeprom_value(Mcp4461EepromLocation location) {
reg |= static_cast<uint8_t>(Mcp4461EepromLocation::MCP4461_EEPROM_1) + (static_cast<uint8_t>(location) * 0x10); reg |= static_cast<uint8_t>(Mcp4461EepromLocation::MCP4461_EEPROM_1) + (static_cast<uint8_t>(location) * 0x10);
reg |= static_cast<uint8_t>(Mcp4461Commands::READ); reg |= static_cast<uint8_t>(Mcp4461Commands::READ);
uint16_t buf; uint16_t buf;
if (this->is_eeprom_ready_for_writing_(true)) { if (!this->is_eeprom_ready_for_writing_(true)) {
return 0; return 0;
} }
if (!this->read_byte_16(reg, &buf)) { if (!this->read_byte_16(reg, &buf)) {
@ -642,10 +641,9 @@ bool Mcp4461Component::mcp4461_write_(uint8_t addr, uint16_t data, bool nonvolat
ESP_LOGW(TAG, "Ignoring write to write protected chip"); ESP_LOGW(TAG, "Ignoring write to write protected chip");
return false; return false;
} }
if (this->is_eeprom_ready_for_writing_(true)) { if (!this->is_eeprom_ready_for_writing_(true)) {
return false; return false;
} }
this->previous_write_exec_time_ = millis();
} }
return this->write_byte(reg, value_byte); return this->write_byte(reg, value_byte);
} }