diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index f7971a5fbe..2251395d10 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -26,7 +26,7 @@ void Mcp4461Component::begin_() { for (uint8_t i = 0; i < 8; i++) { if (this->reg_[i].initial_value.has_value()) { uint16_t initial_state; - initial_state = static_cast(*this->reg_[i].initial_value * 1000.f); + initial_state = static_cast(*this->reg_[i].initial_value * 256.0f); this->write_wiper_level_(i, initial_state); } if (this->reg_[i].enabled) { diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 82bc1fe8b6..2a4dda0fee 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -8,6 +8,7 @@ namespace esphome { namespace mcp4461 { /// @brief Struct representing current wiper details/state +/// Default wiper state is 0x80h (128 int) struct WiperState { bool enabled = true; uint16_t state = 0; @@ -36,8 +37,8 @@ enum class Mcp4461Addresses : uint8_t { MCP4461_EEPROM_1 = 0xB0 }; -// @brief enumerate allowed channels/wipers -enum Mcp4461WiperIdx : uint8_t { +// @brief Class to enumerate allowed channels/wipers +enum class Mcp4461WiperIdx : uint8_t { MCP4461_WIPER_0 = 0, MCP4461_WIPER_1 = 1, MCP4461_WIPER_2 = 2, @@ -97,22 +98,6 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { /// @param[terminal] terminal to disable, one of { 'a', 'b', 'w', 'h' } void initialize_terminal_disabled(Mcp4461WiperIdx wiper, char terminal); - /// @brief enumerate required status codes - 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_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 - MCP4461_WIPER_LOCKED, // The wiper is locked using WiperLock-technology - all actions for this wiper will be - // aborted/discarded - } error_code_{MCP4461_STATUS_OK}; - protected: friend class Mcp4461Wiper; /// @brief update write protection status of device @@ -168,6 +153,22 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { /// @brief internal function to set terminal registers bool set_terminal_register_(Mcp4461TerminalIdx terminal_connector, uint8_t data); + /// @brief available/required status codes + 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_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 + MCP4461_WIPER_LOCKED, // The wiper is locked using WiperLock-technology - all actions for this wiper will be + // aborted/discarded + } error_code_{MCP4461_STATUS_OK}; + WiperState reg_[8]; void begin_(); bool last_eeprom_write_timed_out_{false}; diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index c8d7c53f79..4de67b069c 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -38,7 +38,6 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented initial_value_; }; } // namespace mcp4461