From 14e38f0469a67e29189a20d51a2b6dcfa9d5e390 Mon Sep 17 00:00:00 2001 From: Oxan van Leeuwen Date: Mon, 20 Mar 2023 04:38:41 +0100 Subject: [PATCH] Upgrade clang-format to v13 (#4535) * Upgrade clang-format to v13 * Apply clang-format-13 formatting changes * Format * Format bme_680 --------- Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- .devcontainer/devcontainer.json | 2 +- .github/workflows/ci.yml | 2 +- docker/Dockerfile | 2 +- esphome/components/am43/cover/am43_cover.cpp | 2 +- esphome/components/api/api_frame_helper.cpp | 10 ++-- esphome/components/bme680/bme680.cpp | 8 ++-- esphome/components/ccs811/ccs811.cpp | 4 +- esphome/components/cs5460a/cs5460a.cpp | 2 +- esphome/components/daly_bms/daly_bms.cpp | 4 +- esphome/components/dfplayer/dfplayer.cpp | 2 +- esphome/components/display/display_buffer.cpp | 8 ++-- esphome/components/ens210/ens210.cpp | 4 +- esphome/components/esp32/core.cpp | 2 +- .../esp32_ble_client/ble_client_base.cpp | 8 ++-- .../esp32_ble_client/ble_client_base.h | 9 ++-- .../esp32_ble_server/ble_characteristic.cpp | 24 +++++----- .../fingerprint_grow/fingerprint_grow.cpp | 30 ++++++------ .../fingerprint_grow/fingerprint_grow.h | 8 ++-- .../hitachi_ac344/hitachi_ac344.cpp | 2 +- .../hitachi_ac424/hitachi_ac424.cpp | 2 +- .../components/honeywellabp/honeywellabp.cpp | 4 +- .../components/ili9xxx/ili9xxx_display.cpp | 14 +++--- esphome/components/json/json_util.cpp | 2 +- .../components/lcd_gpio/gpio_lcd_display.cpp | 2 +- esphome/components/ld2410/ld2410.h | 2 +- esphome/components/light/color_mode.h | 21 +++++---- .../touchscreen/lilygo_t5_47_touchscreen.cpp | 8 ++-- esphome/components/mcp2515/mcp2515.cpp | 18 ++++---- esphome/components/mcp9600/mcp9600.cpp | 2 +- esphome/components/mcp9808/mcp9808.cpp | 6 +-- .../mopeka_pro_check/mopeka_pro_check.cpp | 3 +- .../mopeka_std_check/mopeka_std_check.cpp | 2 +- esphome/components/network/ip_address.h | 8 ++-- esphome/components/pipsolar/pipsolar.cpp | 22 ++++----- esphome/components/qmp6988/qmp6988.cpp | 46 +++++++++---------- .../components/remote_base/rc5_protocol.cpp | 2 +- esphome/components/scd30/scd30.cpp | 2 +- esphome/components/scd30/scd30.h | 2 +- esphome/components/scd4x/scd4x.cpp | 2 +- esphome/components/sgp4x/sgp4x.cpp | 4 +- esphome/components/sht4x/sht4x.cpp | 2 +- esphome/components/st7920/st7920.cpp | 2 +- esphome/components/sun/sun.cpp | 2 +- esphome/components/tcs34725/tcs34725.cpp | 2 +- esphome/components/tm1637/tm1637.cpp | 2 +- esphome/components/tm1638/tm1638.cpp | 2 +- esphome/components/tuya/tuya.cpp | 4 +- .../components/vbus/sensor/vbus_sensor.cpp | 2 +- esphome/components/vl53l0x/vl53l0x_sensor.cpp | 2 +- esphome/components/web_server/web_server.cpp | 2 +- esphome/components/whirlpool/whirlpool.cpp | 2 +- esphome/components/xiaomi_ble/xiaomi_ble.cpp | 12 ++--- esphome/components/xpt2046/xpt2046.cpp | 6 +-- esphome/core/log.h | 4 +- script/clang-format | 8 ++-- 55 files changed, 182 insertions(+), 179 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7e5a0c19c9..1f9a98d7ec 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -51,6 +51,6 @@ "files.associations": { "**/.vscode/*.json": "jsonc" }, - "C_Cpp.clang_format_path": "/usr/bin/clang-format-11", + "C_Cpp.clang_format_path": "/usr/bin/clang-format-13", } } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 769456c581..d22c2b7e03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,7 +133,7 @@ jobs: - name: Install clang tools run: | sudo apt-get install \ - clang-format-11 \ + clang-format-13 \ clang-tidy-11 if: matrix.id == 'clang-tidy' || matrix.id == 'clang-format' diff --git a/docker/Dockerfile b/docker/Dockerfile index 59901d7b2c..383c73565d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -135,7 +135,7 @@ RUN \ apt-get update \ # Use pinned versions so that we get updates with build caching && apt-get install -y --no-install-recommends \ - clang-format-11=1:11.0.1-2 \ + clang-format-13=1:13.0.1-6~deb11u1 \ clang-tidy-11=1:11.0.1-2 \ patch=2.7.6-7 \ software-properties-common=0.96.20.2-2.1 \ diff --git a/esphome/components/am43/cover/am43_cover.cpp b/esphome/components/am43/cover/am43_cover.cpp index b09f5ab767..d0ef4a2fbb 100644 --- a/esphome/components/am43/cover/am43_cover.cpp +++ b/esphome/components/am43/cover/am43_cover.cpp @@ -65,7 +65,7 @@ void Am43Component::control(const CoverCall &call) { if (this->invert_position_) pos = 1 - pos; - auto *packet = this->encoder_->get_set_position_request(100 - (uint8_t)(pos * 100)); + auto *packet = this->encoder_->get_set_position_request(100 - (uint8_t) (pos * 100)); auto status = esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_, packet->length, packet->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index c18e045a99..f4b18a1fd6 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -295,7 +295,7 @@ APIError APINoiseFrameHelper::state_action_() { if (aerr != APIError::OK) return aerr; // ignore contents, may be used in future for flags - prologue_.push_back((uint8_t)(frame.msg.size() >> 8)); + prologue_.push_back((uint8_t) (frame.msg.size() >> 8)); prologue_.push_back((uint8_t) frame.msg.size()); prologue_.insert(prologue_.end(), frame.msg.begin(), frame.msg.end()); @@ -492,9 +492,9 @@ APIError APINoiseFrameHelper::write_packet(uint16_t type, const uint8_t *payload // tmpbuf[1], tmpbuf[2] to be set later const uint8_t msg_offset = 3; const uint8_t payload_offset = msg_offset + 4; - tmpbuf[msg_offset + 0] = (uint8_t)(type >> 8); // type + tmpbuf[msg_offset + 0] = (uint8_t) (type >> 8); // type tmpbuf[msg_offset + 1] = (uint8_t) type; - tmpbuf[msg_offset + 2] = (uint8_t)(payload_len >> 8); // data_len + tmpbuf[msg_offset + 2] = (uint8_t) (payload_len >> 8); // data_len tmpbuf[msg_offset + 3] = (uint8_t) payload_len; // copy data std::copy(payload, payload + payload_len, &tmpbuf[payload_offset]); @@ -512,7 +512,7 @@ APIError APINoiseFrameHelper::write_packet(uint16_t type, const uint8_t *payload } size_t total_len = 3 + mbuf.size; - tmpbuf[1] = (uint8_t)(mbuf.size >> 8); + tmpbuf[1] = (uint8_t) (mbuf.size >> 8); tmpbuf[2] = (uint8_t) mbuf.size; struct iovec iov; @@ -610,7 +610,7 @@ APIError APINoiseFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) { APIError APINoiseFrameHelper::write_frame_(const uint8_t *data, size_t len) { uint8_t header[3]; header[0] = 0x01; // indicator - header[1] = (uint8_t)(len >> 8); + header[1] = (uint8_t) (len >> 8); header[2] = (uint8_t) len; struct iovec iov[2]; diff --git a/esphome/components/bme680/bme680.cpp b/esphome/components/bme680/bme680.cpp index e5704a8f9f..2b48f39e31 100644 --- a/esphome/components/bme680/bme680.cpp +++ b/esphome/components/bme680/bme680.cpp @@ -1,6 +1,6 @@ #include "bme680.h" -#include "esphome/core/log.h" #include "esphome/core/hal.h" +#include "esphome/core/log.h" namespace esphome { namespace bme680 { @@ -275,8 +275,8 @@ uint8_t BME680Component::calc_heater_resistance_(uint16_t temperature) { var3 = var1 + (var2 / 2); var4 = (var3 / (res_heat_range + 4)); var5 = (131 * res_heat_val) + 65536; - heatr_res_x100 = (int32_t)(((var4 / var5) - 250) * 34); - heatr_res = (uint8_t)((heatr_res_x100 + 50) / 100); + heatr_res_x100 = (int32_t) (((var4 / var5) - 250) * 34); + heatr_res = (uint8_t) ((heatr_res_x100 + 50) / 100); return heatr_res; } @@ -316,7 +316,7 @@ void BME680Component::read_data_() { uint32_t raw_temperature = (uint32_t(data[5]) << 12) | (uint32_t(data[6]) << 4) | (uint32_t(data[7]) >> 4); uint32_t raw_pressure = (uint32_t(data[2]) << 12) | (uint32_t(data[3]) << 4) | (uint32_t(data[4]) >> 4); uint32_t raw_humidity = (uint32_t(data[8]) << 8) | uint32_t(data[9]); - uint16_t raw_gas = (uint16_t)((uint32_t) data[13] * 4 | (((uint32_t) data[14]) / 64)); + uint16_t raw_gas = (uint16_t) ((uint32_t) data[13] * 4 | (((uint32_t) data[14]) / 64)); uint8_t gas_range = data[14] & 0x0F; float temperature = this->calc_temperature_(raw_temperature); diff --git a/esphome/components/ccs811/ccs811.cpp b/esphome/components/ccs811/ccs811.cpp index 5c60989afa..f1dadf673a 100644 --- a/esphome/components/ccs811/ccs811.cpp +++ b/esphome/components/ccs811/ccs811.cpp @@ -145,8 +145,8 @@ void CCS811Component::send_env_data_() { // https://github.com/adafruit/Adafruit_CCS811/blob/0990f5c620354d8bc087c4706bec091d8e6e5dfd/Adafruit_CCS811.cpp#L135-L142 uint16_t hum_conv = static_cast(lroundf(humidity * 512.0f + 0.5f)); uint16_t temp_conv = static_cast(lroundf(temperature * 512.0f + 0.5f)); - this->write_bytes(0x05, {(uint8_t)((hum_conv >> 8) & 0xff), (uint8_t)((hum_conv & 0xff)), - (uint8_t)((temp_conv >> 8) & 0xff), (uint8_t)((temp_conv & 0xff))}); + this->write_bytes(0x05, {(uint8_t) ((hum_conv >> 8) & 0xff), (uint8_t) ((hum_conv & 0xff)), + (uint8_t) ((temp_conv >> 8) & 0xff), (uint8_t) ((temp_conv & 0xff))}); } void CCS811Component::dump_config() { ESP_LOGCONFIG(TAG, "CCS811"); diff --git a/esphome/components/cs5460a/cs5460a.cpp b/esphome/components/cs5460a/cs5460a.cpp index b0c0531936..fb8e50b87a 100644 --- a/esphome/components/cs5460a/cs5460a.cpp +++ b/esphome/components/cs5460a/cs5460a.cpp @@ -305,7 +305,7 @@ bool CS5460AComponent::check_status_() { voltage_sensor_->publish_state(raw_voltage * voltage_multiplier_); if (power_sensor_ != nullptr && raw_energy != prev_raw_energy_) { - int32_t raw = (int32_t)(raw_energy << 8) >> 8; /* Sign-extend */ + int32_t raw = (int32_t) (raw_energy << 8) >> 8; /* Sign-extend */ power_sensor_->publish_state(raw * power_multiplier_); prev_raw_energy_ = raw_energy; } diff --git a/esphome/components/daly_bms/daly_bms.cpp b/esphome/components/daly_bms/daly_bms.cpp index 36047e02d0..3b41723327 100644 --- a/esphome/components/daly_bms/daly_bms.cpp +++ b/esphome/components/daly_bms/daly_bms.cpp @@ -61,8 +61,8 @@ void DalyBmsComponent::request_data_(uint8_t data_id) { request_message[9] = 0x00; // | request_message[10] = 0x00; // | request_message[11] = 0x00; // Empty Data - request_message[12] = (uint8_t)(request_message[0] + request_message[1] + request_message[2] + - request_message[3]); // Checksum (Lower byte of the other bytes sum) + request_message[12] = (uint8_t) (request_message[0] + request_message[1] + request_message[2] + + request_message[3]); // Checksum (Lower byte of the other bytes sum) this->write_array(request_message, sizeof(request_message)); this->flush(); diff --git a/esphome/components/dfplayer/dfplayer.cpp b/esphome/components/dfplayer/dfplayer.cpp index dcba95e20c..e16479570f 100644 --- a/esphome/components/dfplayer/dfplayer.cpp +++ b/esphome/components/dfplayer/dfplayer.cpp @@ -19,7 +19,7 @@ void DFPlayer::play_folder(uint16_t folder, uint16_t file) { } void DFPlayer::send_cmd_(uint8_t cmd, uint16_t argument) { - uint8_t buffer[10]{0x7e, 0xff, 0x06, cmd, 0x01, (uint8_t)(argument >> 8), (uint8_t) argument, 0x00, 0x00, 0xef}; + uint8_t buffer[10]{0x7e, 0xff, 0x06, cmd, 0x01, (uint8_t) (argument >> 8), (uint8_t) argument, 0x00, 0x00, 0xef}; uint16_t checksum = 0; for (uint8_t i = 1; i < 7; i++) checksum += buffer[i]; diff --git a/esphome/components/display/display_buffer.cpp b/esphome/components/display/display_buffer.cpp index 7cd85dabd4..19751e7355 100644 --- a/esphome/components/display/display_buffer.cpp +++ b/esphome/components/display/display_buffer.cpp @@ -664,7 +664,7 @@ bool Animation::get_pixel(int x, int y) const { return false; const uint32_t width_8 = ((this->width_ + 7u) / 8u) * 8u; const uint32_t frame_index = this->height_ * width_8 * this->current_frame_; - if (frame_index >= (uint32_t)(this->width_ * this->height_ * this->animation_frame_count_)) + if (frame_index >= (uint32_t) (this->width_ * this->height_ * this->animation_frame_count_)) return false; const uint32_t pos = x + y * width_8 + frame_index; return progmem_read_byte(this->data_start_ + (pos / 8u)) & (0x80 >> (pos % 8u)); @@ -673,7 +673,7 @@ Color Animation::get_color_pixel(int x, int y) const { if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_) return Color::BLACK; const uint32_t frame_index = this->width_ * this->height_ * this->current_frame_; - if (frame_index >= (uint32_t)(this->width_ * this->height_ * this->animation_frame_count_)) + if (frame_index >= (uint32_t) (this->width_ * this->height_ * this->animation_frame_count_)) return Color::BLACK; const uint32_t pos = (x + y * this->width_ + frame_index) * 3; const uint32_t color32 = (progmem_read_byte(this->data_start_ + pos + 2) << 0) | @@ -685,7 +685,7 @@ Color Animation::get_rgb565_pixel(int x, int y) const { if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_) return Color::BLACK; const uint32_t frame_index = this->width_ * this->height_ * this->current_frame_; - if (frame_index >= (uint32_t)(this->width_ * this->height_ * this->animation_frame_count_)) + if (frame_index >= (uint32_t) (this->width_ * this->height_ * this->animation_frame_count_)) return Color::BLACK; const uint32_t pos = (x + y * this->width_ + frame_index) * 2; uint16_t rgb565 = @@ -699,7 +699,7 @@ Color Animation::get_grayscale_pixel(int x, int y) const { if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_) return Color::BLACK; const uint32_t frame_index = this->width_ * this->height_ * this->current_frame_; - if (frame_index >= (uint32_t)(this->width_ * this->height_ * this->animation_frame_count_)) + if (frame_index >= (uint32_t) (this->width_ * this->height_ * this->animation_frame_count_)) return Color::BLACK; const uint32_t pos = (x + y * this->width_ + frame_index); const uint8_t gray = progmem_read_byte(this->data_start_ + pos); diff --git a/esphome/components/ens210/ens210.cpp b/esphome/components/ens210/ens210.cpp index a9c519856b..86890c05e8 100644 --- a/esphome/components/ens210/ens210.cpp +++ b/esphome/components/ens210/ens210.cpp @@ -168,7 +168,7 @@ void ENS210Component::update() { return; } // Pack bytes for humidity - h_val_data = (uint32_t)((uint32_t) data[5] << 16 | (uint32_t) data[4] << 8 | (uint32_t) data[3]); + h_val_data = (uint32_t) ((uint32_t) data[5] << 16 | (uint32_t) data[4] << 8 | (uint32_t) data[3]); // Extract humidity data and update the status extract_measurement_(h_val_data, &humidity_data, &humidity_status); @@ -183,7 +183,7 @@ void ENS210Component::update() { return; } // Pack bytes for temperature - t_val_data = (uint32_t)((uint32_t) data[2] << 16 | (uint32_t) data[1] << 8 | (uint32_t) data[0]); + t_val_data = (uint32_t) ((uint32_t) data[2] << 16 | (uint32_t) data[1] << 8 | (uint32_t) data[0]); // Extract temperature data and update the status extract_measurement_(t_val_data, &temperature_data, &temperature_status); diff --git a/esphome/components/esp32/core.cpp b/esphome/components/esp32/core.cpp index 6123d83a34..b47392bc6b 100644 --- a/esphome/components/esp32/core.cpp +++ b/esphome/components/esp32/core.cpp @@ -23,7 +23,7 @@ void loop(); namespace esphome { void IRAM_ATTR HOT yield() { vPortYield(); } -uint32_t IRAM_ATTR HOT millis() { return (uint32_t)(esp_timer_get_time() / 1000ULL); } +uint32_t IRAM_ATTR HOT millis() { return (uint32_t) (esp_timer_get_time() / 1000ULL); } void IRAM_ATTR HOT delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); } uint32_t IRAM_ATTR HOT micros() { return (uint32_t) esp_timer_get_time(); } void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); } diff --git a/esphome/components/esp32_ble_client/ble_client_base.cpp b/esphome/components/esp32_ble_client/ble_client_base.cpp index 9ca82c7239..40eff49266 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.cpp +++ b/esphome/components/esp32_ble_client/ble_client_base.cpp @@ -316,18 +316,18 @@ float BLEClientBase::parse_char_value(uint8_t *value, uint16_t length) { case 0xD: // int12. case 0xE: // int16. if (length > 2) { - return (float) ((int16_t)(value[1] << 8) + (int16_t) value[2]); + return (float) ((int16_t) (value[1] << 8) + (int16_t) value[2]); } // fall through case 0xF: // int24. if (length > 3) { - return (float) ((int32_t)(value[1] << 16) + (int32_t)(value[2] << 8) + (int32_t)(value[3])); + return (float) ((int32_t) (value[1] << 16) + (int32_t) (value[2] << 8) + (int32_t) (value[3])); } // fall through case 0x10: // int32. if (length > 4) { - return (float) ((int32_t)(value[1] << 24) + (int32_t)(value[2] << 16) + (int32_t)(value[3] << 8) + - (int32_t)(value[4])); + return (float) ((int32_t) (value[1] << 24) + (int32_t) (value[2] << 16) + (int32_t) (value[3] << 8) + + (int32_t) (value[4])); } } ESP_LOGW(TAG, "[%d] [%s] Cannot parse characteristic value of type 0x%x length %d", this->connection_index_, diff --git a/esphome/components/esp32_ble_client/ble_client_base.h b/esphome/components/esp32_ble_client/ble_client_base.h index 2879da4d8c..97886d0b19 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.h +++ b/esphome/components/esp32_ble_client/ble_client_base.h @@ -45,10 +45,11 @@ class BLEClientBase : public espbt::ESPBTClient, public Component { memset(this->remote_bda_, 0, sizeof(this->remote_bda_)); this->address_str_ = ""; } else { - this->address_str_ = str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, (uint8_t)(this->address_ >> 40) & 0xff, - (uint8_t)(this->address_ >> 32) & 0xff, (uint8_t)(this->address_ >> 24) & 0xff, - (uint8_t)(this->address_ >> 16) & 0xff, (uint8_t)(this->address_ >> 8) & 0xff, - (uint8_t)(this->address_ >> 0) & 0xff); + this->address_str_ = + str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, (uint8_t) (this->address_ >> 40) & 0xff, + (uint8_t) (this->address_ >> 32) & 0xff, (uint8_t) (this->address_ >> 24) & 0xff, + (uint8_t) (this->address_ >> 16) & 0xff, (uint8_t) (this->address_ >> 8) & 0xff, + (uint8_t) (this->address_ >> 0) & 0xff); } } std::string address_str() const { return this->address_str_; } diff --git a/esphome/components/esp32_ble_server/ble_characteristic.cpp b/esphome/components/esp32_ble_server/ble_characteristic.cpp index df822ac0b9..15a51f6ede 100644 --- a/esphome/components/esp32_ble_server/ble_characteristic.cpp +++ b/esphome/components/esp32_ble_server/ble_characteristic.cpp @@ -148,44 +148,44 @@ bool BLECharacteristic::is_failed() { void BLECharacteristic::set_broadcast_property(bool value) { if (value) { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_BROADCAST); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_BROADCAST); } else { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST); } } void BLECharacteristic::set_indicate_property(bool value) { if (value) { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_INDICATE); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_INDICATE); } else { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_INDICATE); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_INDICATE); } } void BLECharacteristic::set_notify_property(bool value) { if (value) { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_NOTIFY); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_NOTIFY); } else { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY); } } void BLECharacteristic::set_read_property(bool value) { if (value) { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_READ); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_READ); } else { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_READ); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_READ); } } void BLECharacteristic::set_write_property(bool value) { if (value) { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE); } else { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE); } } void BLECharacteristic::set_write_no_response_property(bool value) { if (value) { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE_NR); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE_NR); } else { - this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE_NR); + this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE_NR); } } diff --git a/esphome/components/fingerprint_grow/fingerprint_grow.cpp b/esphome/components/fingerprint_grow/fingerprint_grow.cpp index 1d6cb776b7..d27b0ca4cd 100644 --- a/esphome/components/fingerprint_grow/fingerprint_grow.cpp +++ b/esphome/components/fingerprint_grow/fingerprint_grow.cpp @@ -95,7 +95,7 @@ void FingerprintGrowComponent::scan_and_match_() { } if (this->scan_image_(1) == OK) { this->waiting_removal_ = true; - this->data_ = {SEARCH, 0x01, 0x00, 0x00, (uint8_t)(this->capacity_ >> 8), (uint8_t)(this->capacity_ & 0xFF)}; + this->data_ = {SEARCH, 0x01, 0x00, 0x00, (uint8_t) (this->capacity_ >> 8), (uint8_t) (this->capacity_ & 0xFF)}; switch (this->send_command_()) { case OK: { ESP_LOGD(TAG, "Fingerprint matched"); @@ -171,7 +171,7 @@ uint8_t FingerprintGrowComponent::save_fingerprint_() { } ESP_LOGI(TAG, "Storing model"); - this->data_ = {STORE, 0x01, (uint8_t)(this->enrollment_slot_ >> 8), (uint8_t)(this->enrollment_slot_ & 0xFF)}; + this->data_ = {STORE, 0x01, (uint8_t) (this->enrollment_slot_ >> 8), (uint8_t) (this->enrollment_slot_ & 0xFF)}; switch (this->send_command_()) { case OK: ESP_LOGI(TAG, "Stored model"); @@ -188,8 +188,8 @@ uint8_t FingerprintGrowComponent::save_fingerprint_() { bool FingerprintGrowComponent::check_password_() { ESP_LOGD(TAG, "Checking password"); - this->data_ = {VERIFY_PASSWORD, (uint8_t)(this->password_ >> 24), (uint8_t)(this->password_ >> 16), - (uint8_t)(this->password_ >> 8), (uint8_t)(this->password_ & 0xFF)}; + this->data_ = {VERIFY_PASSWORD, (uint8_t) (this->password_ >> 24), (uint8_t) (this->password_ >> 16), + (uint8_t) (this->password_ >> 8), (uint8_t) (this->password_ & 0xFF)}; switch (this->send_command_()) { case OK: ESP_LOGD(TAG, "Password verified"); @@ -203,8 +203,8 @@ bool FingerprintGrowComponent::check_password_() { bool FingerprintGrowComponent::set_password_() { ESP_LOGI(TAG, "Setting new password: %d", this->new_password_); - this->data_ = {SET_PASSWORD, (uint8_t)(this->new_password_ >> 24), (uint8_t)(this->new_password_ >> 16), - (uint8_t)(this->new_password_ >> 8), (uint8_t)(this->new_password_ & 0xFF)}; + this->data_ = {SET_PASSWORD, (uint8_t) (this->new_password_ >> 24), (uint8_t) (this->new_password_ >> 16), + (uint8_t) (this->new_password_ >> 8), (uint8_t) (this->new_password_ & 0xFF)}; if (this->send_command_() == OK) { ESP_LOGI(TAG, "New password successfully set"); ESP_LOGI(TAG, "Define the new password in your configuration and reflash now"); @@ -250,7 +250,7 @@ void FingerprintGrowComponent::get_fingerprint_count_() { void FingerprintGrowComponent::delete_fingerprint(uint16_t finger_id) { ESP_LOGI(TAG, "Deleting fingerprint in slot %d", finger_id); - this->data_ = {DELETE, (uint8_t)(finger_id >> 8), (uint8_t)(finger_id & 0xFF), 0x00, 0x01}; + this->data_ = {DELETE, (uint8_t) (finger_id >> 8), (uint8_t) (finger_id & 0xFF), 0x00, 0x01}; switch (this->send_command_()) { case OK: ESP_LOGI(TAG, "Deleted fingerprint"); @@ -320,8 +320,8 @@ void FingerprintGrowComponent::aura_led_control(uint8_t state, uint8_t speed, ui } uint8_t FingerprintGrowComponent::send_command_() { - this->write((uint8_t)(START_CODE >> 8)); - this->write((uint8_t)(START_CODE & 0xFF)); + this->write((uint8_t) (START_CODE >> 8)); + this->write((uint8_t) (START_CODE & 0xFF)); this->write(this->address_[0]); this->write(this->address_[1]); this->write(this->address_[2]); @@ -329,8 +329,8 @@ uint8_t FingerprintGrowComponent::send_command_() { this->write(COMMAND); uint16_t wire_length = this->data_.size() + 2; - this->write((uint8_t)(wire_length >> 8)); - this->write((uint8_t)(wire_length & 0xFF)); + this->write((uint8_t) (wire_length >> 8)); + this->write((uint8_t) (wire_length & 0xFF)); uint16_t sum = ((wire_length) >> 8) + ((wire_length) &0xFF) + COMMAND; for (auto data : this->data_) { @@ -338,8 +338,8 @@ uint8_t FingerprintGrowComponent::send_command_() { sum += data; } - this->write((uint8_t)(sum >> 8)); - this->write((uint8_t)(sum & 0xFF)); + this->write((uint8_t) (sum >> 8)); + this->write((uint8_t) (sum & 0xFF)); this->data_.clear(); @@ -354,11 +354,11 @@ uint8_t FingerprintGrowComponent::send_command_() { byte = this->read(); switch (idx) { case 0: - if (byte != (uint8_t)(START_CODE >> 8)) + if (byte != (uint8_t) (START_CODE >> 8)) continue; break; case 1: - if (byte != (uint8_t)(START_CODE & 0xFF)) { + if (byte != (uint8_t) (START_CODE & 0xFF)) { idx = 0; continue; } diff --git a/esphome/components/fingerprint_grow/fingerprint_grow.h b/esphome/components/fingerprint_grow/fingerprint_grow.h index 96d02a1e8c..fd316237f7 100644 --- a/esphome/components/fingerprint_grow/fingerprint_grow.h +++ b/esphome/components/fingerprint_grow/fingerprint_grow.h @@ -91,10 +91,10 @@ class FingerprintGrowComponent : public PollingComponent, public uart::UARTDevic void dump_config() override; void set_address(uint32_t address) { - this->address_[0] = (uint8_t)(address >> 24); - this->address_[1] = (uint8_t)(address >> 16); - this->address_[2] = (uint8_t)(address >> 8); - this->address_[3] = (uint8_t)(address & 0xFF); + this->address_[0] = (uint8_t) (address >> 24); + this->address_[1] = (uint8_t) (address >> 16); + this->address_[2] = (uint8_t) (address >> 8); + this->address_[3] = (uint8_t) (address & 0xFF); } void set_sensing_pin(GPIOPin *sensing_pin) { this->sensing_pin_ = sensing_pin; } void set_password(uint32_t password) { this->password_ = password; } diff --git a/esphome/components/hitachi_ac344/hitachi_ac344.cpp b/esphome/components/hitachi_ac344/hitachi_ac344.cpp index 7b93b00503..2825e4f04c 100644 --- a/esphome/components/hitachi_ac344/hitachi_ac344.cpp +++ b/esphome/components/hitachi_ac344/hitachi_ac344.cpp @@ -12,7 +12,7 @@ void set_bits(uint8_t *const dst, const uint8_t offset, const uint8_t nbits, con uint8_t mask = UINT8_MAX >> (8 - ((nbits > 8) ? 8 : nbits)); // Calculate the mask & clear the space for the data. // Clear the destination bits. - *dst &= ~(uint8_t)(mask << offset); + *dst &= ~(uint8_t) (mask << offset); // Merge in the data. *dst |= ((data & mask) << offset); } diff --git a/esphome/components/hitachi_ac424/hitachi_ac424.cpp b/esphome/components/hitachi_ac424/hitachi_ac424.cpp index 65cfaa4175..0bfc3ae564 100644 --- a/esphome/components/hitachi_ac424/hitachi_ac424.cpp +++ b/esphome/components/hitachi_ac424/hitachi_ac424.cpp @@ -12,7 +12,7 @@ void set_bits(uint8_t *const dst, const uint8_t offset, const uint8_t nbits, con uint8_t mask = UINT8_MAX >> (8 - ((nbits > 8) ? 8 : nbits)); // Calculate the mask & clear the space for the data. // Clear the destination bits. - *dst &= ~(uint8_t)(mask << offset); + *dst &= ~(uint8_t) (mask << offset); // Merge in the data. *dst |= ((data & mask) << offset); } diff --git a/esphome/components/honeywellabp/honeywellabp.cpp b/esphome/components/honeywellabp/honeywellabp.cpp index 910c39e8c8..124bd6bb95 100644 --- a/esphome/components/honeywellabp/honeywellabp.cpp +++ b/esphome/components/honeywellabp/honeywellabp.cpp @@ -35,9 +35,9 @@ uint8_t HONEYWELLABPSensor::readsensor_() { // if device is normal and there is new data, bitmask and save the raw data if (status_ == 0) { // 14 - bit pressure is the last 6 bits of byte 0 (high bits) & all of byte 1 (lowest 8 bits) - pressure_count_ = ((uint16_t)(buf_[0]) << 8 & 0x3F00) | ((uint16_t)(buf_[1]) & 0xFF); + pressure_count_ = ((uint16_t) (buf_[0]) << 8 & 0x3F00) | ((uint16_t) (buf_[1]) & 0xFF); // 11 - bit temperature is all of byte 2 (lowest 8 bits) and the first three bits of byte 3 - temperature_count_ = (((uint16_t)(buf_[2]) << 3) & 0x7F8) | (((uint16_t)(buf_[3]) >> 5) & 0x7); + temperature_count_ = (((uint16_t) (buf_[2]) << 3) & 0x7F8) | (((uint16_t) (buf_[3]) >> 5) & 0x7); ESP_LOGV(TAG, "Sensor pressure_count_ %d", pressure_count_); ESP_LOGV(TAG, "Sensor temperature_count_ %d", temperature_count_); } diff --git a/esphome/components/ili9xxx/ili9xxx_display.cpp b/esphome/components/ili9xxx/ili9xxx_display.cpp index 0091a2aabc..1b5248fa29 100644 --- a/esphome/components/ili9xxx/ili9xxx_display.cpp +++ b/esphome/components/ili9xxx/ili9xxx_display.cpp @@ -1,8 +1,8 @@ #include "ili9xxx_display.h" -#include "esphome/core/log.h" #include "esphome/core/application.h" -#include "esphome/core/helpers.h" #include "esphome/core/hal.h" +#include "esphome/core/helpers.h" +#include "esphome/core/log.h" namespace esphome { namespace ili9xxx { @@ -85,7 +85,7 @@ void ILI9XXXDisplay::fill(Color color) { case BITS_16: new_color = display::ColorUtil::color_to_565(color); for (uint32_t i = 0; i < this->get_buffer_length_() * 2; i = i + 2) { - this->buffer_[i] = (uint8_t)(new_color >> 8); + this->buffer_[i] = (uint8_t) (new_color >> 8); this->buffer_[i + 1] = (uint8_t) new_color; } return; @@ -111,8 +111,8 @@ void HOT ILI9XXXDisplay::draw_absolute_pixel_internal(int x, int y, Color color) case BITS_16: pos = pos * 2; new_color = display::ColorUtil::color_to_565(color, display::ColorOrder::COLOR_ORDER_RGB); - if (this->buffer_[pos] != (uint8_t)(new_color >> 8)) { - this->buffer_[pos] = (uint8_t)(new_color >> 8); + if (this->buffer_[pos] != (uint8_t) (new_color >> 8)) { + this->buffer_[pos] = (uint8_t) (new_color >> 8); updated = true; } pos = pos + 1; @@ -192,9 +192,9 @@ void ILI9XXXDisplay::display_() { uint8_t pass_buff[3]; - pass_buff[2] = (uint8_t)((red / 32.0) * 64) << 2; + pass_buff[2] = (uint8_t) ((red / 32.0) * 64) << 2; pass_buff[1] = (uint8_t) green << 2; - pass_buff[0] = (uint8_t)((blue / 32.0) * 64) << 2; + pass_buff[0] = (uint8_t) ((blue / 32.0) * 64) << 2; this->write_array(pass_buff, sizeof(pass_buff)); } diff --git a/esphome/components/json/json_util.cpp b/esphome/components/json/json_util.cpp index f105280b23..f27d441804 100644 --- a/esphome/components/json/json_util.cpp +++ b/esphome/components/json/json_util.cpp @@ -73,7 +73,7 @@ void parse_json(const std::string &data, const json_parse_t &f) { const size_t free_heap = rp2040.getFreeHeap(); #endif bool pass = false; - size_t request_size = std::min(free_heap, (size_t)(data.size() * 1.5)); + size_t request_size = std::min(free_heap, (size_t) (data.size() * 1.5)); do { DynamicJsonDocument json_document(request_size); if (json_document.capacity() == 0) { diff --git a/esphome/components/lcd_gpio/gpio_lcd_display.cpp b/esphome/components/lcd_gpio/gpio_lcd_display.cpp index 94ddc34051..a738893816 100644 --- a/esphome/components/lcd_gpio/gpio_lcd_display.cpp +++ b/esphome/components/lcd_gpio/gpio_lcd_display.cpp @@ -17,7 +17,7 @@ void GPIOLCDDisplay::setup() { this->enable_pin_->setup(); // OUTPUT this->enable_pin_->digital_write(false); - for (uint8_t i = 0; i < (uint8_t)(this->is_four_bit_mode() ? 4u : 8u); i++) { + for (uint8_t i = 0; i < (uint8_t) (this->is_four_bit_mode() ? 4u : 8u); i++) { this->data_pins_[i]->setup(); // OUTPUT this->data_pins_[i]->digital_write(false); } diff --git a/esphome/components/ld2410/ld2410.h b/esphome/components/ld2410/ld2410.h index 5a35798bc2..8edb83a8d5 100644 --- a/esphome/components/ld2410/ld2410.h +++ b/esphome/components/ld2410/ld2410.h @@ -118,7 +118,7 @@ class LD2410Component : public Component, public uart::UARTDevice { #endif std::vector rx_buffer_; - int two_byte_to_int_(char firstbyte, char secondbyte) { return (int16_t)(secondbyte << 8) + firstbyte; } + int two_byte_to_int_(char firstbyte, char secondbyte) { return (int16_t) (secondbyte << 8) + firstbyte; } void send_command_(uint8_t command_str, uint8_t *command_value, int command_value_len); void set_max_distances_timeout_(uint8_t max_moving_distance_range, uint8_t max_still_distance_range, diff --git a/esphome/components/light/color_mode.h b/esphome/components/light/color_mode.h index 77c377d39e..e524763c9f 100644 --- a/esphome/components/light/color_mode.h +++ b/esphome/components/light/color_mode.h @@ -52,25 +52,26 @@ enum class ColorMode : uint8_t { /// Only on/off control. ON_OFF = (uint8_t) ColorCapability::ON_OFF, /// Dimmable light. - BRIGHTNESS = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS), + BRIGHTNESS = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS), /// White output only (use only if the light also has another color mode such as RGB). - WHITE = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::WHITE), + WHITE = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::WHITE), /// Controllable color temperature output. COLOR_TEMPERATURE = - (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::COLOR_TEMPERATURE), + (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::COLOR_TEMPERATURE), /// Cold and warm white output with individually controllable brightness. - COLD_WARM_WHITE = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::COLD_WARM_WHITE), + COLD_WARM_WHITE = + (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::COLD_WARM_WHITE), /// RGB color output. - RGB = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB), + RGB = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB), /// RGB color output and a separate white output. RGB_WHITE = - (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB | ColorCapability::WHITE), + (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB | ColorCapability::WHITE), /// RGB color output and a separate white output with controllable color temperature. - RGB_COLOR_TEMPERATURE = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB | - ColorCapability::WHITE | ColorCapability::COLOR_TEMPERATURE), + RGB_COLOR_TEMPERATURE = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB | + ColorCapability::WHITE | ColorCapability::COLOR_TEMPERATURE), /// RGB color output, and separate cold and warm white outputs. - RGB_COLD_WARM_WHITE = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB | - ColorCapability::COLD_WARM_WHITE), + RGB_COLD_WARM_WHITE = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB | + ColorCapability::COLD_WARM_WHITE), }; /// Helper class to allow bitwise operations on ColorMode with ColorCapability diff --git a/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp b/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp index b92d7d6f10..b89cf2a724 100644 --- a/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp +++ b/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp @@ -113,8 +113,8 @@ void LilygoT547Touchscreen::loop() { if (tp.state == 0x06) tp.state = 0x07; - uint16_t y = (uint16_t)((buffer[i * 5 + 1 + offset] << 4) | ((buffer[i * 5 + 3 + offset] >> 4) & 0x0F)); - uint16_t x = (uint16_t)((buffer[i * 5 + 2 + offset] << 4) | (buffer[i * 5 + 3 + offset] & 0x0F)); + uint16_t y = (uint16_t) ((buffer[i * 5 + 1 + offset] << 4) | ((buffer[i * 5 + 3 + offset] >> 4) & 0x0F)); + uint16_t x = (uint16_t) ((buffer[i * 5 + 2 + offset] << 4) | (buffer[i * 5 + 3 + offset] & 0x0F)); switch (this->rotation_) { case ROTATE_0_DEGREES: @@ -142,8 +142,8 @@ void LilygoT547Touchscreen::loop() { tp.id = (buffer[0] >> 4) & 0x0F; tp.state = 0x06; - uint16_t y = (uint16_t)((buffer[0 * 5 + 1] << 4) | ((buffer[0 * 5 + 3] >> 4) & 0x0F)); - uint16_t x = (uint16_t)((buffer[0 * 5 + 2] << 4) | (buffer[0 * 5 + 3] & 0x0F)); + uint16_t y = (uint16_t) ((buffer[0 * 5 + 1] << 4) | ((buffer[0 * 5 + 3] >> 4) & 0x0F)); + uint16_t x = (uint16_t) ((buffer[0 * 5 + 2] << 4) | (buffer[0 * 5 + 3] & 0x0F)); switch (this->rotation_) { case ROTATE_0_DEGREES: diff --git a/esphome/components/mcp2515/mcp2515.cpp b/esphome/components/mcp2515/mcp2515.cpp index e845c79a64..b90b4de66d 100644 --- a/esphome/components/mcp2515/mcp2515.cpp +++ b/esphome/components/mcp2515/mcp2515.cpp @@ -148,19 +148,19 @@ canbus::Error MCP2515::set_clk_out_(const CanClkOut divisor) { } void MCP2515::prepare_id_(uint8_t *buffer, const bool extended, const uint32_t id) { - uint16_t canid = (uint16_t)(id & 0x0FFFF); + uint16_t canid = (uint16_t) (id & 0x0FFFF); if (extended) { - buffer[MCP_EID0] = (uint8_t)(canid & 0xFF); - buffer[MCP_EID8] = (uint8_t)(canid >> 8); - canid = (uint16_t)(id >> 16); - buffer[MCP_SIDL] = (uint8_t)(canid & 0x03); - buffer[MCP_SIDL] += (uint8_t)((canid & 0x1C) << 3); + buffer[MCP_EID0] = (uint8_t) (canid & 0xFF); + buffer[MCP_EID8] = (uint8_t) (canid >> 8); + canid = (uint16_t) (id >> 16); + buffer[MCP_SIDL] = (uint8_t) (canid & 0x03); + buffer[MCP_SIDL] += (uint8_t) ((canid & 0x1C) << 3); buffer[MCP_SIDL] |= TXB_EXIDE_MASK; - buffer[MCP_SIDH] = (uint8_t)(canid >> 5); + buffer[MCP_SIDH] = (uint8_t) (canid >> 5); } else { - buffer[MCP_SIDH] = (uint8_t)(canid >> 3); - buffer[MCP_SIDL] = (uint8_t)((canid & 0x07) << 5); + buffer[MCP_SIDH] = (uint8_t) (canid >> 3); + buffer[MCP_SIDL] = (uint8_t) ((canid & 0x07) << 5); buffer[MCP_EID0] = 0; buffer[MCP_EID8] = 0; } diff --git a/esphome/components/mcp9600/mcp9600.cpp b/esphome/components/mcp9600/mcp9600.cpp index 3fdd788fc6..b56c838f78 100644 --- a/esphome/components/mcp9600/mcp9600.cpp +++ b/esphome/components/mcp9600/mcp9600.cpp @@ -32,7 +32,7 @@ void MCP9600Component::setup() { uint16_t dev_id = 0; this->read_byte_16(MCP9600_REGISTER_DEVICE_ID, &dev_id); - this->device_id_ = (uint8_t)(dev_id >> 8); + this->device_id_ = (uint8_t) (dev_id >> 8); // Allows both MCP9600's and MCP9601's to be connected. if (this->device_id_ != (uint8_t) 0x40 && this->device_id_ != (uint8_t) 0x41) { diff --git a/esphome/components/mcp9808/mcp9808.cpp b/esphome/components/mcp9808/mcp9808.cpp index fca1331fc3..626fcd540d 100644 --- a/esphome/components/mcp9808/mcp9808.cpp +++ b/esphome/components/mcp9808/mcp9808.cpp @@ -54,16 +54,16 @@ void MCP9808Sensor::update() { } float temp = NAN; - uint8_t msb = (uint8_t)((raw_temp & 0xff00) >> 8); + uint8_t msb = (uint8_t) ((raw_temp & 0xff00) >> 8); uint8_t lsb = raw_temp & 0x00ff; msb = msb & MCP9808_AMBIENT_CLEAR_FLAGS; if ((msb & MCP9808_AMBIENT_TEMP_NEGATIVE) == MCP9808_AMBIENT_TEMP_NEGATIVE) { msb = msb & MCP9808_AMBIENT_CLEAR_SIGN; - temp = (256 - ((uint16_t)(msb) *16 + lsb / 16.0f)) * -1; + temp = (256 - ((uint16_t) (msb) *16 + lsb / 16.0f)) * -1; } else { - temp = (uint16_t)(msb) *16 + lsb / 16.0f; + temp = (uint16_t) (msb) *16 + lsb / 16.0f; } if (std::isnan(temp)) { diff --git a/esphome/components/mopeka_pro_check/mopeka_pro_check.cpp b/esphome/components/mopeka_pro_check/mopeka_pro_check.cpp index 60592b00ad..02d77a6b33 100644 --- a/esphome/components/mopeka_pro_check/mopeka_pro_check.cpp +++ b/esphome/components/mopeka_pro_check/mopeka_pro_check.cpp @@ -123,7 +123,8 @@ uint32_t MopekaProCheck::parse_distance_(const std::vector &message) { double raw_level = raw & 0x3FFF; double raw_t = (message[2] & 0x7F); - return (uint32_t)(raw_level * (MOPEKA_LPG_COEF[0] + MOPEKA_LPG_COEF[1] * raw_t + MOPEKA_LPG_COEF[2] * raw_t * raw_t)); + return (uint32_t) (raw_level * + (MOPEKA_LPG_COEF[0] + MOPEKA_LPG_COEF[1] * raw_t + MOPEKA_LPG_COEF[2] * raw_t * raw_t)); } uint8_t MopekaProCheck::parse_temperature_(const std::vector &message) { return (message[2] & 0x7F) - 40; } diff --git a/esphome/components/mopeka_std_check/mopeka_std_check.cpp b/esphome/components/mopeka_std_check/mopeka_std_check.cpp index cbe51b8f2d..ae7b646b9d 100644 --- a/esphome/components/mopeka_std_check/mopeka_std_check.cpp +++ b/esphome/components/mopeka_std_check/mopeka_std_check.cpp @@ -216,7 +216,7 @@ uint8_t MopekaStdCheck::parse_temperature_(const mopeka_std_package *message) { if (tmp == 0x0) { return -40; } else { - return (uint8_t)((tmp - 25.0f) * 1.776964f); + return (uint8_t) ((tmp - 25.0f) * 1.776964f); } } diff --git a/esphome/components/network/ip_address.h b/esphome/components/network/ip_address.h index d69dee4547..af198179ba 100644 --- a/esphome/components/network/ip_address.h +++ b/esphome/components/network/ip_address.h @@ -12,10 +12,10 @@ struct IPAddress { IPAddress() : addr_({0, 0, 0, 0}) {} IPAddress(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth) : addr_({first, second, third, fourth}) {} IPAddress(uint32_t raw) { - addr_[0] = (uint8_t)(raw >> 0); - addr_[1] = (uint8_t)(raw >> 8); - addr_[2] = (uint8_t)(raw >> 16); - addr_[3] = (uint8_t)(raw >> 24); + addr_[0] = (uint8_t) (raw >> 0); + addr_[1] = (uint8_t) (raw >> 8); + addr_[2] = (uint8_t) (raw >> 16); + addr_[3] = (uint8_t) (raw >> 24); } operator uint32_t() const { uint32_t res = 0; diff --git a/esphome/components/pipsolar/pipsolar.cpp b/esphome/components/pipsolar/pipsolar.cpp index 5f203645fe..c9d1ed00f6 100644 --- a/esphome/components/pipsolar/pipsolar.cpp +++ b/esphome/components/pipsolar/pipsolar.cpp @@ -770,15 +770,15 @@ uint8_t Pipsolar::check_incoming_crc_() { uint16_t crc16; crc16 = cal_crc_half_(read_buffer_, read_pos_ - 3); ESP_LOGD(TAG, "checking crc on incoming message"); - if (((uint8_t)((crc16) >> 8)) == read_buffer_[read_pos_ - 3] && - ((uint8_t)((crc16) &0xff)) == read_buffer_[read_pos_ - 2]) { + if (((uint8_t) ((crc16) >> 8)) == read_buffer_[read_pos_ - 3] && + ((uint8_t) ((crc16) &0xff)) == read_buffer_[read_pos_ - 2]) { ESP_LOGD(TAG, "CRC OK"); read_buffer_[read_pos_ - 1] = 0; read_buffer_[read_pos_ - 2] = 0; read_buffer_[read_pos_ - 3] = 0; return 1; } - ESP_LOGD(TAG, "CRC NOK expected: %X %X but got: %X %X", ((uint8_t)((crc16) >> 8)), ((uint8_t)((crc16) &0xff)), + ESP_LOGD(TAG, "CRC NOK expected: %X %X but got: %X %X", ((uint8_t) ((crc16) >> 8)), ((uint8_t) ((crc16) &0xff)), read_buffer_[read_pos_ - 3], read_buffer_[read_pos_ - 2]); return 0; } @@ -800,8 +800,8 @@ uint8_t Pipsolar::send_next_command_() { crc16 = cal_crc_half_(byte_command, length); this->write_str(command); // checksum - this->write(((uint8_t)((crc16) >> 8))); // highbyte - this->write(((uint8_t)((crc16) &0xff))); // lowbyte + this->write(((uint8_t) ((crc16) >> 8))); // highbyte + this->write(((uint8_t) ((crc16) &0xff))); // lowbyte // end Byte this->write(0x0D); ESP_LOGD(TAG, "Sending command from queue: %s with length %d", command, length); @@ -829,8 +829,8 @@ void Pipsolar::send_next_poll_() { this->write_array(this->used_polling_commands_[this->last_polling_command_].command, this->used_polling_commands_[this->last_polling_command_].length); // checksum - this->write(((uint8_t)((crc16) >> 8))); // highbyte - this->write(((uint8_t)((crc16) &0xff))); // lowbyte + this->write(((uint8_t) ((crc16) >> 8))); // highbyte + this->write(((uint8_t) ((crc16) &0xff))); // lowbyte // end Byte this->write(0x0D); ESP_LOGD(TAG, "Sending polling command : %s with length %d", @@ -882,7 +882,7 @@ void Pipsolar::add_polling_command_(const char *command, ENUMPollingCommand poll used_polling_command.command = new uint8_t[length]; // NOLINT(cppcoreguidelines-owning-memory) size_t i = 0; for (; beg != end; ++beg, ++i) { - used_polling_command.command[i] = (uint8_t)(*beg); + used_polling_command.command[i] = (uint8_t) (*beg); } used_polling_command.errors = 0; used_polling_command.identifier = polling_command; @@ -907,17 +907,17 @@ uint16_t Pipsolar::cal_crc_half_(uint8_t *msg, uint8_t len) { crc = 0; while (len-- != 0) { - da = ((uint8_t)(crc >> 8)) >> 4; + da = ((uint8_t) (crc >> 8)) >> 4; crc <<= 4; crc ^= crc_ta[da ^ (*ptr >> 4)]; - da = ((uint8_t)(crc >> 8)) >> 4; + da = ((uint8_t) (crc >> 8)) >> 4; crc <<= 4; crc ^= crc_ta[da ^ (*ptr & 0x0f)]; ptr++; } b_crc_low = crc; - b_crc_hign = (uint8_t)(crc >> 8); + b_crc_hign = (uint8_t) (crc >> 8); if (b_crc_low == 0x28 || b_crc_low == 0x0d || b_crc_low == 0x0a) b_crc_low++; diff --git a/esphome/components/qmp6988/qmp6988.cpp b/esphome/components/qmp6988/qmp6988.cpp index 5bad1e4a47..c24780eb25 100644 --- a/esphome/components/qmp6988/qmp6988.cpp +++ b/esphome/components/qmp6988/qmp6988.cpp @@ -121,38 +121,38 @@ bool QMP6988Component::get_calibration_data_() { } qmp6988_data_.qmp6988_cali.COE_a0 = - (QMP6988_S32_t)(((a_data_uint8_tr[18] << SHIFT_LEFT_12_POSITION) | - (a_data_uint8_tr[19] << SHIFT_LEFT_4_POSITION) | (a_data_uint8_tr[24] & 0x0f)) - << 12); + (QMP6988_S32_t) (((a_data_uint8_tr[18] << SHIFT_LEFT_12_POSITION) | + (a_data_uint8_tr[19] << SHIFT_LEFT_4_POSITION) | (a_data_uint8_tr[24] & 0x0f)) + << 12); qmp6988_data_.qmp6988_cali.COE_a0 = qmp6988_data_.qmp6988_cali.COE_a0 >> 12; qmp6988_data_.qmp6988_cali.COE_a1 = - (QMP6988_S16_t)(((a_data_uint8_tr[20]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[21]); + (QMP6988_S16_t) (((a_data_uint8_tr[20]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[21]); qmp6988_data_.qmp6988_cali.COE_a2 = - (QMP6988_S16_t)(((a_data_uint8_tr[22]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[23]); + (QMP6988_S16_t) (((a_data_uint8_tr[22]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[23]); qmp6988_data_.qmp6988_cali.COE_b00 = - (QMP6988_S32_t)(((a_data_uint8_tr[0] << SHIFT_LEFT_12_POSITION) | (a_data_uint8_tr[1] << SHIFT_LEFT_4_POSITION) | - ((a_data_uint8_tr[24] & 0xf0) >> SHIFT_RIGHT_4_POSITION)) - << 12); + (QMP6988_S32_t) (((a_data_uint8_tr[0] << SHIFT_LEFT_12_POSITION) | (a_data_uint8_tr[1] << SHIFT_LEFT_4_POSITION) | + ((a_data_uint8_tr[24] & 0xf0) >> SHIFT_RIGHT_4_POSITION)) + << 12); qmp6988_data_.qmp6988_cali.COE_b00 = qmp6988_data_.qmp6988_cali.COE_b00 >> 12; qmp6988_data_.qmp6988_cali.COE_bt1 = - (QMP6988_S16_t)(((a_data_uint8_tr[2]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[3]); + (QMP6988_S16_t) (((a_data_uint8_tr[2]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[3]); qmp6988_data_.qmp6988_cali.COE_bt2 = - (QMP6988_S16_t)(((a_data_uint8_tr[4]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[5]); + (QMP6988_S16_t) (((a_data_uint8_tr[4]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[5]); qmp6988_data_.qmp6988_cali.COE_bp1 = - (QMP6988_S16_t)(((a_data_uint8_tr[6]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[7]); + (QMP6988_S16_t) (((a_data_uint8_tr[6]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[7]); qmp6988_data_.qmp6988_cali.COE_b11 = - (QMP6988_S16_t)(((a_data_uint8_tr[8]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[9]); + (QMP6988_S16_t) (((a_data_uint8_tr[8]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[9]); qmp6988_data_.qmp6988_cali.COE_bp2 = - (QMP6988_S16_t)(((a_data_uint8_tr[10]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[11]); + (QMP6988_S16_t) (((a_data_uint8_tr[10]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[11]); qmp6988_data_.qmp6988_cali.COE_b12 = - (QMP6988_S16_t)(((a_data_uint8_tr[12]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[13]); + (QMP6988_S16_t) (((a_data_uint8_tr[12]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[13]); qmp6988_data_.qmp6988_cali.COE_b21 = - (QMP6988_S16_t)(((a_data_uint8_tr[14]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[15]); + (QMP6988_S16_t) (((a_data_uint8_tr[14]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[15]); qmp6988_data_.qmp6988_cali.COE_bp3 = - (QMP6988_S16_t)(((a_data_uint8_tr[16]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[17]); + (QMP6988_S16_t) (((a_data_uint8_tr[16]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[17]); ESP_LOGV(TAG, "<-----------calibration data-------------->\r\n"); ESP_LOGV(TAG, "COE_a0[%d] COE_a1[%d] COE_a2[%d] COE_b00[%d]\r\n", qmp6988_data_.qmp6988_cali.COE_a0, @@ -197,7 +197,7 @@ QMP6988_S16_t QMP6988Component::get_compensated_temperature_(qmp6988_ik_data_t * wk2 = ((QMP6988_S64_t) ik->a2 * (QMP6988_S64_t) dt) >> 14; // 30Q47+24-1=53 (39Q33) wk2 = (wk2 * (QMP6988_S64_t) dt) >> 10; // 39Q33+24-1=62 (52Q23) wk2 = ((wk1 + wk2) / 32767) >> 19; // 54,52->55Q23 (20Q04) - ret = (QMP6988_S16_t)((ik->a0 + wk2) >> 4); // 21Q4 -> 17Q0 + ret = (QMP6988_S16_t) ((ik->a0 + wk2) >> 4); // 21Q4 -> 17Q0 return ret; } @@ -332,13 +332,13 @@ void QMP6988Component::calculate_pressure_() { ESP_LOGE(TAG, "Error reading raw pressure/temp values"); return; } - p_read = (QMP6988_U32_t)((((QMP6988_U32_t)(a_data_uint8_tr[0])) << SHIFT_LEFT_16_POSITION) | - (((QMP6988_U16_t)(a_data_uint8_tr[1])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[2])); - p_raw = (QMP6988_S32_t)(p_read - SUBTRACTOR); + p_read = (QMP6988_U32_t) ((((QMP6988_U32_t) (a_data_uint8_tr[0])) << SHIFT_LEFT_16_POSITION) | + (((QMP6988_U16_t) (a_data_uint8_tr[1])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[2])); + p_raw = (QMP6988_S32_t) (p_read - SUBTRACTOR); - t_read = (QMP6988_U32_t)((((QMP6988_U32_t)(a_data_uint8_tr[3])) << SHIFT_LEFT_16_POSITION) | - (((QMP6988_U16_t)(a_data_uint8_tr[4])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[5])); - t_raw = (QMP6988_S32_t)(t_read - SUBTRACTOR); + t_read = (QMP6988_U32_t) ((((QMP6988_U32_t) (a_data_uint8_tr[3])) << SHIFT_LEFT_16_POSITION) | + (((QMP6988_U16_t) (a_data_uint8_tr[4])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[5])); + t_raw = (QMP6988_S32_t) (t_read - SUBTRACTOR); t_int = this->get_compensated_temperature_(&(qmp6988_data_.ik), t_raw); p_int = this->get_compensated_pressure_(&(qmp6988_data_.ik), p_raw, t_int); diff --git a/esphome/components/remote_base/rc5_protocol.cpp b/esphome/components/remote_base/rc5_protocol.cpp index 47a85cda57..cb6eed4c6c 100644 --- a/esphome/components/remote_base/rc5_protocol.cpp +++ b/esphome/components/remote_base/rc5_protocol.cpp @@ -78,7 +78,7 @@ optional RC5Protocol::decode(RemoteReceiveData src) { out_data |= 1; } - out.command = (uint8_t)(out_data & 0x3F) + (1 - field_bit) * 64u; + out.command = (uint8_t) (out_data & 0x3F) + (1 - field_bit) * 64u; out.address = (out_data >> 6) & 0x1F; return out; } diff --git a/esphome/components/scd30/scd30.cpp b/esphome/components/scd30/scd30.cpp index c25ed107b7..01abca0a1f 100644 --- a/esphome/components/scd30/scd30.cpp +++ b/esphome/components/scd30/scd30.cpp @@ -43,7 +43,7 @@ void SCD30Component::setup() { uint16_t(raw_firmware_version[0] & 0xFF)); if (this->temperature_offset_ != 0) { - if (!this->write_command(SCD30_CMD_TEMPERATURE_OFFSET, (uint16_t)(temperature_offset_ * 100.0))) { + if (!this->write_command(SCD30_CMD_TEMPERATURE_OFFSET, (uint16_t) (temperature_offset_ * 100.0))) { ESP_LOGE(TAG, "Sensor SCD30 error setting temperature offset."); this->error_code_ = MEASUREMENT_INIT_FAILED; this->mark_failed(); diff --git a/esphome/components/scd30/scd30.h b/esphome/components/scd30/scd30.h index 4a4ca832bf..40f075e673 100644 --- a/esphome/components/scd30/scd30.h +++ b/esphome/components/scd30/scd30.h @@ -16,7 +16,7 @@ class SCD30Component : public Component, public sensirion_common::SensirionI2CDe void set_automatic_self_calibration(bool asc) { enable_asc_ = asc; } void set_altitude_compensation(uint16_t altitude) { altitude_compensation_ = altitude; } void set_ambient_pressure_compensation(float pressure) { - ambient_pressure_compensation_ = (uint16_t)(pressure * 1000); + ambient_pressure_compensation_ = (uint16_t) (pressure * 1000); } void set_temperature_offset(float offset) { temperature_offset_ = offset; } void set_update_interval(uint16_t interval) { update_interval_ = interval; } diff --git a/esphome/components/scd4x/scd4x.cpp b/esphome/components/scd4x/scd4x.cpp index 117b92b901..a8a4129b48 100644 --- a/esphome/components/scd4x/scd4x.cpp +++ b/esphome/components/scd4x/scd4x.cpp @@ -50,7 +50,7 @@ void SCD4XComponent::setup() { uint16_t(raw_serial_number[0] & 0xFF), (uint16_t(raw_serial_number[1]) >> 8)); if (!this->write_command(SCD4X_CMD_TEMPERATURE_OFFSET, - (uint16_t)(temperature_offset_ * SCD4X_TEMPERATURE_OFFSET_MULTIPLIER))) { + (uint16_t) (temperature_offset_ * SCD4X_TEMPERATURE_OFFSET_MULTIPLIER))) { ESP_LOGE(TAG, "Error setting temperature offset."); this->error_code_ = MEASUREMENT_INIT_FAILED; this->mark_failed(); diff --git a/esphome/components/sgp4x/sgp4x.cpp b/esphome/components/sgp4x/sgp4x.cpp index 7fe46b9518..52f9adc808 100644 --- a/esphome/components/sgp4x/sgp4x.cpp +++ b/esphome/components/sgp4x/sgp4x.cpp @@ -234,8 +234,8 @@ bool SGP4xComponent::measure_raw_(uint16_t &voc_raw, uint16_t &nox_raw) { response_words = 2; } } - uint16_t rhticks = llround((uint16_t)((humidity * 65535) / 100)); - uint16_t tempticks = (uint16_t)(((temperature + 45) * 65535) / 175); + uint16_t rhticks = llround((uint16_t) ((humidity * 65535) / 100)); + uint16_t tempticks = (uint16_t) (((temperature + 45) * 65535) / 175); // first parameter are the relative humidity ticks data[0] = rhticks; // secomd parameter are the temperature ticks diff --git a/esphome/components/sht4x/sht4x.cpp b/esphome/components/sht4x/sht4x.cpp index bdc3e62d2f..0f9123434d 100644 --- a/esphome/components/sht4x/sht4x.cpp +++ b/esphome/components/sht4x/sht4x.cpp @@ -19,7 +19,7 @@ void SHT4XComponent::setup() { ESP_LOGCONFIG(TAG, "Setting up sht4x..."); if (this->duty_cycle_ > 0.0) { - uint32_t heater_interval = (uint32_t)(this->heater_time_ / this->duty_cycle_); + uint32_t heater_interval = (uint32_t) (this->heater_time_ / this->duty_cycle_); ESP_LOGD(TAG, "Heater interval: %i", heater_interval); if (this->heater_power_ == SHT4X_HEATERPOWER_HIGH) { diff --git a/esphome/components/st7920/st7920.cpp b/esphome/components/st7920/st7920.cpp index 63fa0ba72f..f336d24e24 100644 --- a/esphome/components/st7920/st7920.cpp +++ b/esphome/components/st7920/st7920.cpp @@ -74,7 +74,7 @@ void ST7920::goto_xy_(uint16_t x, uint16_t y) { void HOT ST7920::write_display_data() { uint8_t i, j, b; - for (j = 0; j < (uint8_t)(this->get_height_internal() / 2); j++) { + for (j = 0; j < (uint8_t) (this->get_height_internal() / 2); j++) { this->goto_xy_(0, j); this->enable(); for (i = 0; i < 16; i++) { // 16 bytes from line #0+ diff --git a/esphome/components/sun/sun.cpp b/esphome/components/sun/sun.cpp index 113c14d431..54aaf0942b 100644 --- a/esphome/components/sun/sun.cpp +++ b/esphome/components/sun/sun.cpp @@ -269,7 +269,7 @@ struct SunAtLocation { num_t jd = julian_day(date) + added_d; num_t eot = SunAtTime(jd).equation_of_time() * 240; - time_t new_timestamp = (time_t)(date.timestamp + added_d * 86400 - eot); + time_t new_timestamp = (time_t) (date.timestamp + added_d * 86400 - eot); return time::ESPTime::from_epoch_utc(new_timestamp); } }; diff --git a/esphome/components/tcs34725/tcs34725.cpp b/esphome/components/tcs34725/tcs34725.cpp index 276bf65ebf..88c59eb761 100644 --- a/esphome/components/tcs34725/tcs34725.cpp +++ b/esphome/components/tcs34725/tcs34725.cpp @@ -287,7 +287,7 @@ void TCS34725Component::update() { } // calculate register value from timing - uint8_t regval_atime = (uint8_t)(256.f - integration_time_next / 2.4f); + uint8_t regval_atime = (uint8_t) (256.f - integration_time_next / 2.4f); ESP_LOGD(TAG, "Integration time: %.1fms, ideal: %.1fms regval_new %d Gain: %.f Clear channel raw: %d gain reg: %d", this->integration_time_, integration_time_next, regval_atime, this->gain_, raw_c, this->gain_reg_); diff --git a/esphome/components/tm1637/tm1637.cpp b/esphome/components/tm1637/tm1637.cpp index be2192ea22..5b8cbc6004 100644 --- a/esphome/components/tm1637/tm1637.cpp +++ b/esphome/components/tm1637/tm1637.cpp @@ -168,7 +168,7 @@ uint8_t TM1637Display::get_keys() { // Bit | 7 6 5 4 3 2 1 0 // ------+------------------------ // To | 0 0 0 0 K2 S2 S1 S0 - key_code = (uint8_t)((key_code & 0x80) >> 7 | (key_code & 0x40) >> 5 | (key_code & 0x20) >> 3 | (key_code & 0x08)); + key_code = (uint8_t) ((key_code & 0x80) >> 7 | (key_code & 0x40) >> 5 | (key_code & 0x20) >> 3 | (key_code & 0x08)); } return key_code; } diff --git a/esphome/components/tm1638/tm1638.cpp b/esphome/components/tm1638/tm1638.cpp index 526b53f601..24cb4122bf 100644 --- a/esphome/components/tm1638/tm1638.cpp +++ b/esphome/components/tm1638/tm1638.cpp @@ -140,7 +140,7 @@ void TM1638Component::set_intensity(uint8_t brightness_level) { this->send_command_(TM1638_REGISTER_FIXEDADDRESS); if (brightness_level > 0) { - this->send_command_((uint8_t)(TM1638_REGISTER_DISPLAYON | intensity_)); + this->send_command_((uint8_t) (TM1638_REGISTER_DISPLAYON | intensity_)); } else { this->send_command_(TM1638_REGISTER_DISPLAYOFF); } diff --git a/esphome/components/tuya/tuya.cpp b/esphome/components/tuya/tuya.cpp index 79a9049b04..040b9b7ed5 100644 --- a/esphome/components/tuya/tuya.cpp +++ b/esphome/components/tuya/tuya.cpp @@ -381,8 +381,8 @@ void Tuya::handle_datapoints_(const uint8_t *buffer, size_t len) { } void Tuya::send_raw_command_(TuyaCommand command) { - uint8_t len_hi = (uint8_t)(command.payload.size() >> 8); - uint8_t len_lo = (uint8_t)(command.payload.size() & 0xFF); + uint8_t len_hi = (uint8_t) (command.payload.size() >> 8); + uint8_t len_lo = (uint8_t) (command.payload.size() & 0xFF); uint8_t version = 0; this->last_command_timestamp_ = millis(); diff --git a/esphome/components/vbus/sensor/vbus_sensor.cpp b/esphome/components/vbus/sensor/vbus_sensor.cpp index 57d5a355ad..8261773431 100644 --- a/esphome/components/vbus/sensor/vbus_sensor.cpp +++ b/esphome/components/vbus/sensor/vbus_sensor.cpp @@ -12,7 +12,7 @@ static inline uint16_t get_u16(std::vector &message, int start) { } static inline int16_t get_i16(std::vector &message, int start) { - return (int16_t)((message[start + 1] << 8) + message[start]); + return (int16_t) ((message[start + 1] << 8) + message[start]); } void DeltaSolBSPlusSensor::dump_config() { diff --git a/esphome/components/vl53l0x/vl53l0x_sensor.cpp b/esphome/components/vl53l0x/vl53l0x_sensor.cpp index f851cf6d73..b07779a653 100644 --- a/esphome/components/vl53l0x/vl53l0x_sensor.cpp +++ b/esphome/components/vl53l0x/vl53l0x_sensor.cpp @@ -88,7 +88,7 @@ void VL53L0XSensor::setup() { this->timeout_start_us_ = micros(); while (reg(0x83).get() == 0x00) { - if (this->timeout_us_ > 0 && ((uint16_t)(micros() - this->timeout_start_us_) > this->timeout_us_)) { + if (this->timeout_us_ > 0 && ((uint16_t) (micros() - this->timeout_start_us_) > this->timeout_us_)) { ESP_LOGE(TAG, "'%s' - setup timeout", this->name_.c_str()); this->mark_failed(); return; diff --git a/esphome/components/web_server/web_server.cpp b/esphome/components/web_server/web_server.cpp index 6c74c79ce6..80a53a7515 100644 --- a/esphome/components/web_server/web_server.cpp +++ b/esphome/components/web_server/web_server.cpp @@ -867,7 +867,7 @@ void WebServer::handle_climate_request(AsyncWebServerRequest *request, const Url } // Longest: HORIZONTAL -#define PSTR_LOCAL(mode_s) strncpy_P(__buf, (PGM_P)((mode_s)), 15) +#define PSTR_LOCAL(mode_s) strncpy_P(__buf, (PGM_P) ((mode_s)), 15) std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_config) { return json::build_json([obj, start_config](JsonObject root) { diff --git a/esphome/components/whirlpool/whirlpool.cpp b/esphome/components/whirlpool/whirlpool.cpp index f354ab070d..225423b4db 100644 --- a/esphome/components/whirlpool/whirlpool.cpp +++ b/esphome/components/whirlpool/whirlpool.cpp @@ -78,7 +78,7 @@ void WhirlpoolClimate::transmit_state() { // Temperature auto temp = (uint8_t) roundf(clamp(this->target_temperature, this->temperature_min_(), this->temperature_max_())); - remote_state[3] |= (uint8_t)(temp - this->temperature_min_()) << 4; + remote_state[3] |= (uint8_t) (temp - this->temperature_min_()) << 4; // Fan speed switch (this->fan_mode.value()) { diff --git a/esphome/components/xiaomi_ble/xiaomi_ble.cpp b/esphome/components/xiaomi_ble/xiaomi_ble.cpp index 95d97defe2..95faea0446 100644 --- a/esphome/components/xiaomi_ble/xiaomi_ble.cpp +++ b/esphome/components/xiaomi_ble/xiaomi_ble.cpp @@ -239,12 +239,12 @@ bool decrypt_xiaomi_payload(std::vector &raw, const uint8_t *bindkey, c } uint8_t mac_reverse[6] = {0}; - mac_reverse[5] = (uint8_t)(address >> 40); - mac_reverse[4] = (uint8_t)(address >> 32); - mac_reverse[3] = (uint8_t)(address >> 24); - mac_reverse[2] = (uint8_t)(address >> 16); - mac_reverse[1] = (uint8_t)(address >> 8); - mac_reverse[0] = (uint8_t)(address >> 0); + mac_reverse[5] = (uint8_t) (address >> 40); + mac_reverse[4] = (uint8_t) (address >> 32); + mac_reverse[3] = (uint8_t) (address >> 24); + mac_reverse[2] = (uint8_t) (address >> 16); + mac_reverse[1] = (uint8_t) (address >> 8); + mac_reverse[0] = (uint8_t) (address >> 0); XiaomiAESVector vector{.key = {0}, .plaintext = {0}, diff --git a/esphome/components/xpt2046/xpt2046.cpp b/esphome/components/xpt2046/xpt2046.cpp index e3317e0fd5..6c7c55a995 100644 --- a/esphome/components/xpt2046/xpt2046.cpp +++ b/esphome/components/xpt2046/xpt2046.cpp @@ -104,8 +104,8 @@ void XPT2046Component::check_touch_() { break; } - touchpoint.x = (int16_t)((int) touchpoint.x * this->display_->get_width() / 0xfff); - touchpoint.y = (int16_t)((int) touchpoint.y * this->display_->get_height() / 0xfff); + touchpoint.x = (int16_t) ((int) touchpoint.x * this->display_->get_width() / 0xfff); + touchpoint.y = (int16_t) ((int) touchpoint.y * this->display_->get_height() / 0xfff); if (!this->touched || (now - this->last_pos_ms_) >= this->report_millis_) { ESP_LOGV(TAG, "Touching at [%03X, %03X] => [%3d, %3d]", this->x_raw, this->y_raw, touchpoint.x, touchpoint.y); @@ -185,7 +185,7 @@ int16_t XPT2046Component::normalize(int16_t val, int16_t min_val, int16_t max_va } else if (val >= max_val) { ret = 0xfff; } else { - ret = (int16_t)((int) 0xfff * (val - min_val) / (max_val - min_val)); + ret = (int16_t) ((int) 0xfff * (val - min_val) / (max_val - min_val)); } return ret; diff --git a/esphome/core/log.h b/esphome/core/log.h index bef5e5c633..6775aa5ac5 100644 --- a/esphome/core/log.h +++ b/esphome/core/log.h @@ -167,7 +167,7 @@ struct LogString; #include #if USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 5, 0) -#define LOG_STR_ARG(s) ((PGM_P)(s)) +#define LOG_STR_ARG(s) ((PGM_P) (s)) #else // Pre-Arduino 2.5, we can't pass a PSTR() to printf(). Emulate support by copying the message to a // local buffer first. String length is limited to 63 characters. @@ -176,7 +176,7 @@ struct LogString; ({ \ char __buf[64]; \ __buf[63] = '\0'; \ - strncpy_P(__buf, (PGM_P)(s), 63); \ + strncpy_P(__buf, (PGM_P) (s), 63); \ __buf; \ }) #endif diff --git a/script/clang-format b/script/clang-format index ae807262f1..165fbd269f 100755 --- a/script/clang-format +++ b/script/clang-format @@ -17,7 +17,7 @@ def run_format(args, queue, lock, failed_files): """Takes filenames out of queue and runs clang-format on them.""" while True: path = queue.get() - invocation = ["clang-format-11"] + invocation = ["clang-format-13"] if args.inplace: invocation.append("-i") else: @@ -59,14 +59,14 @@ def main(): args = parser.parse_args() try: - get_output("clang-format-11", "-version") + get_output("clang-format-13", "-version") except: print( """ Oops. It looks like clang-format is not installed. - Please check you can run "clang-format-11 -version" in your terminal and install - clang-format (v11) if necessary. + Please check you can run "clang-format-13 -version" in your terminal and install + clang-format (v13) if necessary. Note you can also upload your code as a pull request on GitHub and see the CI check output to apply clang-format.