[power_supply] Optimize logging, reduce flash footprint (#9923)

This commit is contained in:
Keith Burzinski 2025-07-27 00:54:10 -05:00 committed by GitHub
parent bcc56648c0
commit 14862904ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 9 deletions

View File

@ -13,14 +13,13 @@ void PowerSupply::setup() {
this->request_high_power();
}
void PowerSupply::dump_config() {
ESP_LOGCONFIG(TAG, "Power Supply:");
LOG_PIN(" Pin: ", this->pin_);
ESP_LOGCONFIG(TAG,
"Power Supply:\n"
" Time to enable: %" PRIu32 " ms\n"
" Keep on time: %.1f s",
this->enable_time_, this->keep_on_time_ / 1000.0f);
if (this->enable_on_boot_)
ESP_LOGCONFIG(TAG, " Enabled at startup: True");
" Keep on time: %" PRIu32 " s\n"
" Enable at startup: %s",
this->enable_time_, this->keep_on_time_ / 1000u, YESNO(this->enable_on_boot_));
LOG_PIN(" Pin: ", this->pin_);
}
float PowerSupply::get_setup_priority() const { return setup_priority::IO; }
@ -30,7 +29,7 @@ bool PowerSupply::is_enabled() const { return this->active_requests_ != 0; }
void PowerSupply::request_high_power() {
if (this->active_requests_ == 0) {
this->cancel_timeout("power-supply-off");
ESP_LOGD(TAG, "Enabling power supply.");
ESP_LOGV(TAG, "Enabling");
this->pin_->digital_write(true);
delay(this->enable_time_);
}
@ -45,7 +44,7 @@ void PowerSupply::unrequest_high_power() {
this->active_requests_--;
if (this->active_requests_ == 0) {
this->set_timeout("power-supply-off", this->keep_on_time_, [this]() {
ESP_LOGD(TAG, "Disabling power supply.");
ESP_LOGV(TAG, "Disabling");
this->pin_->digital_write(false);
});
}

View File

@ -36,10 +36,10 @@ class PowerSupply : public Component {
protected:
GPIOPin *pin_;
bool enable_on_boot_{false};
uint32_t enable_time_;
uint32_t keep_on_time_;
int16_t active_requests_{0}; // use signed integer to make catching negative requests easier.
bool enable_on_boot_{false};
};
class PowerSupplyRequester {