mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 09:44:12 +01:00
clang-tidy suggestions.
This commit is contained in:
parent
635cd1f4c8
commit
c1d8b4e541
2 changed files with 30 additions and 30 deletions
|
@ -44,13 +44,13 @@ void LD2415HComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, " Minimum Speed Threshold: %u KPH", this->min_speed_threshold_);
|
ESP_LOGCONFIG(TAG, " Minimum Speed Threshold: %u KPH", this->min_speed_threshold_);
|
||||||
ESP_LOGCONFIG(TAG, " Compensation Angle: %u", this->compensation_angle_);
|
ESP_LOGCONFIG(TAG, " Compensation Angle: %u", this->compensation_angle_);
|
||||||
ESP_LOGCONFIG(TAG, " Sensitivity: %u", this->sensitivity_);
|
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, " 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, " Vibration Correction: %u", this->vibration_correction_);
|
||||||
ESP_LOGCONFIG(TAG, " Relay Trigger Duration: %u", this->relay_trigger_duration_);
|
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, " 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() {
|
void LD2415HComponent::loop() {
|
||||||
|
@ -165,7 +165,7 @@ void LD2415HComponent::set_relay_trigger_speed(uint8_t speed) {
|
||||||
this->update_relay_duration_speed_ = true;
|
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++)
|
for (uint8_t i = 0; i < size; i++)
|
||||||
ESP_LOGD(TAG, " 0x%02x", cmd[i]);
|
ESP_LOGD(TAG, " 0x%02x", cmd[i]);
|
||||||
|
|
||||||
|
@ -243,14 +243,14 @@ void LD2415HComponent::parse_config_() {
|
||||||
|
|
||||||
char *token = strtok(this->response_buffer_, delim);
|
char *token = strtok(this->response_buffer_, delim);
|
||||||
|
|
||||||
while (token != NULL) {
|
while (token != nullptr) {
|
||||||
if (std::strlen(token) != token_len) {
|
if (std::strlen(token) != token_len) {
|
||||||
ESP_LOGE(TAG, "Configuration key length invalid.");
|
ESP_LOGE(TAG, "Configuration key length invalid.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
key = token;
|
key = token;
|
||||||
|
|
||||||
token = strtok(NULL, delim);
|
token = strtok(nullptr, delim);
|
||||||
if (std::strlen(token) != token_len) {
|
if (std::strlen(token) != token_len) {
|
||||||
ESP_LOGE(TAG, "Configuration value length invalid.");
|
ESP_LOGE(TAG, "Configuration value length invalid.");
|
||||||
break;
|
break;
|
||||||
|
@ -259,7 +259,7 @@ void LD2415HComponent::parse_config_() {
|
||||||
|
|
||||||
this->parse_config_param_(key, val);
|
this->parse_config_param_(key, val);
|
||||||
|
|
||||||
token = strtok(NULL, delim);
|
token = strtok(nullptr, delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Configuration received:");
|
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, " Minimum Speed Threshold: %u KPH", this->min_speed_threshold_);
|
||||||
ESP_LOGCONFIG(TAG, " Compensation Angle: %u", this->compensation_angle_);
|
ESP_LOGCONFIG(TAG, " Compensation Angle: %u", this->compensation_angle_);
|
||||||
ESP_LOGCONFIG(TAG, " Sensitivity: %u", this->sensitivity_);
|
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, " 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, " Vibration Correction: %u", this->vibration_correction_);
|
||||||
ESP_LOGCONFIG(TAG, " Relay Trigger Duration: %u", this->relay_trigger_duration_);
|
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, " 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_() {
|
void LD2415HComponent::parse_firmware_() {
|
||||||
|
@ -302,7 +302,7 @@ void LD2415HComponent::parse_speed_() {
|
||||||
++p;
|
++p;
|
||||||
this->approaching_ = (*p == '+');
|
this->approaching_ = (*p == '+');
|
||||||
++p;
|
++p;
|
||||||
this->speed_ = atof(p);
|
this->speed_ = strtod(p, nullptr);
|
||||||
|
|
||||||
ESP_LOGV(TAG, "Speed updated: %f KPH", this->speed_);
|
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);
|
this->sensitivity_ = std::stoi(value, nullptr, 16);
|
||||||
break;
|
break;
|
||||||
case '4':
|
case '4':
|
||||||
this->tracking_mode_ = this->i_to_TrackingMode_(v);
|
this->tracking_mode_ = this->i_to_tracking_mode_(v);
|
||||||
break;
|
break;
|
||||||
case '5':
|
case '5':
|
||||||
this->sample_rate_ = v;
|
this->sample_rate_ = v;
|
||||||
break;
|
break;
|
||||||
case '6':
|
case '6':
|
||||||
this->unit_of_measure_ = this->i_to_UnitOfMeasure_(v);
|
this->unit_of_measure_ = this->i_to_unit_of_measure_(v);
|
||||||
break;
|
break;
|
||||||
case '7':
|
case '7':
|
||||||
this->vibration_correction_ = v;
|
this->vibration_correction_ = v;
|
||||||
|
@ -356,7 +356,7 @@ void LD2415HComponent::parse_config_param_(char *key, char *value) {
|
||||||
this->relay_trigger_speed_ = v;
|
this->relay_trigger_speed_ = v;
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
this->negotiation_mode_ = this->i_to_NegotiationMode_(v);
|
this->negotiation_mode_ = this->i_to_negotiation_mode_(v);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGD(TAG, "Unknown Parameter %s:%s", key, value);
|
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);
|
TrackingMode u = TrackingMode(value);
|
||||||
switch (u) {
|
switch (u) {
|
||||||
case TrackingMode::APPROACHING_AND_RETREATING:
|
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);
|
UnitOfMeasure u = UnitOfMeasure(value);
|
||||||
switch (u) {
|
switch (u) {
|
||||||
case UnitOfMeasure::MPS:
|
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);
|
NegotiationMode u = NegotiationMode(value);
|
||||||
|
|
||||||
switch (u) {
|
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) {
|
switch (value) {
|
||||||
case TrackingMode::APPROACHING_AND_RETREATING:
|
case TrackingMode::APPROACHING_AND_RETREATING:
|
||||||
return "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) {
|
switch (value) {
|
||||||
case UnitOfMeasure::MPS:
|
case UnitOfMeasure::MPS:
|
||||||
return "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) {
|
switch (value) {
|
||||||
case NegotiationMode::CUSTOM_AGREEMENT:
|
case NegotiationMode::CUSTOM_AGREEMENT:
|
||||||
return "CUSTOM_AGREEMENT";
|
return "CUSTOM_AGREEMENT";
|
||||||
|
@ -442,7 +442,7 @@ const char *LD2415HComponent::NegotiationMode_to_s_(NegotiationMode value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *i_to_s_(std::map<std::string, uint8_t> map, uint8_t i) {
|
const char *i_to_s(const std::map<std::string, uint8_t> &map, uint8_t i) {
|
||||||
for (const auto &pair : map) {
|
for (const auto &pair : map) {
|
||||||
if (pair.second == i) {
|
if (pair.second == i) {
|
||||||
return pair.first;
|
return pair.first;
|
||||||
|
|
|
@ -114,12 +114,12 @@ class LD2415HComponent : public Component, public uart::UARTDevice {
|
||||||
|
|
||||||
char firmware_[20] = "";
|
char firmware_[20] = "";
|
||||||
float speed_ = 0;
|
float speed_ = 0;
|
||||||
bool approaching_ = 1;
|
bool approaching_ = true;
|
||||||
char response_buffer_[64];
|
char response_buffer_[64];
|
||||||
uint8_t response_buffer_index_ = 0;
|
uint8_t response_buffer_index_ = 0;
|
||||||
|
|
||||||
// Processing
|
// 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);
|
bool fill_buffer_(char c);
|
||||||
void clear_remaining_buffer_(uint8_t pos);
|
void clear_remaining_buffer_(uint8_t pos);
|
||||||
void parse_buffer_();
|
void parse_buffer_();
|
||||||
|
@ -129,13 +129,13 @@ class LD2415HComponent : public Component, public uart::UARTDevice {
|
||||||
void parse_config_param_(char *key, char *value);
|
void parse_config_param_(char *key, char *value);
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
TrackingMode i_to_TrackingMode_(uint8_t value);
|
TrackingMode i_to_tracking_mode_(uint8_t value);
|
||||||
UnitOfMeasure i_to_UnitOfMeasure_(uint8_t value);
|
UnitOfMeasure i_to_unit_of_measure_(uint8_t value);
|
||||||
NegotiationMode i_to_NegotiationMode_(uint8_t value);
|
NegotiationMode i_to_negotiation_mode_(uint8_t value);
|
||||||
const char *TrackingMode_to_s_(TrackingMode value);
|
const char *tracking_mode_to_s_(TrackingMode value);
|
||||||
const char *UnitOfMeasure_to_s_(UnitOfMeasure value);
|
const char *unit_of_measure_to_s_(UnitOfMeasure value);
|
||||||
const char *NegotiationMode_to_s_(NegotiationMode value);
|
const char *negotiation_mode_to_s_(NegotiationMode value);
|
||||||
const char *i_to_s_(std::map<std::string, uint8_t> map, uint8_t i);
|
const char *i_to_s(const std::map<std::string, uint8_t> &map, uint8_t i);
|
||||||
|
|
||||||
std::vector<LD2415HListener *> listeners_{};
|
std::vector<LD2415HListener *> listeners_{};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue