mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Compatibility with clang-tidy v14 (#2272)
This commit is contained in:
parent
f31e0532c4
commit
0cd24c629a
12 changed files with 41 additions and 45 deletions
|
@ -2,9 +2,11 @@
|
|||
Checks: >-
|
||||
*,
|
||||
-abseil-*,
|
||||
-altera-*,
|
||||
-android-*,
|
||||
-boost-*,
|
||||
-bugprone-branch-clone,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
-bugprone-narrowing-conversions,
|
||||
-bugprone-signed-char-misuse,
|
||||
-bugprone-too-small-loop-variable,
|
||||
|
@ -20,6 +22,7 @@ Checks: >-
|
|||
-clang-diagnostic-sign-compare,
|
||||
-clang-diagnostic-unused-variable,
|
||||
-clang-diagnostic-unused-const-variable,
|
||||
-concurrency-*,
|
||||
-cppcoreguidelines-avoid-c-arrays,
|
||||
-cppcoreguidelines-avoid-goto,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
|
@ -72,6 +75,7 @@ Checks: >-
|
|||
-readability-const-return-type,
|
||||
-readability-convert-member-functions-to-static,
|
||||
-readability-else-after-return,
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-implicit-bool-conversion,
|
||||
-readability-isolate-declaration,
|
||||
-readability-magic-numbers,
|
||||
|
|
|
@ -113,14 +113,14 @@ void BME280Component::setup() {
|
|||
this->calibration_.h5 = read_u8_(BME280_REGISTER_DIG_H5 + 1) << 4 | (read_u8_(BME280_REGISTER_DIG_H5) >> 4);
|
||||
this->calibration_.h6 = read_u8_(BME280_REGISTER_DIG_H6);
|
||||
|
||||
uint8_t humid_register = 0;
|
||||
if (!this->read_byte(BME280_REGISTER_CONTROLHUMID, &humid_register)) {
|
||||
uint8_t humid_control_val = 0;
|
||||
if (!this->read_byte(BME280_REGISTER_CONTROLHUMID, &humid_control_val)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
humid_register &= ~0b00000111;
|
||||
humid_register |= this->humidity_oversampling_ & 0b111;
|
||||
if (!this->write_byte(BME280_REGISTER_CONTROLHUMID, humid_register)) {
|
||||
humid_control_val &= ~0b00000111;
|
||||
humid_control_val |= this->humidity_oversampling_ & 0b111;
|
||||
if (!this->write_byte(BME280_REGISTER_CONTROLHUMID, humid_control_val)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
@ -169,11 +169,11 @@ inline uint8_t oversampling_to_time(BME280Oversampling over_sampling) { return (
|
|||
void BME280Component::update() {
|
||||
// Enable sensor
|
||||
ESP_LOGV(TAG, "Sending conversion request...");
|
||||
uint8_t meas_register = 0;
|
||||
meas_register |= (this->temperature_oversampling_ & 0b111) << 5;
|
||||
meas_register |= (this->pressure_oversampling_ & 0b111) << 2;
|
||||
meas_register |= BME280_MODE_FORCED;
|
||||
if (!this->write_byte(BME280_REGISTER_CONTROL, meas_register)) {
|
||||
uint8_t meas_value = 0;
|
||||
meas_value |= (this->temperature_oversampling_ & 0b111) << 5;
|
||||
meas_value |= (this->pressure_oversampling_ & 0b111) << 2;
|
||||
meas_value |= BME280_MODE_FORCED;
|
||||
if (!this->write_byte(BME280_REGISTER_CONTROL, meas_value)) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -123,11 +123,11 @@ inline uint8_t oversampling_to_time(BMP280Oversampling over_sampling) { return (
|
|||
void BMP280Component::update() {
|
||||
// Enable sensor
|
||||
ESP_LOGV(TAG, "Sending conversion request...");
|
||||
uint8_t meas_register = 0;
|
||||
meas_register |= (this->temperature_oversampling_ & 0b111) << 5;
|
||||
meas_register |= (this->pressure_oversampling_ & 0b111) << 2;
|
||||
meas_register |= 0b01; // Forced mode
|
||||
if (!this->write_byte(BMP280_REGISTER_CONTROL, meas_register)) {
|
||||
uint8_t meas_value = 0;
|
||||
meas_value |= (this->temperature_oversampling_ & 0b111) << 5;
|
||||
meas_value |= (this->pressure_oversampling_ & 0b111) << 2;
|
||||
meas_value |= 0b01; // Forced mode
|
||||
if (!this->write_byte(BMP280_REGISTER_CONTROL, meas_value)) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -514,9 +514,7 @@ Color Animation::get_grayscale_pixel(int x, int y) const {
|
|||
return Color(gray | gray << 8 | gray << 16 | gray << 24);
|
||||
}
|
||||
Animation::Animation(const uint8_t *data_start, int width, int height, uint32_t animation_frame_count, ImageType type)
|
||||
: Image(data_start, width, height, type), animation_frame_count_(animation_frame_count) {
|
||||
current_frame_ = 0;
|
||||
}
|
||||
: Image(data_start, width, height, type), current_frame_(0), animation_frame_count_(animation_frame_count) {}
|
||||
int Animation::get_animation_frame_count() const { return this->animation_frame_count_; }
|
||||
int Animation::get_current_frame() const { return this->current_frame_; }
|
||||
void Animation::next_frame() {
|
||||
|
|
|
@ -16,7 +16,7 @@ I2CComponent::I2CComponent() {
|
|||
this->wire_ = new TwoWire(next_i2c_bus_num_);
|
||||
next_i2c_bus_num_++;
|
||||
#else
|
||||
this->wire_ = &Wire;
|
||||
this->wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,8 @@ float MCP3008::read_data(uint8_t pin) {
|
|||
}
|
||||
|
||||
MCP3008Sensor::MCP3008Sensor(MCP3008 *parent, const std::string &name, uint8_t pin, float reference_voltage)
|
||||
: PollingComponent(1000), parent_(parent), pin_(pin) {
|
||||
: PollingComponent(1000), parent_(parent), pin_(pin), reference_voltage_(reference_voltage) {
|
||||
this->set_name(name);
|
||||
this->reference_voltage_ = reference_voltage;
|
||||
}
|
||||
|
||||
float MCP3008Sensor::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
|
|
@ -25,7 +25,7 @@ MQTTClientComponent::MQTTClientComponent() {
|
|||
// Connection
|
||||
void MQTTClientComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up MQTT...");
|
||||
this->mqtt_client_.onMessage([this](char *topic, char *payload, AsyncMqttClientMessageProperties properties,
|
||||
this->mqtt_client_.onMessage([this](char const *topic, char *payload, AsyncMqttClientMessageProperties properties,
|
||||
size_t len, size_t index, size_t total) {
|
||||
if (index == 0)
|
||||
this->payload_buffer_.reserve(total);
|
||||
|
|
|
@ -41,7 +41,7 @@ optional<RC5Data> RC5Protocol::decode(RemoteReceiveData src) {
|
|||
.address = 0,
|
||||
.command = 0,
|
||||
};
|
||||
int field_bit = 0;
|
||||
uint8_t field_bit;
|
||||
|
||||
if (src.expect_space(BIT_TIME_US) && src.expect_mark(BIT_TIME_US)) {
|
||||
field_bit = 1;
|
||||
|
@ -60,7 +60,7 @@ optional<RC5Data> RC5Protocol::decode(RemoteReceiveData src) {
|
|||
return {};
|
||||
}
|
||||
|
||||
uint64_t out_data = 0;
|
||||
uint32_t out_data = 0;
|
||||
for (int bit = NBITS - 4; bit >= 1; bit--) {
|
||||
if ((src.expect_space(BIT_TIME_US) || src.expect_space(2 * BIT_TIME_US)) &&
|
||||
(src.expect_mark(BIT_TIME_US) || src.peek_mark(2 * BIT_TIME_US))) {
|
||||
|
@ -78,7 +78,7 @@ optional<RC5Data> RC5Protocol::decode(RemoteReceiveData src) {
|
|||
out_data |= 1;
|
||||
}
|
||||
|
||||
out.command = (out_data & 0x3F) + (1 - field_bit) * 64;
|
||||
out.command = (uint8_t)(out_data & 0x3F) + (1 - field_bit) * 64u;
|
||||
out.address = (out_data >> 6) & 0x1F;
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -220,15 +220,14 @@ static const uint8_t PROGMEM
|
|||
// clang-format on
|
||||
static const char *const TAG = "st7735";
|
||||
|
||||
ST7735::ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr) {
|
||||
model_ = model;
|
||||
this->width_ = width;
|
||||
this->height_ = height;
|
||||
this->colstart_ = colstart;
|
||||
this->rowstart_ = rowstart;
|
||||
this->eightbitcolor_ = eightbitcolor;
|
||||
this->usebgr_ = usebgr;
|
||||
}
|
||||
ST7735::ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr)
|
||||
: model_(model),
|
||||
colstart_(colstart),
|
||||
rowstart_(rowstart),
|
||||
eightbitcolor_(eightbitcolor),
|
||||
usebgr_(usebgr),
|
||||
width_(width),
|
||||
height_(height) {}
|
||||
|
||||
void ST7735::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ST7735...");
|
||||
|
|
|
@ -79,10 +79,8 @@ struct SunAtTime {
|
|||
num_t jde;
|
||||
num_t t;
|
||||
|
||||
SunAtTime(num_t jde) : jde(jde) {
|
||||
// eq 25.1, p. 163; julian centuries from the epoch J2000.0
|
||||
t = (jde - 2451545) / 36525.0;
|
||||
}
|
||||
// eq 25.1, p. 163; julian centuries from the epoch J2000.0
|
||||
SunAtTime(num_t jde) : jde(jde), t((jde - 2451545) / 36525.0) {}
|
||||
|
||||
num_t mean_obliquity() const {
|
||||
// eq. 22.2, p. 147; mean obliquity of the ecliptic
|
||||
|
|
|
@ -196,10 +196,8 @@ uint32_t Nameable::get_object_id_hash() { return this->object_id_hash_; }
|
|||
bool Nameable::is_disabled_by_default() const { return this->disabled_by_default_; }
|
||||
void Nameable::set_disabled_by_default(bool disabled_by_default) { this->disabled_by_default_ = disabled_by_default; }
|
||||
|
||||
WarnIfComponentBlockingGuard::WarnIfComponentBlockingGuard(Component *component) {
|
||||
component_ = component;
|
||||
started_ = millis();
|
||||
}
|
||||
WarnIfComponentBlockingGuard::WarnIfComponentBlockingGuard(Component *component)
|
||||
: started_(millis()), component_(component) {}
|
||||
WarnIfComponentBlockingGuard::~WarnIfComponentBlockingGuard() {
|
||||
uint32_t now = millis();
|
||||
if (now - started_ > 50) {
|
||||
|
|
|
@ -20,7 +20,7 @@ static const char *const TAG = "preferences";
|
|||
ESPPreferenceObject::ESPPreferenceObject() : offset_(0), length_words_(0), type_(0), data_(nullptr) {}
|
||||
ESPPreferenceObject::ESPPreferenceObject(size_t offset, size_t length, uint32_t type)
|
||||
: offset_(offset), length_words_(length), type_(type) {
|
||||
this->data_ = new uint32_t[this->length_words_ + 1];
|
||||
this->data_ = new uint32_t[this->length_words_ + 1]; // NOLINT(cppcoreguidelines-prefer-member-initializer)
|
||||
for (uint32_t i = 0; i < this->length_words_ + 1; i++)
|
||||
this->data_[i] = 0;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ static inline bool esp_rtc_user_mem_read(uint32_t index, uint32_t *dest) {
|
|||
if (index >= ESP_RTC_USER_MEM_SIZE_WORDS) {
|
||||
return false;
|
||||
}
|
||||
*dest = ESP_RTC_USER_MEM[index];
|
||||
*dest = ESP_RTC_USER_MEM[index]; // NOLINT(performance-no-int-to-ptr)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ static inline bool esp_rtc_user_mem_write(uint32_t index, uint32_t value) {
|
|||
return false;
|
||||
}
|
||||
|
||||
auto *ptr = &ESP_RTC_USER_MEM[index];
|
||||
auto *ptr = &ESP_RTC_USER_MEM[index]; // NOLINT(performance-no-int-to-ptr)
|
||||
*ptr = value;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue