mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Merge remote-tracking branch 'origin/extract_helpers' into integration
This commit is contained in:
		| @@ -4,6 +4,7 @@ | |||||||
| #include "esphome/core/helpers.h" | #include "esphome/core/helpers.h" | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
| #include <cmath> | #include <cmath> | ||||||
|  | #include <numbers> | ||||||
|  |  | ||||||
| #ifdef USE_ESP8266 | #ifdef USE_ESP8266 | ||||||
| #include <core_esp8266_waveform.h> | #include <core_esp8266_waveform.h> | ||||||
| @@ -203,7 +204,7 @@ void AcDimmer::setup() { | |||||||
| #endif | #endif | ||||||
| } | } | ||||||
| void AcDimmer::write_state(float state) { | void AcDimmer::write_state(float state) { | ||||||
|   state = std::acos(1 - (2 * state)) / 3.14159;  // RMS power compensation |   state = std::acos(1 - (2 * state)) / std::numbers::pi;  // RMS power compensation | ||||||
|   auto new_value = static_cast<uint16_t>(roundf(state * 65535)); |   auto new_value = static_cast<uint16_t>(roundf(state * 65535)); | ||||||
|   if (new_value != 0 && this->store_.value == 0) |   if (new_value != 0 && this->store_.value == 0) | ||||||
|     this->store_.init_cycle = this->init_with_half_cycle_; |     this->store_.init_cycle = this->init_with_half_cycle_; | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| #include "atm90e32.h" | #include "atm90e32.h" | ||||||
| #include <cinttypes> | #include <cinttypes> | ||||||
| #include <cmath> | #include <cmath> | ||||||
|  | #include <numbers> | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| @@ -848,7 +849,7 @@ uint16_t ATM90E32Component::calculate_voltage_threshold(int line_freq, uint16_t | |||||||
|   float nominal_voltage = (line_freq == 60) ? 120.0f : 220.0f; |   float nominal_voltage = (line_freq == 60) ? 120.0f : 220.0f; | ||||||
|   float target_voltage = nominal_voltage * multiplier; |   float target_voltage = nominal_voltage * multiplier; | ||||||
|  |  | ||||||
|   float peak_01v = target_voltage * 100.0f * std::sqrt(2.0f);  // convert RMS → peak, scale to 0.01V |   float peak_01v = target_voltage * 100.0f * std::numbers::sqrt2_v<float>;  // convert RMS → peak, scale to 0.01V | ||||||
|   float divider = (2.0f * ugain) / 32768.0f; |   float divider = (2.0f * ugain) / 32768.0f; | ||||||
|  |  | ||||||
|   float threshold = peak_01v / divider; |   float threshold = peak_01v / divider; | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #include "display.h" | #include "display.h" | ||||||
| #include <utility> | #include <utility> | ||||||
|  | #include <numbers> | ||||||
| #include "display_color_utils.h" | #include "display_color_utils.h" | ||||||
| #include "esphome/core/hal.h" | #include "esphome/core/hal.h" | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
| @@ -424,15 +425,15 @@ void HOT Display::get_regular_polygon_vertex(int vertex_id, int *vertex_x, int * | |||||||
|     // hence we rotate the shape by 270° to orient the polygon up. |     // hence we rotate the shape by 270° to orient the polygon up. | ||||||
|     rotation_degrees += ROTATION_270_DEGREES; |     rotation_degrees += ROTATION_270_DEGREES; | ||||||
|     // Convert the rotation to radians, easier to use in trigonometrical calculations |     // Convert the rotation to radians, easier to use in trigonometrical calculations | ||||||
|     float rotation_radians = rotation_degrees * PI / 180; |     float rotation_radians = rotation_degrees * std::numbers::pi / 180; | ||||||
|     // A pointy top variation means the first vertex of the polygon is at the top center of the shape, this requires no |     // A pointy top variation means the first vertex of the polygon is at the top center of the shape, this requires no | ||||||
|     // additional rotation of the shape. |     // additional rotation of the shape. | ||||||
|     // A flat top variation means the first point of the polygon has to be rotated so that the first edge is horizontal, |     // A flat top variation means the first point of the polygon has to be rotated so that the first edge is horizontal, | ||||||
|     // this requires to rotate the shape by π/edges radians counter-clockwise so that the first point is located on the |     // this requires to rotate the shape by π/edges radians counter-clockwise so that the first point is located on the | ||||||
|     // left side of the first horizontal edge. |     // left side of the first horizontal edge. | ||||||
|     rotation_radians -= (variation == VARIATION_FLAT_TOP) ? PI / edges : 0.0; |     rotation_radians -= (variation == VARIATION_FLAT_TOP) ? std::numbers::pi / edges : 0.0; | ||||||
|  |  | ||||||
|     float vertex_angle = ((float) vertex_id) / edges * 2 * PI + rotation_radians; |     float vertex_angle = ((float) vertex_id) / edges * 2 * std::numbers::pi + rotation_radians; | ||||||
|     *vertex_x = (int) round(cos(vertex_angle) * radius) + center_x; |     *vertex_x = (int) round(cos(vertex_angle) * radius) + center_x; | ||||||
|     *vertex_y = (int) round(sin(vertex_angle) * radius) + center_y; |     *vertex_y = (int) round(sin(vertex_angle) * radius) + center_y; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -138,8 +138,6 @@ enum DisplayRotation { | |||||||
|   DISPLAY_ROTATION_270_DEGREES = 270, |   DISPLAY_ROTATION_270_DEGREES = 270, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #define PI 3.1415926535897932384626433832795 |  | ||||||
|  |  | ||||||
| const int EDGES_TRIGON = 3; | const int EDGES_TRIGON = 3; | ||||||
| const int EDGES_TRIANGLE = 3; | const int EDGES_TRIANGLE = 3; | ||||||
| const int EDGES_TETRAGON = 4; | const int EDGES_TETRAGON = 4; | ||||||
|   | |||||||
| @@ -704,7 +704,7 @@ FINAL_VALIDATE_SCHEMA = cv.Schema(final_validate) | |||||||
| async def to_code(config): | async def to_code(config): | ||||||
|     cg.add_platformio_option("board", config[CONF_BOARD]) |     cg.add_platformio_option("board", config[CONF_BOARD]) | ||||||
|     cg.add_platformio_option("board_upload.flash_size", config[CONF_FLASH_SIZE]) |     cg.add_platformio_option("board_upload.flash_size", config[CONF_FLASH_SIZE]) | ||||||
|     cg.set_cpp_standard("gnu++17") |     cg.set_cpp_standard("gnu++20") | ||||||
|     cg.add_build_flag("-DUSE_ESP32") |     cg.add_build_flag("-DUSE_ESP32") | ||||||
|     cg.add_define("ESPHOME_BOARD", config[CONF_BOARD]) |     cg.add_define("ESPHOME_BOARD", config[CONF_BOARD]) | ||||||
|     cg.add_build_flag(f"-DUSE_ESP32_VARIANT_{config[CONF_VARIANT]}") |     cg.add_build_flag(f"-DUSE_ESP32_VARIANT_{config[CONF_VARIANT]}") | ||||||
|   | |||||||
| @@ -183,7 +183,7 @@ async def to_code(config): | |||||||
|  |  | ||||||
|     cg.add_platformio_option("board", config[CONF_BOARD]) |     cg.add_platformio_option("board", config[CONF_BOARD]) | ||||||
|     cg.add_build_flag("-DUSE_ESP8266") |     cg.add_build_flag("-DUSE_ESP8266") | ||||||
|     cg.set_cpp_standard("gnu++17") |     cg.set_cpp_standard("gnu++20") | ||||||
|     cg.add_define("ESPHOME_BOARD", config[CONF_BOARD]) |     cg.add_define("ESPHOME_BOARD", config[CONF_BOARD]) | ||||||
|     cg.add_define("ESPHOME_VARIANT", "ESP8266") |     cg.add_define("ESPHOME_VARIANT", "ESP8266") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -129,9 +129,9 @@ void IRAM_ATTR ISRInternalGPIOPin::digital_write(bool value) { | |||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|     if (value != arg->inverted) { |     if (value != arg->inverted) { | ||||||
|       *arg->out_set_reg |= 1; |       *arg->out_set_reg = *arg->out_set_reg | 1; | ||||||
|     } else { |     } else { | ||||||
|       *arg->out_set_reg &= ~1; |       *arg->out_set_reg = *arg->out_set_reg & ~1; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @@ -147,7 +147,7 @@ void IRAM_ATTR ISRInternalGPIOPin::pin_mode(gpio::Flags flags) { | |||||||
|     if (flags & gpio::FLAG_OUTPUT) { |     if (flags & gpio::FLAG_OUTPUT) { | ||||||
|       *arg->mode_set_reg = arg->mask; |       *arg->mode_set_reg = arg->mask; | ||||||
|       if (flags & gpio::FLAG_OPEN_DRAIN) { |       if (flags & gpio::FLAG_OPEN_DRAIN) { | ||||||
|         *arg->control_reg |= 1 << GPCD; |         *arg->control_reg = *arg->control_reg | (1 << GPCD); | ||||||
|       } else { |       } else { | ||||||
|         *arg->control_reg &= ~(1 << GPCD); |         *arg->control_reg &= ~(1 << GPCD); | ||||||
|       } |       } | ||||||
| @@ -155,21 +155,21 @@ void IRAM_ATTR ISRInternalGPIOPin::pin_mode(gpio::Flags flags) { | |||||||
|       *arg->mode_clr_reg = arg->mask; |       *arg->mode_clr_reg = arg->mask; | ||||||
|     } |     } | ||||||
|     if (flags & gpio::FLAG_PULLUP) { |     if (flags & gpio::FLAG_PULLUP) { | ||||||
|       *arg->func_reg |= 1 << GPFPU; |       *arg->func_reg = *arg->func_reg | (1 << GPFPU); | ||||||
|       *arg->control_reg |= 1 << GPCD; |       *arg->control_reg = *arg->control_reg | (1 << GPCD); | ||||||
|     } else { |     } else { | ||||||
|       *arg->func_reg &= ~(1 << GPFPU); |       *arg->func_reg = *arg->func_reg & ~(1 << GPFPU); | ||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|     if (flags & gpio::FLAG_OUTPUT) { |     if (flags & gpio::FLAG_OUTPUT) { | ||||||
|       *arg->mode_set_reg |= 1; |       *arg->mode_set_reg = *arg->mode_set_reg | 1; | ||||||
|     } else { |     } else { | ||||||
|       *arg->mode_set_reg &= ~1; |       *arg->mode_set_reg = *arg->mode_set_reg & ~1; | ||||||
|     } |     } | ||||||
|     if (flags & gpio::FLAG_PULLDOWN) { |     if (flags & gpio::FLAG_PULLDOWN) { | ||||||
|       *arg->func_reg |= 1 << GP16FPD; |       *arg->func_reg = *arg->func_reg | (1 << GP16FPD); | ||||||
|     } else { |     } else { | ||||||
|       *arg->func_reg &= ~(1 << GP16FPD); |       *arg->func_reg = *arg->func_reg & ~(1 << GP16FPD); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -41,6 +41,6 @@ CONFIG_SCHEMA = cv.All( | |||||||
| async def to_code(config): | async def to_code(config): | ||||||
|     cg.add_build_flag("-DUSE_HOST") |     cg.add_build_flag("-DUSE_HOST") | ||||||
|     cg.add_define("USE_ESPHOME_HOST_MAC_ADDRESS", config[CONF_MAC_ADDRESS].parts) |     cg.add_define("USE_ESPHOME_HOST_MAC_ADDRESS", config[CONF_MAC_ADDRESS].parts) | ||||||
|     cg.add_build_flag("-std=gnu++17") |     cg.add_build_flag("-std=gnu++20") | ||||||
|     cg.add_define("ESPHOME_BOARD", "host") |     cg.add_define("ESPHOME_BOARD", "host") | ||||||
|     cg.add_platformio_option("platform", "platformio/native") |     cg.add_platformio_option("platform", "platformio/native") | ||||||
|   | |||||||
| @@ -258,7 +258,7 @@ bool OtaHttpRequestComponent::http_get_md5_() { | |||||||
| } | } | ||||||
|  |  | ||||||
| bool OtaHttpRequestComponent::validate_url_(const std::string &url) { | bool OtaHttpRequestComponent::validate_url_(const std::string &url) { | ||||||
|   if ((url.length() < 8) || (url.find("http") != 0) || (url.find("://") == std::string::npos)) { |   if ((url.length() < 8) || !url.starts_with("http") || (url.find("://") == std::string::npos)) { | ||||||
|     ESP_LOGE(TAG, "URL is invalid and/or must be prefixed with 'http://' or 'https://'"); |     ESP_LOGE(TAG, "URL is invalid and/or must be prefixed with 'http://' or 'https://'"); | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -159,12 +159,6 @@ void HydreonRGxxComponent::schedule_reboot_() { | |||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool HydreonRGxxComponent::buffer_starts_with_(const std::string &prefix) { |  | ||||||
|   return this->buffer_starts_with_(prefix.c_str()); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool HydreonRGxxComponent::buffer_starts_with_(const char *prefix) { return buffer_.rfind(prefix, 0) == 0; } |  | ||||||
|  |  | ||||||
| void HydreonRGxxComponent::process_line_() { | void HydreonRGxxComponent::process_line_() { | ||||||
|   ESP_LOGV(TAG, "Read from serial: %s", this->buffer_.substr(0, this->buffer_.size() - 2).c_str()); |   ESP_LOGV(TAG, "Read from serial: %s", this->buffer_.substr(0, this->buffer_.size() - 2).c_str()); | ||||||
|  |  | ||||||
| @@ -191,7 +185,7 @@ void HydreonRGxxComponent::process_line_() { | |||||||
|     ESP_LOGW(TAG, "Received EmSat!"); |     ESP_LOGW(TAG, "Received EmSat!"); | ||||||
|     this->em_sat_ = true; |     this->em_sat_ = true; | ||||||
|   } |   } | ||||||
|   if (this->buffer_starts_with_("PwrDays")) { |   if (buffer_.starts_with("PwrDays")) { | ||||||
|     if (this->boot_count_ <= 0) { |     if (this->boot_count_ <= 0) { | ||||||
|       this->boot_count_ = 1; |       this->boot_count_ = 1; | ||||||
|     } else { |     } else { | ||||||
| @@ -220,7 +214,7 @@ void HydreonRGxxComponent::process_line_() { | |||||||
|     } |     } | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   if (this->buffer_starts_with_("SW")) { |   if (buffer_.starts_with("SW")) { | ||||||
|     std::string::size_type majend = this->buffer_.find('.'); |     std::string::size_type majend = this->buffer_.find('.'); | ||||||
|     std::string::size_type endversion = this->buffer_.find(' ', 3); |     std::string::size_type endversion = this->buffer_.find(' ', 3); | ||||||
|     if (majend == std::string::npos || endversion == std::string::npos || majend > endversion) { |     if (majend == std::string::npos || endversion == std::string::npos || majend > endversion) { | ||||||
| @@ -282,7 +276,7 @@ void HydreonRGxxComponent::process_line_() { | |||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|     for (const auto *ignore : IGNORE_STRINGS) { |     for (const auto *ignore : IGNORE_STRINGS) { | ||||||
|       if (this->buffer_starts_with_(ignore)) { |       if (buffer_.starts_with(ignore)) { | ||||||
|         ESP_LOGI(TAG, "Ignoring %s", this->buffer_.substr(0, this->buffer_.size() - 2).c_str()); |         ESP_LOGI(TAG, "Ignoring %s", this->buffer_.substr(0, this->buffer_.size() - 2).c_str()); | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -264,7 +264,7 @@ async def component_to_code(config): | |||||||
|     # force using arduino framework |     # force using arduino framework | ||||||
|     cg.add_platformio_option("framework", "arduino") |     cg.add_platformio_option("framework", "arduino") | ||||||
|     cg.add_build_flag("-DUSE_ARDUINO") |     cg.add_build_flag("-DUSE_ARDUINO") | ||||||
|     cg.set_cpp_standard("gnu++17") |     cg.set_cpp_standard("gnu++20") | ||||||
|  |  | ||||||
|     # disable library compatibility checks |     # disable library compatibility checks | ||||||
|     cg.add_platformio_option("lib_ldf_mode", "off") |     cg.add_platformio_option("lib_ldf_mode", "off") | ||||||
|   | |||||||
| @@ -344,7 +344,7 @@ void OnlineImage::end_connection_() { | |||||||
| } | } | ||||||
|  |  | ||||||
| bool OnlineImage::validate_url_(const std::string &url) { | bool OnlineImage::validate_url_(const std::string &url) { | ||||||
|   if ((url.length() < 8) || (url.find("http") != 0) || (url.find("://") == std::string::npos)) { |   if ((url.length() < 8) || !url.starts_with("http") || (url.find("://") == std::string::npos)) { | ||||||
|     ESP_LOGE(TAG, "URL is invalid and/or must be prefixed with 'http://' or 'https://'"); |     ESP_LOGE(TAG, "URL is invalid and/or must be prefixed with 'http://' or 'https://'"); | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -63,7 +63,7 @@ void PulseMeterSensor::loop() { | |||||||
|   // If an edge was peeked, repay the debt |   // If an edge was peeked, repay the debt | ||||||
|   if (this->peeked_edge_ && this->get_->count_ > 0) { |   if (this->peeked_edge_ && this->get_->count_ > 0) { | ||||||
|     this->peeked_edge_ = false; |     this->peeked_edge_ = false; | ||||||
|     this->get_->count_--; |     this->get_->count_--;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // If there is an unprocessed edge, and filter_us_ has passed since, count this edge early |   // If there is an unprocessed edge, and filter_us_ has passed since, count this edge early | ||||||
| @@ -71,7 +71,7 @@ void PulseMeterSensor::loop() { | |||||||
|       now - this->get_->last_rising_edge_us_ >= this->filter_us_) { |       now - this->get_->last_rising_edge_us_ >= this->filter_us_) { | ||||||
|     this->peeked_edge_ = true; |     this->peeked_edge_ = true; | ||||||
|     this->get_->last_detected_edge_us_ = this->get_->last_rising_edge_us_; |     this->get_->last_detected_edge_us_ = this->get_->last_rising_edge_us_; | ||||||
|     this->get_->count_++; |     this->get_->count_++;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Check if we detected a pulse this loop |   // Check if we detected a pulse this loop | ||||||
| @@ -146,7 +146,7 @@ void IRAM_ATTR PulseMeterSensor::edge_intr(PulseMeterSensor *sensor) { | |||||||
|     state.last_sent_edge_us_ = now; |     state.last_sent_edge_us_ = now; | ||||||
|     set.last_detected_edge_us_ = now; |     set.last_detected_edge_us_ = now; | ||||||
|     set.last_rising_edge_us_ = now; |     set.last_rising_edge_us_ = now; | ||||||
|     set.count_++; |     set.count_++;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // This ISR is bound to rising edges, so the pin is high |   // This ISR is bound to rising edges, so the pin is high | ||||||
| @@ -169,7 +169,7 @@ void IRAM_ATTR PulseMeterSensor::pulse_intr(PulseMeterSensor *sensor) { | |||||||
|   } else if (length && !state.latched_ && sensor->last_pin_val_) {  // Long enough high edge |   } else if (length && !state.latched_ && sensor->last_pin_val_) {  // Long enough high edge | ||||||
|     state.latched_ = true; |     state.latched_ = true; | ||||||
|     set.last_detected_edge_us_ = state.last_intr_; |     set.last_detected_edge_us_ = state.last_intr_; | ||||||
|     set.count_++; |     set.count_++;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Due to order of operations this includes |   // Due to order of operations this includes | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ bool RadonEyeListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device | |||||||
|  |  | ||||||
|     // Check if the device name starts with any of the prefixes |     // Check if the device name starts with any of the prefixes | ||||||
|     if (std::any_of(prefixes.begin(), prefixes.end(), |     if (std::any_of(prefixes.begin(), prefixes.end(), | ||||||
|                     [&](const std::string &prefix) { return device.get_name().rfind(prefix, 0) == 0; })) { |                     [&](const std::string &prefix) { return device.get_name().starts_with(prefix); })) { | ||||||
|       // Device found |       // Device found | ||||||
|       ESP_LOGD(TAG, "Found Radon Eye device Name: %s (MAC: %s)", device.get_name().c_str(), |       ESP_LOGD(TAG, "Found Radon Eye device Name: %s (MAC: %s)", device.get_name().c_str(), | ||||||
|                device.address_str().c_str()); |                device.address_str().c_str()); | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ void IRAM_ATTR HOT RemoteReceiverComponentStore::gpio_intr(RemoteReceiverCompone | |||||||
|   if (time_since_change <= arg->filter_us) |   if (time_since_change <= arg->filter_us) | ||||||
|     return; |     return; | ||||||
|  |  | ||||||
|   arg->buffer[arg->buffer_write_at = next] = now; |   arg->buffer[arg->buffer_write_at = next] = now;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
| } | } | ||||||
|  |  | ||||||
| void RemoteReceiverComponent::setup() { | void RemoteReceiverComponent::setup() { | ||||||
|   | |||||||
| @@ -167,7 +167,7 @@ async def to_code(config): | |||||||
|     cg.add_platformio_option("lib_ldf_mode", "chain+") |     cg.add_platformio_option("lib_ldf_mode", "chain+") | ||||||
|     cg.add_platformio_option("board", config[CONF_BOARD]) |     cg.add_platformio_option("board", config[CONF_BOARD]) | ||||||
|     cg.add_build_flag("-DUSE_RP2040") |     cg.add_build_flag("-DUSE_RP2040") | ||||||
|     cg.set_cpp_standard("gnu++17") |     cg.set_cpp_standard("gnu++20") | ||||||
|     cg.add_define("ESPHOME_BOARD", config[CONF_BOARD]) |     cg.add_define("ESPHOME_BOARD", config[CONF_BOARD]) | ||||||
|     cg.add_define("ESPHOME_VARIANT", "RP2040") |     cg.add_define("ESPHOME_VARIANT", "RP2040") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #include "sn74hc595.h" | #include "sn74hc595.h" | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
|  | #include <ranges> | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace sn74hc595 { | namespace sn74hc595 { | ||||||
| @@ -55,9 +56,9 @@ void SN74HC595Component::digital_write_(uint16_t pin, bool value) { | |||||||
| } | } | ||||||
|  |  | ||||||
| void SN74HC595GPIOComponent::write_gpio() { | void SN74HC595GPIOComponent::write_gpio() { | ||||||
|   for (auto byte = this->output_bytes_.rbegin(); byte != this->output_bytes_.rend(); byte++) { |   for (uint8_t &output_byte : std::ranges::reverse_view(this->output_bytes_)) { | ||||||
|     for (int8_t i = 7; i >= 0; i--) { |     for (int8_t i = 7; i >= 0; i--) { | ||||||
|       bool bit = (*byte >> i) & 1; |       bool bit = (output_byte >> i) & 1; | ||||||
|       this->data_pin_->digital_write(bit); |       this->data_pin_->digital_write(bit); | ||||||
|       this->clock_pin_->digital_write(true); |       this->clock_pin_->digital_write(true); | ||||||
|       this->clock_pin_->digital_write(false); |       this->clock_pin_->digital_write(false); | ||||||
| @@ -68,9 +69,9 @@ void SN74HC595GPIOComponent::write_gpio() { | |||||||
|  |  | ||||||
| #ifdef USE_SPI | #ifdef USE_SPI | ||||||
| void SN74HC595SPIComponent::write_gpio() { | void SN74HC595SPIComponent::write_gpio() { | ||||||
|   for (auto byte = this->output_bytes_.rbegin(); byte != this->output_bytes_.rend(); byte++) { |   for (uint8_t &output_byte : std::ranges::reverse_view(this->output_bytes_)) { | ||||||
|     this->enable(); |     this->enable(); | ||||||
|     this->transfer_byte(*byte); |     this->transfer_byte(output_byte); | ||||||
|     this->disable(); |     this->disable(); | ||||||
|   } |   } | ||||||
|   SN74HC595Component::write_gpio(); |   SN74HC595Component::write_gpio(); | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #include "sun.h" | #include "sun.h" | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
|  | #include <numbers> | ||||||
|  |  | ||||||
| /* | /* | ||||||
| The formulas/algorithms in this module are based on the book | The formulas/algorithms in this module are based on the book | ||||||
| @@ -18,14 +19,12 @@ using namespace esphome::sun::internal; | |||||||
|  |  | ||||||
| static const char *const TAG = "sun"; | static const char *const TAG = "sun"; | ||||||
|  |  | ||||||
| #undef PI |  | ||||||
| #undef degrees | #undef degrees | ||||||
| #undef radians | #undef radians | ||||||
| #undef sq | #undef sq | ||||||
|  |  | ||||||
| static const num_t PI = 3.141592653589793; | inline num_t degrees(num_t rad) { return rad * 180 / std::numbers::pi; } | ||||||
| inline num_t degrees(num_t rad) { return rad * 180 / PI; } | inline num_t radians(num_t deg) { return deg * std::numbers::pi / 180; } | ||||||
| inline num_t radians(num_t deg) { return deg * PI / 180; } |  | ||||||
| inline num_t arcdeg(num_t deg, num_t minutes, num_t seconds) { return deg + minutes / 60 + seconds / 3600; } | inline num_t arcdeg(num_t deg, num_t minutes, num_t seconds) { return deg + minutes / 60 + seconds / 3600; } | ||||||
| inline num_t sq(num_t x) { return x * x; } | inline num_t sq(num_t x) { return x * x; } | ||||||
| inline num_t cb(num_t x) { return x * x * x; } | inline num_t cb(num_t x) { return x * x * x; } | ||||||
|   | |||||||
| @@ -152,7 +152,7 @@ void IRAM_ATTR Tx20ComponentStore::gpio_intr(Tx20ComponentStore *arg) { | |||||||
|     } |     } | ||||||
|     arg->buffer[arg->buffer_index] = 1; |     arg->buffer[arg->buffer_index] = 1; | ||||||
|     arg->start_time = now; |     arg->start_time = now; | ||||||
|     arg->buffer_index++; |     arg->buffer_index++;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   const uint32_t delay = now - arg->start_time; |   const uint32_t delay = now - arg->start_time; | ||||||
| @@ -183,7 +183,7 @@ void IRAM_ATTR Tx20ComponentStore::gpio_intr(Tx20ComponentStore *arg) { | |||||||
|   } |   } | ||||||
|   arg->spent_time += delay; |   arg->spent_time += delay; | ||||||
|   arg->start_time = now; |   arg->start_time = now; | ||||||
|   arg->buffer_index++; |   arg->buffer_index++;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
| } | } | ||||||
| void IRAM_ATTR Tx20ComponentStore::reset() { | void IRAM_ATTR Tx20ComponentStore::reset() { | ||||||
|   tx20_available = false; |   tx20_available = false; | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ static const char *const KEYS = "0123456789*#"; | |||||||
| void IRAM_ATTR HOT WiegandStore::d0_gpio_intr(WiegandStore *arg) { | void IRAM_ATTR HOT WiegandStore::d0_gpio_intr(WiegandStore *arg) { | ||||||
|   if (arg->d0.digital_read()) |   if (arg->d0.digital_read()) | ||||||
|     return; |     return; | ||||||
|   arg->count++; |   arg->count++;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
|   arg->value <<= 1; |   arg->value <<= 1; | ||||||
|   arg->last_bit_time = millis(); |   arg->last_bit_time = millis(); | ||||||
|   arg->done = false; |   arg->done = false; | ||||||
| @@ -20,7 +20,7 @@ void IRAM_ATTR HOT WiegandStore::d0_gpio_intr(WiegandStore *arg) { | |||||||
| void IRAM_ATTR HOT WiegandStore::d1_gpio_intr(WiegandStore *arg) { | void IRAM_ATTR HOT WiegandStore::d1_gpio_intr(WiegandStore *arg) { | ||||||
|   if (arg->d1.digital_read()) |   if (arg->d1.digital_read()) | ||||||
|     return; |     return; | ||||||
|   arg->count++; |   arg->count++;  // NOLINT(clang-diagnostic-deprecated-volatile) | ||||||
|   arg->value = (arg->value << 1) | 1; |   arg->value = (arg->value << 1) | 1; | ||||||
|   arg->last_bit_time = millis(); |   arg->last_bit_time = millis(); | ||||||
|   arg->done = false; |   arg->done = false; | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ | |||||||
| #include "esphome/core/version.h" | #include "esphome/core/version.h" | ||||||
| #include "esphome/core/hal.h" | #include "esphome/core/hal.h" | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
|  | #include <ranges> | ||||||
|  |  | ||||||
| #ifdef USE_STATUS_LED | #ifdef USE_STATUS_LED | ||||||
| #include "esphome/components/status_led/status_led.h" | #include "esphome/components/status_led/status_led.h" | ||||||
| @@ -188,8 +189,8 @@ void IRAM_ATTR HOT Application::feed_wdt(uint32_t time) { | |||||||
| } | } | ||||||
| void Application::reboot() { | void Application::reboot() { | ||||||
|   ESP_LOGI(TAG, "Forcing a reboot"); |   ESP_LOGI(TAG, "Forcing a reboot"); | ||||||
|   for (auto it = this->components_.rbegin(); it != this->components_.rend(); ++it) { |   for (auto &component : std::ranges::reverse_view(this->components_)) { | ||||||
|     (*it)->on_shutdown(); |     component->on_shutdown(); | ||||||
|   } |   } | ||||||
|   arch_restart(); |   arch_restart(); | ||||||
| } | } | ||||||
| @@ -202,17 +203,17 @@ void Application::safe_reboot() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void Application::run_safe_shutdown_hooks() { | void Application::run_safe_shutdown_hooks() { | ||||||
|   for (auto it = this->components_.rbegin(); it != this->components_.rend(); ++it) { |   for (auto &component : std::ranges::reverse_view(this->components_)) { | ||||||
|     (*it)->on_safe_shutdown(); |     component->on_safe_shutdown(); | ||||||
|   } |   } | ||||||
|   for (auto it = this->components_.rbegin(); it != this->components_.rend(); ++it) { |   for (auto &component : std::ranges::reverse_view(this->components_)) { | ||||||
|     (*it)->on_shutdown(); |     component->on_shutdown(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| void Application::run_powerdown_hooks() { | void Application::run_powerdown_hooks() { | ||||||
|   for (auto it = this->components_.rbegin(); it != this->components_.rend(); ++it) { |   for (auto &component : std::ranges::reverse_view(this->components_)) { | ||||||
|     (*it)->on_powerdown(); |     component->on_powerdown(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -617,7 +617,7 @@ def set_cpp_standard(standard: str) -> None: | |||||||
|     """Set C++ standard with compiler flag `-std={standard}`.""" |     """Set C++ standard with compiler flag `-std={standard}`.""" | ||||||
|     CORE.add_build_unflag("-std=gnu++11") |     CORE.add_build_unflag("-std=gnu++11") | ||||||
|     CORE.add_build_unflag("-std=gnu++14") |     CORE.add_build_unflag("-std=gnu++14") | ||||||
|     CORE.add_build_unflag("-std=gnu++20") |     CORE.add_build_unflag("-std=gnu++17") | ||||||
|     CORE.add_build_unflag("-std=gnu++23") |     CORE.add_build_unflag("-std=gnu++23") | ||||||
|     CORE.add_build_unflag("-std=gnu++2a") |     CORE.add_build_unflag("-std=gnu++2a") | ||||||
|     CORE.add_build_unflag("-std=gnu++2b") |     CORE.add_build_unflag("-std=gnu++2b") | ||||||
|   | |||||||
| @@ -47,11 +47,11 @@ lib_deps = | |||||||
|     lvgl/lvgl@8.4.0                                       ; lvgl |     lvgl/lvgl@8.4.0                                       ; lvgl | ||||||
| build_flags = | build_flags = | ||||||
|     -DESPHOME_LOG_LEVEL=ESPHOME_LOG_LEVEL_VERY_VERBOSE |     -DESPHOME_LOG_LEVEL=ESPHOME_LOG_LEVEL_VERY_VERBOSE | ||||||
|     -std=gnu++17 |     -std=gnu++20 | ||||||
| build_unflags = | build_unflags = | ||||||
|     -std=gnu++11 |     -std=gnu++11 | ||||||
|     -std=gnu++14 |     -std=gnu++14 | ||||||
|     -std=gnu++20 |     -std=gnu++17 | ||||||
|     -std=gnu++23 |     -std=gnu++23 | ||||||
|     -std=gnu++2a |     -std=gnu++2a | ||||||
|     -std=gnu++2b |     -std=gnu++2b | ||||||
| @@ -560,7 +560,7 @@ lib_deps = | |||||||
| build_flags = | build_flags = | ||||||
|     ${common.build_flags} |     ${common.build_flags} | ||||||
|     -DUSE_HOST |     -DUSE_HOST | ||||||
|     -std=c++17 |     -std=c++20 | ||||||
| build_unflags = | build_unflags = | ||||||
|     ${common.build_unflags} |     ${common.build_unflags} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user