diff --git a/esphome/components/atm90e32/atm90e32.cpp b/esphome/components/atm90e32/atm90e32.cpp index f4c199cb98..412964d0f8 100644 --- a/esphome/components/atm90e32/atm90e32.cpp +++ b/esphome/components/atm90e32/atm90e32.cpp @@ -108,10 +108,14 @@ void ATM90E32Component::update() { #endif } +void ATM90E32Component::get_cs_summary_(std::span buffer) { + this->cs_->dump_summary(buffer.data(), buffer.size()); +} + void ATM90E32Component::setup() { this->spi_setup(); - this->cs_summary_ = this->cs_->dump_summary(); - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); uint16_t mmode0 = 0x87; // 3P4W 50Hz uint16_t high_thresh = 0; @@ -159,13 +163,13 @@ void ATM90E32Component::setup() { if (this->enable_offset_calibration_) { // Initialize flash storage for offset calibrations uint32_t o_hash = fnv1_hash("_offset_calibration_"); - o_hash = fnv1_hash_extend(o_hash, this->cs_summary_); + o_hash = fnv1_hash_extend(o_hash, cs); this->offset_pref_ = global_preferences->make_preference(o_hash, true); this->restore_offset_calibrations_(); // Initialize flash storage for power offset calibrations uint32_t po_hash = fnv1_hash("_power_offset_calibration_"); - po_hash = fnv1_hash_extend(po_hash, this->cs_summary_); + po_hash = fnv1_hash_extend(po_hash, cs); this->power_offset_pref_ = global_preferences->make_preference(po_hash, true); this->restore_power_offset_calibrations_(); } else { @@ -186,7 +190,7 @@ void ATM90E32Component::setup() { if (this->enable_gain_calibration_) { // Initialize flash storage for gain calibration uint32_t g_hash = fnv1_hash("_gain_calibration_"); - g_hash = fnv1_hash_extend(g_hash, this->cs_summary_); + g_hash = fnv1_hash_extend(g_hash, cs); this->gain_calibration_pref_ = global_preferences->make_preference(g_hash, true); this->restore_gain_calibrations_(); @@ -217,7 +221,8 @@ void ATM90E32Component::setup() { } void ATM90E32Component::log_calibration_status_() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); bool offset_mismatch = false; bool power_mismatch = false; @@ -568,7 +573,8 @@ float ATM90E32Component::get_chip_temperature_() { } void ATM90E32Component::run_gain_calibrations() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); if (!this->enable_gain_calibration_) { ESP_LOGW(TAG, "[CALIBRATION][%s] Gain calibration is disabled! Enable it first with enable_gain_calibration: true", cs); @@ -668,7 +674,8 @@ void ATM90E32Component::run_gain_calibrations() { } void ATM90E32Component::save_gain_calibration_to_memory_() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); bool success = this->gain_calibration_pref_.save(&this->gain_phase_); global_preferences->sync(); if (success) { @@ -681,7 +688,8 @@ void ATM90E32Component::save_gain_calibration_to_memory_() { } void ATM90E32Component::save_offset_calibration_to_memory_() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); bool success = this->offset_pref_.save(&this->offset_phase_); global_preferences->sync(); if (success) { @@ -697,7 +705,8 @@ void ATM90E32Component::save_offset_calibration_to_memory_() { } void ATM90E32Component::save_power_offset_calibration_to_memory_() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); bool success = this->power_offset_pref_.save(&this->power_offset_phase_); global_preferences->sync(); if (success) { @@ -713,7 +722,8 @@ void ATM90E32Component::save_power_offset_calibration_to_memory_() { } void ATM90E32Component::run_offset_calibrations() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); if (!this->enable_offset_calibration_) { ESP_LOGW(TAG, "[CALIBRATION][%s] Offset calibration is disabled! Enable it first with enable_offset_calibration: true", @@ -743,7 +753,8 @@ void ATM90E32Component::run_offset_calibrations() { } void ATM90E32Component::run_power_offset_calibrations() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); if (!this->enable_offset_calibration_) { ESP_LOGW( TAG, @@ -816,7 +827,8 @@ void ATM90E32Component::write_power_offsets_to_registers_(uint8_t phase, int16_t } void ATM90E32Component::restore_gain_calibrations_() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); for (uint8_t i = 0; i < 3; ++i) { this->config_gain_phase_[i].voltage_gain = this->phase_[i].voltage_gain_; this->config_gain_phase_[i].current_gain = this->phase_[i].ct_gain_; @@ -870,7 +882,8 @@ void ATM90E32Component::restore_gain_calibrations_() { } void ATM90E32Component::restore_offset_calibrations_() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); for (uint8_t i = 0; i < 3; ++i) this->config_offset_phase_[i] = this->offset_phase_[i]; @@ -912,7 +925,8 @@ void ATM90E32Component::restore_offset_calibrations_() { } void ATM90E32Component::restore_power_offset_calibrations_() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); for (uint8_t i = 0; i < 3; ++i) this->config_power_offset_phase_[i] = this->power_offset_phase_[i]; @@ -954,7 +968,8 @@ void ATM90E32Component::restore_power_offset_calibrations_() { } void ATM90E32Component::clear_gain_calibrations() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); if (!this->using_saved_calibrations_) { ESP_LOGI(TAG, "[CALIBRATION][%s] No stored gain calibrations to clear. Current values:", cs); ESP_LOGI(TAG, "[CALIBRATION][%s] ----------------------------------------------------------", cs); @@ -1003,7 +1018,8 @@ void ATM90E32Component::clear_gain_calibrations() { } void ATM90E32Component::clear_offset_calibrations() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); if (!this->restored_offset_calibration_) { ESP_LOGI(TAG, "[CALIBRATION][%s] No stored offset calibrations to clear. Current values:", cs); ESP_LOGI(TAG, "[CALIBRATION][%s] --------------------------------------------------------------", cs); @@ -1045,7 +1061,8 @@ void ATM90E32Component::clear_offset_calibrations() { } void ATM90E32Component::clear_power_offset_calibrations() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); if (!this->restored_power_offset_calibration_) { ESP_LOGI(TAG, "[CALIBRATION][%s] No stored power offsets to clear. Current values:", cs); ESP_LOGI(TAG, "[CALIBRATION][%s] ---------------------------------------------------------------------", cs); @@ -1120,7 +1137,8 @@ int16_t ATM90E32Component::calibrate_power_offset(uint8_t phase, bool reactive) } bool ATM90E32Component::verify_gain_writes_() { - const char *cs = this->cs_summary_.c_str(); + char cs[GPIO_SUMMARY_MAX_LEN]; + this->get_cs_summary_(cs); bool success = true; for (uint8_t phase = 0; phase < 3; phase++) { uint16_t read_voltage = this->read16_(voltage_gain_registers[phase]); diff --git a/esphome/components/atm90e32/atm90e32.h b/esphome/components/atm90e32/atm90e32.h index 938ce512ce..2524616470 100644 --- a/esphome/components/atm90e32/atm90e32.h +++ b/esphome/components/atm90e32/atm90e32.h @@ -1,11 +1,13 @@ #pragma once +#include #include #include "atm90e32_reg.h" #include "esphome/components/sensor/sensor.h" #include "esphome/components/spi/spi.h" #include "esphome/core/application.h" #include "esphome/core/component.h" +#include "esphome/core/gpio.h" #include "esphome/core/helpers.h" #include "esphome/core/preferences.h" @@ -182,6 +184,7 @@ class ATM90E32Component : public PollingComponent, bool verify_gain_writes_(); bool validate_spi_read_(uint16_t expected, const char *context = nullptr); void log_calibration_status_(); + void get_cs_summary_(std::span buffer); struct ATM90E32Phase { uint16_t voltage_gain_{0}; @@ -247,7 +250,6 @@ class ATM90E32Component : public PollingComponent, ESPPreferenceObject offset_pref_; ESPPreferenceObject power_offset_pref_; ESPPreferenceObject gain_calibration_pref_; - std::string cs_summary_; sensor::Sensor *freq_sensor_{nullptr}; #ifdef USE_TEXT_SENSOR diff --git a/esphome/components/mipi_rgb/mipi_rgb.cpp b/esphome/components/mipi_rgb/mipi_rgb.cpp index ef96da8a1c..d0e716bd24 100644 --- a/esphome/components/mipi_rgb/mipi_rgb.cpp +++ b/esphome/components/mipi_rgb/mipi_rgb.cpp @@ -1,9 +1,11 @@ #ifdef USE_ESP32_VARIANT_ESP32S3 #include "mipi_rgb.h" +#include "esphome/core/gpio.h" +#include "esphome/core/hal.h" #include "esphome/core/helpers.h" #include "esphome/core/log.h" -#include "esphome/core/hal.h" #include "esp_lcd_panel_rgb.h" +#include namespace esphome { namespace mipi_rgb { @@ -343,19 +345,27 @@ int MipiRgb::get_height() { } } -static std::string get_pin_name(GPIOPin *pin) { +static const char *get_pin_name(GPIOPin *pin, std::span buffer) { if (pin == nullptr) return "None"; - return pin->dump_summary(); + pin->dump_summary(buffer.data(), buffer.size()); + return buffer.data(); } void MipiRgb::dump_pins_(uint8_t start, uint8_t end, const char *name, uint8_t offset) { + char pin_summary[GPIO_SUMMARY_MAX_LEN]; for (uint8_t i = start; i != end; i++) { - ESP_LOGCONFIG(TAG, " %s pin %d: %s", name, offset++, this->data_pins_[i]->dump_summary().c_str()); + this->data_pins_[i]->dump_summary(pin_summary, sizeof(pin_summary)); + ESP_LOGCONFIG(TAG, " %s pin %d: %s", name, offset++, pin_summary); } } void MipiRgb::dump_config() { + char reset_buf[GPIO_SUMMARY_MAX_LEN]; + char de_buf[GPIO_SUMMARY_MAX_LEN]; + char pclk_buf[GPIO_SUMMARY_MAX_LEN]; + char hsync_buf[GPIO_SUMMARY_MAX_LEN]; + char vsync_buf[GPIO_SUMMARY_MAX_LEN]; ESP_LOGCONFIG(TAG, "MIPI_RGB LCD" "\n Model: %s" @@ -379,9 +389,9 @@ void MipiRgb::dump_config() { this->model_, this->width_, this->height_, this->rotation_, YESNO(this->pclk_inverted_), this->hsync_pulse_width_, this->hsync_back_porch_, this->hsync_front_porch_, this->vsync_pulse_width_, this->vsync_back_porch_, this->vsync_front_porch_, YESNO(this->invert_colors_), - (unsigned) (this->pclk_frequency_ / 1000000), get_pin_name(this->reset_pin_).c_str(), - get_pin_name(this->de_pin_).c_str(), get_pin_name(this->pclk_pin_).c_str(), - get_pin_name(this->hsync_pin_).c_str(), get_pin_name(this->vsync_pin_).c_str()); + (unsigned) (this->pclk_frequency_ / 1000000), get_pin_name(this->reset_pin_, reset_buf), + get_pin_name(this->de_pin_, de_buf), get_pin_name(this->pclk_pin_, pclk_buf), + get_pin_name(this->hsync_pin_, hsync_buf), get_pin_name(this->vsync_pin_, vsync_buf)); this->dump_pins_(8, 13, "Blue", 0); this->dump_pins_(13, 16, "Green", 0); diff --git a/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp b/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp index a81bb17dfc..363f4b63b8 100644 --- a/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp +++ b/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp @@ -1,5 +1,6 @@ #ifdef USE_ESP32_VARIANT_ESP32S3 #include "rpi_dpi_rgb.h" +#include "esphome/core/gpio.h" #include "esphome/core/log.h" namespace esphome { @@ -134,8 +135,11 @@ void RpiDpiRgb::dump_config() { LOG_PIN(" Enable Pin: ", this->enable_pin_); LOG_PIN(" Reset Pin: ", this->reset_pin_); size_t data_pin_count = sizeof(this->data_pins_) / sizeof(this->data_pins_[0]); - for (size_t i = 0; i != data_pin_count; i++) - ESP_LOGCONFIG(TAG, " Data pin %d: %s", i, (this->data_pins_[i])->dump_summary().c_str()); + char pin_summary[GPIO_SUMMARY_MAX_LEN]; + for (size_t i = 0; i != data_pin_count; i++) { + this->data_pins_[i]->dump_summary(pin_summary, sizeof(pin_summary)); + ESP_LOGCONFIG(TAG, " Data pin %d: %s", i, pin_summary); + } } void RpiDpiRgb::reset_display_() const { diff --git a/esphome/components/sensor/filter.cpp b/esphome/components/sensor/filter.cpp index 3adf28748d..375505a557 100644 --- a/esphome/components/sensor/filter.cpp +++ b/esphome/components/sensor/filter.cpp @@ -445,22 +445,18 @@ optional CalibratePolynomialFilter::new_value(float value) { ClampFilter::ClampFilter(float min, float max, bool ignore_out_of_range) : min_(min), max_(max), ignore_out_of_range_(ignore_out_of_range) {} optional ClampFilter::new_value(float value) { - if (std::isfinite(value)) { - if (std::isfinite(this->min_) && value < this->min_) { - if (this->ignore_out_of_range_) { - return {}; - } else { - return this->min_; - } + if (std::isfinite(this->min_) && !(value >= this->min_)) { + if (this->ignore_out_of_range_) { + return {}; } + return this->min_; + } - if (std::isfinite(this->max_) && value > this->max_) { - if (this->ignore_out_of_range_) { - return {}; - } else { - return this->max_; - } + if (std::isfinite(this->max_) && !(value <= this->max_)) { + if (this->ignore_out_of_range_) { + return {}; } + return this->max_; } return value; } diff --git a/esphome/components/st7701s/st7701s.cpp b/esphome/components/st7701s/st7701s.cpp index 6314c99fb0..221fe39b9d 100644 --- a/esphome/components/st7701s/st7701s.cpp +++ b/esphome/components/st7701s/st7701s.cpp @@ -1,5 +1,6 @@ #ifdef USE_ESP32_VARIANT_ESP32S3 #include "st7701s.h" +#include "esphome/core/gpio.h" #include "esphome/core/log.h" namespace esphome { @@ -183,8 +184,11 @@ void ST7701S::dump_config() { LOG_PIN(" DE Pin: ", this->de_pin_); LOG_PIN(" Reset Pin: ", this->reset_pin_); size_t data_pin_count = sizeof(this->data_pins_) / sizeof(this->data_pins_[0]); - for (size_t i = 0; i != data_pin_count; i++) - ESP_LOGCONFIG(TAG, " Data pin %d: %s", i, (this->data_pins_[i])->dump_summary().c_str()); + char pin_summary[GPIO_SUMMARY_MAX_LEN]; + for (size_t i = 0; i != data_pin_count; i++) { + this->data_pins_[i]->dump_summary(pin_summary, sizeof(pin_summary)); + ESP_LOGCONFIG(TAG, " Data pin %d: %s", i, pin_summary); + } ESP_LOGCONFIG(TAG, " SPI Data rate: %dMHz", (unsigned) (this->data_rate_ / 1000000)); } diff --git a/tests/components/template/common-base.yaml b/tests/components/template/common-base.yaml index afc3fd9819..9dc65fbab8 100644 --- a/tests/components/template/common-base.yaml +++ b/tests/components/template/common-base.yaml @@ -117,6 +117,7 @@ sensor: - 10.0 -> 12.1 - 13.0 -> 14.0 - clamp: + # Infinity and NaN will be clamped (NaN -> min_value, +Infinity -> max_value, -Infinity -> min_value) max_value: 10.0 min_value: -10.0 - debounce: 0.1s