mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-28 08:48:27 +02:00
allow using a binary output for the status led (#4532)
* allow using a binary output for the status led * lint * output status as well * simplify --------- Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
@@ -15,10 +15,10 @@ void StatusLEDLightOutput::loop() {
|
||||
}
|
||||
|
||||
if ((new_state & STATUS_LED_ERROR) != 0u) {
|
||||
this->pin_->digital_write(millis() % 250u < 150u);
|
||||
this->output_state_(millis() % 250u < 150u);
|
||||
this->last_app_state_ = new_state;
|
||||
} else if ((new_state & STATUS_LED_WARNING) != 0u) {
|
||||
this->pin_->digital_write(millis() % 1500u < 250u);
|
||||
this->output_state_(millis() % 1500u < 250u);
|
||||
this->last_app_state_ = new_state;
|
||||
} else if (new_state != this->last_app_state_) {
|
||||
// if no error/warning -> restore light state or turn off
|
||||
@@ -26,17 +26,16 @@ void StatusLEDLightOutput::loop() {
|
||||
|
||||
if (lightstate_)
|
||||
lightstate_->current_values_as_binary(&state);
|
||||
|
||||
this->pin_->digital_write(state);
|
||||
this->last_app_state_ = new_state;
|
||||
|
||||
ESP_LOGD(TAG, "Restoring light state %s", ONOFF(state));
|
||||
|
||||
this->output_state_(state);
|
||||
this->last_app_state_ = new_state;
|
||||
}
|
||||
}
|
||||
|
||||
void StatusLEDLightOutput::setup_state(light::LightState *state) {
|
||||
lightstate_ = state;
|
||||
ESP_LOGD(TAG, "'%s': Setting initital state", state->get_name().c_str());
|
||||
ESP_LOGD(TAG, "'%s': Setting initial state", state->get_name().c_str());
|
||||
this->write_state(state);
|
||||
}
|
||||
|
||||
@@ -47,16 +46,18 @@ void StatusLEDLightOutput::write_state(light::LightState *state) {
|
||||
// if in warning/error, don't overwrite the status_led
|
||||
// once it is back to OK, the loop will restore the state
|
||||
if ((App.get_app_state() & (STATUS_LED_ERROR | STATUS_LED_WARNING)) == 0u) {
|
||||
this->pin_->digital_write(binary);
|
||||
ESP_LOGD(TAG, "'%s': Setting state %s", state->get_name().c_str(), ONOFF(binary));
|
||||
this->output_state_(binary);
|
||||
}
|
||||
}
|
||||
|
||||
void StatusLEDLightOutput::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Status LED...");
|
||||
|
||||
this->pin_->setup();
|
||||
this->pin_->digital_write(false);
|
||||
if (this->pin_ != nullptr) {
|
||||
this->pin_->setup();
|
||||
this->pin_->digital_write(false);
|
||||
}
|
||||
}
|
||||
|
||||
void StatusLEDLightOutput::dump_config() {
|
||||
@@ -64,5 +65,12 @@ void StatusLEDLightOutput::dump_config() {
|
||||
LOG_PIN(" Pin: ", this->pin_);
|
||||
}
|
||||
|
||||
void StatusLEDLightOutput::output_state_(bool state) {
|
||||
if (this->pin_ != nullptr)
|
||||
this->pin_->digital_write(state);
|
||||
if (this->output_ != nullptr)
|
||||
this->output_->set_state(state);
|
||||
}
|
||||
|
||||
} // namespace status_led
|
||||
} // namespace esphome
|
||||
|
||||
Reference in New Issue
Block a user