mirror of
https://github.com/esphome/esphome.git
synced 2025-04-01 08:28:15 +01:00
Update mcp4461_output.cpp
This commit is contained in:
parent
12420b2482
commit
a499f1e446
@ -10,6 +10,10 @@ namespace mcp4461 {
|
||||
static const char *const TAG = "mcp4461.output";
|
||||
|
||||
void Mcp4461Wiper::write_state(float state) {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting");
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
ESP_LOGV(TAG, "Got value %02f from frontend", state);
|
||||
const float max_taps = 256.0;
|
||||
@ -26,6 +30,10 @@ void Mcp4461Wiper::write_state(float state) {
|
||||
}
|
||||
|
||||
void Mcp4461Wiper::set_initial_value(float initial_value) {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting");
|
||||
return;
|
||||
}
|
||||
if (initial_value >= 0.000 && initial_value <= 0.256) {
|
||||
this->initial_value_ = static_cast<uint16_t>(initial_value * 1000);
|
||||
// Use the value
|
||||
@ -40,17 +48,26 @@ void Mcp4461Wiper::set_initial_value(float initial_value) {
|
||||
uint16_t Mcp4461Wiper::get_wiper_level() { return this->parent_->get_wiper_level(this->wiper_); }
|
||||
|
||||
void Mcp4461Wiper::save_level() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting");
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
if (wiper_idx > 3) {
|
||||
ESP_LOGW(TAG, "Cannot save level for nonvolatile wiper %" PRIu8 " !", wiper_idx);
|
||||
return;
|
||||
}
|
||||
uint8_t nonvolatile_wiper_idx = wiper_idx + 4;
|
||||
this->parent_->reg[nonvolatile_wiper_idx].state = this->parent_->reg_[wiper_idx].state;
|
||||
Mcp4461WiperIdx nonvolatile_wiper = static_cast<Mcp4461WiperIdx>(nonvolatile_wiper_idx);
|
||||
this->parent_->set_wiper_level(nonvolatile_wiper, this->state_);
|
||||
}
|
||||
|
||||
void Mcp4461Wiper::enable_wiper() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting");
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
if (wiper_idx > 3) {
|
||||
ESP_LOGW(TAG, "Cannot enable nonvolatile wiper %" PRIu8 " !", wiper_idx);
|
||||
@ -69,20 +86,30 @@ void Mcp4461Wiper::disable_wiper() {
|
||||
}
|
||||
|
||||
void Mcp4461Wiper::increase_wiper() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting");
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
if (wiper_idx > 3) {
|
||||
ESP_LOGW(TAG, "Cannot increase nonvolatile wiper %" PRIu8 " !", wiper_idx);
|
||||
return;
|
||||
}
|
||||
this->state_ = this->state_ + 1.0;
|
||||
this->parent_->increase_wiper(this->wiper_);
|
||||
}
|
||||
|
||||
void Mcp4461Wiper::decrease_wiper() {
|
||||
if (this->parent_->is_failed()) {
|
||||
ESP_LOGW(TAG, "Parent MCP4461 component has failed! Aborting");
|
||||
return;
|
||||
}
|
||||
uint8_t wiper_idx = static_cast<uint8_t>(this->wiper_);
|
||||
if (wiper_idx > 3) {
|
||||
ESP_LOGW(TAG, "Cannot decrease nonvolatile wiper %" PRIu8 " !", wiper_idx);
|
||||
return;
|
||||
}
|
||||
this->state_ = this->state_ - 1.0;
|
||||
this->parent_->decrease_wiper(this->wiper_);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user