mirror of
https://github.com/esphome/esphome.git
synced 2025-04-13 14:20:29 +01:00
commit
266e7b1f8c
@ -52,8 +52,6 @@ static const LogString *mcp4461_get_message_string(int status) {
|
||||
return LOG_STR("Status register could not be read");
|
||||
case Mcp4461Component::MCP4461_STATUS_REGISTER_INVALID:
|
||||
return LOG_STR("Invalid status register value - bits 1,7 or 8 are 0");
|
||||
case Mcp4461Component::MCP4461_PARENT_FAILED:
|
||||
return LOG_STR("Parent component failed");
|
||||
case Mcp4461Component::MCP4461_VALUE_INVALID:
|
||||
return LOG_STR("Invalid value for wiper given");
|
||||
case Mcp4461Component::MCP4461_WRITE_PROTECTED:
|
||||
|
@ -93,11 +93,11 @@ class Mcp4461Component : public Component, public i2c::I2CDevice {
|
||||
|
||||
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_PARENT_FAILED, // Parent component failed
|
||||
MCP4461_VALUE_INVALID, // Invalid value given for wiper / eeprom
|
||||
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
|
||||
|
@ -8,11 +8,18 @@ namespace esphome {
|
||||
namespace mcp4461 {
|
||||
|
||||
static const char *const TAG = "mcp4461.output";
|
||||
static const LogString *const LOG_PARENT_FAILED_STR = LOG_STR("Parent MCP4461 component has failed! Aborting");
|
||||
static const LogString *get_wiper_message_string(int status) {
|
||||
switch (status) {
|
||||
case Mcp4461Component::MCP4461_FAILED:
|
||||
return LOG_STR("Parent MCP4461 component failed");
|
||||
default:
|
||||
return LOG_STR("Unknown error");
|
||||
}
|
||||
}
|
||||
|
||||
void Mcp4461Wiper::write_state(float state) {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(LOG_PARENT_FAILED_STR));
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED)));
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
@ -34,7 +41,7 @@ uint16_t Mcp4461Wiper::get_wiper_level() { return this->parent_->get_wiper_level
|
||||
|
||||
void Mcp4461Wiper::save_level() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(LOG_PARENT_FAILED_STR));
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED)));
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
@ -50,7 +57,7 @@ void Mcp4461Wiper::save_level() {
|
||||
|
||||
void Mcp4461Wiper::enable_wiper() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(LOG_PARENT_FAILED_STR));
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED)));
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
@ -63,7 +70,7 @@ void Mcp4461Wiper::enable_wiper() {
|
||||
|
||||
void Mcp4461Wiper::disable_wiper() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(LOG_PARENT_FAILED_STR));
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED)));
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
@ -76,7 +83,7 @@ void Mcp4461Wiper::disable_wiper() {
|
||||
|
||||
void Mcp4461Wiper::increase_wiper() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(LOG_PARENT_FAILED_STR));
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED)));
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
@ -91,7 +98,7 @@ void Mcp4461Wiper::increase_wiper() {
|
||||
|
||||
void Mcp4461Wiper::decrease_wiper() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(LOG_PARENT_FAILED_STR));
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED)));
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
@ -106,7 +113,7 @@ void Mcp4461Wiper::decrease_wiper() {
|
||||
|
||||
void Mcp4461Wiper::enable_terminal(char terminal) {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(LOG_PARENT_FAILED_STR));
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED)));
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
@ -119,7 +126,7 @@ void Mcp4461Wiper::enable_terminal(char terminal) {
|
||||
|
||||
void Mcp4461Wiper::disable_terminal(char terminal) {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(LOG_PARENT_FAILED_STR));
|
||||
ESP_LOGE(TAG, "%s", LOG_STR_ARG(get_wiper_message_string(Mcp4461Component::MCP4461_FAILED)));
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
|
Loading…
x
Reference in New Issue
Block a user