1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-13 22:28:14 +00:00

Merge pull request #13 from p1ngb4ck/mcp4461_dev

recent changes
This commit is contained in:
Oliver Kleinecke 2025-02-20 12:36:54 +01:00 committed by GitHub
commit a5e40134c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 20 deletions

View File

@ -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<uint16_t>(*this->reg_[i].initial_value * 1000.f);
initial_state = static_cast<uint16_t>(*this->reg_[i].initial_value * 256.0f);
this->write_wiper_level_(i, initial_state);
}
if (this->reg_[i].enabled) {

View File

@ -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};

View File

@ -38,7 +38,6 @@ class Mcp4461Wiper : public output::FloatOutput, public Parented<Mcp4461Componen
Mcp4461Component *parent_;
Mcp4461WiperIdx wiper_;
float state_;
optional<uint16_t> initial_value_;
};
} // namespace mcp4461