From 635cd1f4c80cbf0979a5b492baa243b6c20e8454 Mon Sep 17 00:00:00 2001 From: cptskippy Date: Wed, 29 May 2024 16:21:02 +0000 Subject: [PATCH 1/3] Updating CODEOWNERS --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/CODEOWNERS b/CODEOWNERS index 8b6143859a..2e82df9bda 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -200,6 +200,7 @@ esphome/components/key_provider/* @ssieb esphome/components/kuntze/* @ssieb esphome/components/lcd_menu/* @numo68 esphome/components/ld2410/* @regevbr @sebcaps +esphome/components/ld2415h/* @cptskippy esphome/components/ld2420/* @descipher esphome/components/ledc/* @OttoWinter esphome/components/libretiny/* @kuba2k2 From c1d8b4e54157362da1ee7828f1149c014330e648 Mon Sep 17 00:00:00 2001 From: cptskippy Date: Thu, 30 May 2024 19:35:56 +0000 Subject: [PATCH 2/3] clang-tidy suggestions. --- esphome/components/ld2415h/ld2415h.cpp | 42 +++++++++++++------------- esphome/components/ld2415h/ld2415h.h | 18 +++++------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/esphome/components/ld2415h/ld2415h.cpp b/esphome/components/ld2415h/ld2415h.cpp index b2ebae40fd..c6388cd950 100644 --- a/esphome/components/ld2415h/ld2415h.cpp +++ b/esphome/components/ld2415h/ld2415h.cpp @@ -44,13 +44,13 @@ void LD2415HComponent::dump_config() { ESP_LOGCONFIG(TAG, " Minimum Speed Threshold: %u KPH", this->min_speed_threshold_); ESP_LOGCONFIG(TAG, " Compensation Angle: %u", this->compensation_angle_); ESP_LOGCONFIG(TAG, " Sensitivity: %u", this->sensitivity_); - ESP_LOGCONFIG(TAG, " Tracking Mode: %s", TrackingMode_to_s_(this->tracking_mode_)); + ESP_LOGCONFIG(TAG, " Tracking Mode: %s", tracking_mode_to_s_(this->tracking_mode_)); ESP_LOGCONFIG(TAG, " Sampling Rate: %u", this->sample_rate_); - ESP_LOGCONFIG(TAG, " Unit of Measure: %s", UnitOfMeasure_to_s_(this->unit_of_measure_)); + ESP_LOGCONFIG(TAG, " Unit of Measure: %s", unit_of_measure_to_s_(this->unit_of_measure_)); ESP_LOGCONFIG(TAG, " Vibration Correction: %u", this->vibration_correction_); ESP_LOGCONFIG(TAG, " Relay Trigger Duration: %u", this->relay_trigger_duration_); ESP_LOGCONFIG(TAG, " Relay Trigger Speed: %u KPH", this->relay_trigger_speed_); - ESP_LOGCONFIG(TAG, " Negotiation Mode: %s", NegotiationMode_to_s_(this->negotiation_mode_)); + ESP_LOGCONFIG(TAG, " Negotiation Mode: %s", negotiation_mode_to_s_(this->negotiation_mode_)); } void LD2415HComponent::loop() { @@ -165,7 +165,7 @@ void LD2415HComponent::set_relay_trigger_speed(uint8_t speed) { this->update_relay_duration_speed_ = true; } -void LD2415HComponent::issue_command_(const uint8_t cmd[], const uint8_t size) { +void LD2415HComponent::issue_command_(const uint8_t cmd[], uint8_t size) { for (uint8_t i = 0; i < size; i++) ESP_LOGD(TAG, " 0x%02x", cmd[i]); @@ -243,14 +243,14 @@ void LD2415HComponent::parse_config_() { char *token = strtok(this->response_buffer_, delim); - while (token != NULL) { + while (token != nullptr) { if (std::strlen(token) != token_len) { ESP_LOGE(TAG, "Configuration key length invalid."); break; } key = token; - token = strtok(NULL, delim); + token = strtok(nullptr, delim); if (std::strlen(token) != token_len) { ESP_LOGE(TAG, "Configuration value length invalid."); break; @@ -259,7 +259,7 @@ void LD2415HComponent::parse_config_() { this->parse_config_param_(key, val); - token = strtok(NULL, delim); + token = strtok(nullptr, delim); } ESP_LOGD(TAG, "Configuration received:"); @@ -268,13 +268,13 @@ void LD2415HComponent::parse_config_() { ESP_LOGCONFIG(TAG, " Minimum Speed Threshold: %u KPH", this->min_speed_threshold_); ESP_LOGCONFIG(TAG, " Compensation Angle: %u", this->compensation_angle_); ESP_LOGCONFIG(TAG, " Sensitivity: %u", this->sensitivity_); - ESP_LOGCONFIG(TAG, " Tracking Mode: %s", TrackingMode_to_s_(this->tracking_mode_)); + ESP_LOGCONFIG(TAG, " Tracking Mode: %s", tracking_mode_to_s_(this->tracking_mode_)); ESP_LOGCONFIG(TAG, " Sampling Rate: %u", this->sample_rate_); - ESP_LOGCONFIG(TAG, " Unit of Measure: %s", UnitOfMeasure_to_s_(this->unit_of_measure_)); + ESP_LOGCONFIG(TAG, " Unit of Measure: %s", unit_of_measure_to_s_(this->unit_of_measure_)); ESP_LOGCONFIG(TAG, " Vibration Correction: %u", this->vibration_correction_); ESP_LOGCONFIG(TAG, " Relay Trigger Duration: %u", this->relay_trigger_duration_); ESP_LOGCONFIG(TAG, " Relay Trigger Speed: %u KPH", this->relay_trigger_speed_); - ESP_LOGCONFIG(TAG, " Negotiation Mode: %s", NegotiationMode_to_s_(this->negotiation_mode_)); + ESP_LOGCONFIG(TAG, " Negotiation Mode: %s", negotiation_mode_to_s_(this->negotiation_mode_)); } void LD2415HComponent::parse_firmware_() { @@ -302,7 +302,7 @@ void LD2415HComponent::parse_speed_() { ++p; this->approaching_ = (*p == '+'); ++p; - this->speed_ = atof(p); + this->speed_ = strtod(p, nullptr); ESP_LOGV(TAG, "Speed updated: %f KPH", this->speed_); @@ -338,13 +338,13 @@ void LD2415HComponent::parse_config_param_(char *key, char *value) { this->sensitivity_ = std::stoi(value, nullptr, 16); break; case '4': - this->tracking_mode_ = this->i_to_TrackingMode_(v); + this->tracking_mode_ = this->i_to_tracking_mode_(v); break; case '5': this->sample_rate_ = v; break; case '6': - this->unit_of_measure_ = this->i_to_UnitOfMeasure_(v); + this->unit_of_measure_ = this->i_to_unit_of_measure_(v); break; case '7': this->vibration_correction_ = v; @@ -356,7 +356,7 @@ void LD2415HComponent::parse_config_param_(char *key, char *value) { this->relay_trigger_speed_ = v; break; case '0': - this->negotiation_mode_ = this->i_to_NegotiationMode_(v); + this->negotiation_mode_ = this->i_to_negotiation_mode_(v); break; default: ESP_LOGD(TAG, "Unknown Parameter %s:%s", key, value); @@ -364,7 +364,7 @@ void LD2415HComponent::parse_config_param_(char *key, char *value) { } } -TrackingMode LD2415HComponent::i_to_TrackingMode_(uint8_t value) { +TrackingMode LD2415HComponent::i_to_tracking_mode_(uint8_t value) { TrackingMode u = TrackingMode(value); switch (u) { case TrackingMode::APPROACHING_AND_RETREATING: @@ -379,7 +379,7 @@ TrackingMode LD2415HComponent::i_to_TrackingMode_(uint8_t value) { } } -UnitOfMeasure LD2415HComponent::i_to_UnitOfMeasure_(uint8_t value) { +UnitOfMeasure LD2415HComponent::i_to_unit_of_measure_(uint8_t value) { UnitOfMeasure u = UnitOfMeasure(value); switch (u) { case UnitOfMeasure::MPS: @@ -394,7 +394,7 @@ UnitOfMeasure LD2415HComponent::i_to_UnitOfMeasure_(uint8_t value) { } } -NegotiationMode LD2415HComponent::i_to_NegotiationMode_(uint8_t value) { +NegotiationMode LD2415HComponent::i_to_negotiation_mode_(uint8_t value) { NegotiationMode u = NegotiationMode(value); switch (u) { @@ -408,7 +408,7 @@ NegotiationMode LD2415HComponent::i_to_NegotiationMode_(uint8_t value) { } } -const char *LD2415HComponent::TrackingMode_to_s_(TrackingMode value) { +const char *LD2415HComponent::tracking_mode_to_s_(TrackingMode value) { switch (value) { case TrackingMode::APPROACHING_AND_RETREATING: return "APPROACHING_AND_RETREATING"; @@ -420,7 +420,7 @@ const char *LD2415HComponent::TrackingMode_to_s_(TrackingMode value) { } } -const char *LD2415HComponent::UnitOfMeasure_to_s_(UnitOfMeasure value) { +const char *LD2415HComponent::unit_of_measure_to_s_(UnitOfMeasure value) { switch (value) { case UnitOfMeasure::MPS: return "MPS"; @@ -432,7 +432,7 @@ const char *LD2415HComponent::UnitOfMeasure_to_s_(UnitOfMeasure value) { } } -const char *LD2415HComponent::NegotiationMode_to_s_(NegotiationMode value) { +const char *LD2415HComponent::negotiation_mode_to_s_(NegotiationMode value) { switch (value) { case NegotiationMode::CUSTOM_AGREEMENT: return "CUSTOM_AGREEMENT"; @@ -442,7 +442,7 @@ const char *LD2415HComponent::NegotiationMode_to_s_(NegotiationMode value) { } } -const char *i_to_s_(std::map map, uint8_t i) { +const char *i_to_s(const std::map &map, uint8_t i) { for (const auto &pair : map) { if (pair.second == i) { return pair.first; diff --git a/esphome/components/ld2415h/ld2415h.h b/esphome/components/ld2415h/ld2415h.h index e508dfaf46..c0cc4f1e6f 100644 --- a/esphome/components/ld2415h/ld2415h.h +++ b/esphome/components/ld2415h/ld2415h.h @@ -114,12 +114,12 @@ class LD2415HComponent : public Component, public uart::UARTDevice { char firmware_[20] = ""; float speed_ = 0; - bool approaching_ = 1; + bool approaching_ = true; char response_buffer_[64]; uint8_t response_buffer_index_ = 0; // Processing - void issue_command_(const uint8_t cmd[], const uint8_t size); + void issue_command_(const uint8_t cmd[], uint8_t size); bool fill_buffer_(char c); void clear_remaining_buffer_(uint8_t pos); void parse_buffer_(); @@ -129,13 +129,13 @@ class LD2415HComponent : public Component, public uart::UARTDevice { void parse_config_param_(char *key, char *value); // Helpers - TrackingMode i_to_TrackingMode_(uint8_t value); - UnitOfMeasure i_to_UnitOfMeasure_(uint8_t value); - NegotiationMode i_to_NegotiationMode_(uint8_t value); - const char *TrackingMode_to_s_(TrackingMode value); - const char *UnitOfMeasure_to_s_(UnitOfMeasure value); - const char *NegotiationMode_to_s_(NegotiationMode value); - const char *i_to_s_(std::map map, uint8_t i); + TrackingMode i_to_tracking_mode_(uint8_t value); + UnitOfMeasure i_to_unit_of_measure_(uint8_t value); + NegotiationMode i_to_negotiation_mode_(uint8_t value); + const char *tracking_mode_to_s_(TrackingMode value); + const char *unit_of_measure_to_s_(UnitOfMeasure value); + const char *negotiation_mode_to_s_(NegotiationMode value); + const char *i_to_s(const std::map &map, uint8_t i); std::vector listeners_{}; }; From abc139fc65a212679f864c2862d1ccac7de594d3 Mon Sep 17 00:00:00 2001 From: cptskippy Date: Thu, 30 May 2024 22:04:20 +0000 Subject: [PATCH 3/3] clang.tidy changes --- esphome/components/ld2415h/ld2415h.cpp | 6 +++--- esphome/components/ld2415h/ld2415h.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/esphome/components/ld2415h/ld2415h.cpp b/esphome/components/ld2415h/ld2415h.cpp index c6388cd950..5fc5ffc2c5 100644 --- a/esphome/components/ld2415h/ld2415h.cpp +++ b/esphome/components/ld2415h/ld2415h.cpp @@ -136,7 +136,7 @@ void LD2415HComponent::set_tracking_mode(TrackingMode mode) { this->update_mode_rate_uom_ = true; } -void LD2415HComponent::set_tracking_mode(uint8_t mode) { this->set_tracking_mode(i_to_TrackingMode_(mode)); } +void LD2415HComponent::set_tracking_mode(uint8_t mode) { this->set_tracking_mode(i_to_tracking_mode_(mode)); } void LD2415HComponent::set_sample_rate(const std::string &state) { uint8_t rate = SAMPLE_RATE_STR_TO_INT.at(state); @@ -442,10 +442,10 @@ const char *LD2415HComponent::negotiation_mode_to_s_(NegotiationMode value) { } } -const char *i_to_s(const std::map &map, uint8_t i) { +const char *i_to_s_(const std::map &map, uint8_t i) { for (const auto &pair : map) { if (pair.second == i) { - return pair.first; + return pair.first.c_str(); } } return "Unknown"; diff --git a/esphome/components/ld2415h/ld2415h.h b/esphome/components/ld2415h/ld2415h.h index c0cc4f1e6f..cb753f0e36 100644 --- a/esphome/components/ld2415h/ld2415h.h +++ b/esphome/components/ld2415h/ld2415h.h @@ -135,7 +135,7 @@ class LD2415HComponent : public Component, public uart::UARTDevice { const char *tracking_mode_to_s_(TrackingMode value); const char *unit_of_measure_to_s_(UnitOfMeasure value); const char *negotiation_mode_to_s_(NegotiationMode value); - const char *i_to_s(const std::map &map, uint8_t i); + const char *i_to_s_(const std::map &map, uint8_t i); std::vector listeners_{}; };