mirror of
https://github.com/esphome/esphome.git
synced 2025-03-13 22:28:14 +00:00
Update mcp4461.cpp
This commit is contained in:
parent
32fe8705b9
commit
8d1ed1184b
@ -13,7 +13,7 @@ void Mcp4461Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up mcp4461 using address (0x%02" PRIX8 ")...", this->address_);
|
||||
auto err = this->write(nullptr, 0);
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
@ -171,7 +171,7 @@ uint8_t Mcp4461Component::get_status_register_() {
|
||||
reg |= static_cast<uint8_t>(Mcp4461Commands::READ);
|
||||
uint16_t buf;
|
||||
if (!this->read_byte_16(reg, &buf)) {
|
||||
this->error_code = MCP4461_STATUS_REGISTER_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_REGISTER_ERROR;
|
||||
this->mark_failed();
|
||||
return 0;
|
||||
}
|
||||
@ -181,7 +181,7 @@ uint8_t Mcp4461Component::get_status_register_() {
|
||||
if (msb != 1 || ((lsb >> 7) & 0x01) != 1 || ((lsb >> 1) & 0x01) != 1) {
|
||||
// D8, D7 and R1 bits are hardlocked to 1 -> a status msb bit 0 (bit 9 of status register) of 0 or lsb bit 1/7 = 0
|
||||
// indicate device/communication issues, therefore mark component failed
|
||||
this->error_code = MCP4461_STATUS_REGISTER_INVALID;
|
||||
this->error_code_ = MCP4461_STATUS_REGISTER_INVALID;
|
||||
this->mark_failed();
|
||||
return 0;
|
||||
}
|
||||
@ -247,7 +247,7 @@ uint16_t Mcp4461Component::read_wiper_level_(uint8_t wiper) {
|
||||
}
|
||||
}
|
||||
if (!(this->read_byte_16(reg, &buf))) {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->status_set_warning();
|
||||
ESP_LOGW(TAG, "Error fetching %swiper %" PRIu8 " value", (wiper > 3) ? "nonvolatile " : "", wiper);
|
||||
return 0;
|
||||
@ -302,7 +302,7 @@ void Mcp4461Component::write_wiper_level_(uint8_t wiper, uint16_t value) {
|
||||
nonvolatile = true;
|
||||
}
|
||||
if (!(this->mcp4461_write_(this->get_wiper_address_(wiper), value, nonvolatile))) {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->status_set_warning();
|
||||
ESP_LOGW(TAG, "Error writing %swiper %" PRIu8 " level %" PRIu16 "", (wiper > 3) ? "nonvolatile " : "", wiper,
|
||||
value);
|
||||
@ -379,7 +379,7 @@ bool Mcp4461Component::increase_wiper_(Mcp4461WiperIdx wiper) {
|
||||
reg |= static_cast<uint8_t>(Mcp4461Commands::INCREMENT);
|
||||
auto err = this->write(&this->address_, reg, sizeof(reg));
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
@ -413,7 +413,7 @@ bool Mcp4461Component::decrease_wiper_(Mcp4461WiperIdx wiper) {
|
||||
reg |= static_cast<uint8_t>(Mcp4461Commands::DECREMENT);
|
||||
auto err = this->write(&this->address_, reg, sizeof(reg));
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
@ -461,7 +461,7 @@ uint8_t Mcp4461Component::get_terminal_register_(Mcp4461TerminalIdx terminal_con
|
||||
if (this->read_byte_16(reg, &buf)) {
|
||||
return static_cast<uint8_t>(buf & 0x00ff);
|
||||
} else {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->status_set_warning();
|
||||
ESP_LOGW(TAG, "Error fetching terminal register value");
|
||||
return 0;
|
||||
@ -511,7 +511,7 @@ bool Mcp4461Component::set_terminal_register_(Mcp4461TerminalIdx terminal_connec
|
||||
return false;
|
||||
}
|
||||
if (!(this->mcp4461_write_(addr, data))) {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
@ -585,7 +585,7 @@ uint16_t Mcp4461Component::get_eeprom_value(Mcp4461EepromLocation location) {
|
||||
return 0;
|
||||
}
|
||||
if (!this->read_byte_16(reg, &buf)) {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->status_set_warning();
|
||||
ESP_LOGW(TAG, "Error fetching EEPRom location value");
|
||||
return 0;
|
||||
@ -607,7 +607,7 @@ bool Mcp4461Component::set_eeprom_value(Mcp4461EepromLocation location, uint16_t
|
||||
}
|
||||
addr |= static_cast<uint8_t>(Mcp4461EepromLocation::MCP4461_EEPROM_1) + (static_cast<uint8_t>(location) * 0x10);
|
||||
if (!(this->mcp4461_write_(addr, value, true))) {
|
||||
this->error_code = MCP4461_STATUS_I2C_ERROR;
|
||||
this->error_code_ = MCP4461_STATUS_I2C_ERROR;
|
||||
this->status_set_warning();
|
||||
ESP_LOGW(TAG, "Error writing EEPRom value");
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user