1
0
mirror of https://github.com/esphome/esphome.git synced 2025-02-14 09:47:07 +01:00

Run clang-tidy against ESP32 (#2147)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Otto winter <otto@otto-winter.com>
This commit is contained in:
Oxan van Leeuwen 2021-09-13 18:11:27 +02:00 committed by GitHub
parent a2d2863c72
commit 40c474cd83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 291 additions and 364 deletions

View File

@ -124,7 +124,7 @@ CheckOptions:
- key: readability-identifier-naming.StaticConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.StaticVariableCase
value: 'UPPER_CASE'
value: 'lower_case'
- key: readability-identifier-naming.GlobalConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.ParameterCase

View File

@ -19,17 +19,20 @@ jobs:
- id: clang-format
name: Run script/clang-format
- id: clang-tidy
name: Run script/clang-tidy 1/4
split: 1
name: Run script/clang-tidy for ESP8266
options: --environment esp8266-tidy --grep ARDUINO_ARCH_ESP8266
- id: clang-tidy
name: Run script/clang-tidy 2/4
split: 2
name: Run script/clang-tidy for ESP32 1/4
options: --environment esp32-tidy --split-num 4 --split-at 1
- id: clang-tidy
name: Run script/clang-tidy 3/4
split: 3
name: Run script/clang-tidy for ESP32 2/4
options: --environment esp32-tidy --split-num 4 --split-at 2
- id: clang-tidy
name: Run script/clang-tidy 4/4
split: 4
name: Run script/clang-tidy for ESP32 3/4
options: --environment esp32-tidy --split-num 4 --split-at 3
- id: clang-tidy
name: Run script/clang-tidy for ESP32 4/4
options: --environment esp32-tidy --split-num 4 --split-at 4
# cpp lint job runs with esphome-lint docker image so that clang-format-*
# doesn't have to be installed
@ -51,7 +54,7 @@ jobs:
if: ${{ matrix.id == 'clang-format' }}
- name: Run clang-tidy
run: script/clang-tidy --all-headers --fix --split-num 4 --split-at ${{ matrix.split }}
run: script/clang-tidy --all-headers --fix ${{ matrix.options }}
if: ${{ matrix.id == 'clang-tidy' }}
- name: Suggested changes

View File

@ -141,7 +141,7 @@ void ICACHE_RAM_ATTR HOT AcDimmerDataStore::s_gpio_intr(AcDimmerDataStore *store
#ifdef ARDUINO_ARCH_ESP32
// ESP32 implementation, uses basically the same code but needs to wrap
// timer_interrupt() function to auto-reschedule
static hw_timer_t *dimmer_timer = nullptr;
static hw_timer_t *dimmer_timer = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
void ICACHE_RAM_ATTR HOT AcDimmerDataStore::s_timer_intr() { timer_interrupt(); }
#endif

View File

@ -6,7 +6,7 @@
namespace esphome {
namespace airthings_ble {
static const char *TAG = "airthings_ble";
static const char *const TAG = "airthings_ble";
bool AirthingsListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
for (auto &it : device.get_manufacturer_datas()) {

View File

@ -5,6 +5,8 @@
namespace esphome {
namespace airthings_wave_plus {
static const char *const TAG = "airthings_wave_plus";
void AirthingsWavePlus::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) {
switch (event) {
@ -21,15 +23,15 @@ void AirthingsWavePlus::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt
}
case ESP_GATTC_SEARCH_CMPL_EVT: {
this->handle = 0;
auto chr = this->parent()->get_characteristic(service_uuid, sensors_data_characteristic_uuid);
this->handle_ = 0;
auto chr = this->parent()->get_characteristic(service_uuid_, sensors_data_characteristic_uuid_);
if (chr == nullptr) {
ESP_LOGW(TAG, "No sensor characteristic found at service %s char %s", service_uuid.to_string().c_str(),
sensors_data_characteristic_uuid.to_string().c_str());
ESP_LOGW(TAG, "No sensor characteristic found at service %s char %s", service_uuid_.to_string().c_str(),
sensors_data_characteristic_uuid_.to_string().c_str());
break;
}
this->handle = chr->handle;
this->node_state = espbt::ClientState::Established;
this->handle_ = chr->handle;
this->node_state = esp32_ble_tracker::ClientState::Established;
request_read_values_();
break;
@ -42,7 +44,7 @@ void AirthingsWavePlus::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt
ESP_LOGW(TAG, "Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
break;
}
if (param->read.handle == this->handle) {
if (param->read.handle == this->handle_) {
read_sensors_(param->read.value, param->read.value_len);
}
break;
@ -88,16 +90,16 @@ void AirthingsWavePlus::read_sensors_(uint8_t *raw_value, uint16_t value_len) {
}
}
bool AirthingsWavePlus::is_valid_radon_value_(short radon) { return 0 <= radon && radon <= 16383; }
bool AirthingsWavePlus::is_valid_radon_value_(uint16_t radon) { return 0 <= radon && radon <= 16383; }
bool AirthingsWavePlus::is_valid_voc_value_(short voc) { return 0 <= voc && voc <= 16383; }
bool AirthingsWavePlus::is_valid_voc_value_(uint16_t voc) { return 0 <= voc && voc <= 16383; }
bool AirthingsWavePlus::is_valid_co2_value_(short co2) { return 0 <= co2 && co2 <= 16383; }
bool AirthingsWavePlus::is_valid_co2_value_(uint16_t co2) { return 0 <= co2 && co2 <= 16383; }
void AirthingsWavePlus::loop() {}
void AirthingsWavePlus::update() {
if (this->node_state != espbt::ClientState::Established) {
if (this->node_state != esp32_ble_tracker::ClientState::Established) {
if (!parent()->enabled) {
ESP_LOGW(TAG, "Reconnecting to device");
parent()->set_enabled(true);
@ -110,7 +112,7 @@ void AirthingsWavePlus::update() {
void AirthingsWavePlus::request_read_values_() {
auto status =
esp_ble_gattc_read_char(this->parent()->gattc_if, this->parent()->conn_id, this->handle, ESP_GATT_AUTH_REQ_NONE);
esp_ble_gattc_read_char(this->parent()->gattc_if, this->parent()->conn_id, this->handle_, ESP_GATT_AUTH_REQ_NONE);
if (status) {
ESP_LOGW(TAG, "Error sending read request for sensor, status=%d", status);
}
@ -130,8 +132,8 @@ AirthingsWavePlus::AirthingsWavePlus() : PollingComponent(10000) {
auto service_bt = *BLEUUID::fromString(std::string("b42e1c08-ade7-11e4-89d3-123b93f75cba")).getNative();
auto characteristic_bt = *BLEUUID::fromString(std::string("b42e2a68-ade7-11e4-89d3-123b93f75cba")).getNative();
service_uuid = espbt::ESPBTUUID::from_uuid(service_bt);
sensors_data_characteristic_uuid = espbt::ESPBTUUID::from_uuid(characteristic_bt);
service_uuid_ = esp32_ble_tracker::ESPBTUUID::from_uuid(service_bt);
sensors_data_characteristic_uuid_ = esp32_ble_tracker::ESPBTUUID::from_uuid(characteristic_bt);
}
void AirthingsWavePlus::setup() {}

View File

@ -1,25 +1,21 @@
#pragma once
#ifdef ARDUINO_ARCH_ESP32
#include <algorithm>
#include <iterator>
#include <esp_gattc_api.h>
#include <BLEDevice.h>
#include "esphome/core/component.h"
#include "esphome/core/log.h"
#include "esphome/components/ble_client/ble_client.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/core/log.h"
#include <algorithm>
#include <iterator>
#ifdef ARDUINO_ARCH_ESP32
#include <esp_gattc_api.h>
#include <BLEDevice.h>
using namespace esphome::ble_client;
namespace esphome {
namespace airthings_wave_plus {
static const char *TAG = "airthings_wave_plus";
class AirthingsWavePlus : public PollingComponent, public BLEClientNode {
class AirthingsWavePlus : public PollingComponent, public ble_client::BLEClientNode {
public:
AirthingsWavePlus();
@ -40,9 +36,9 @@ class AirthingsWavePlus : public PollingComponent, public BLEClientNode {
void set_tvoc(sensor::Sensor *tvoc) { tvoc_sensor_ = tvoc; }
protected:
bool is_valid_radon_value_(short radon);
bool is_valid_voc_value_(short voc);
bool is_valid_co2_value_(short co2);
bool is_valid_radon_value_(uint16_t radon);
bool is_valid_voc_value_(uint16_t voc);
bool is_valid_co2_value_(uint16_t co2);
void read_sensors_(uint8_t *value, uint16_t value_len);
void request_read_values_();
@ -55,9 +51,9 @@ class AirthingsWavePlus : public PollingComponent, public BLEClientNode {
sensor::Sensor *co2_sensor_{nullptr};
sensor::Sensor *tvoc_sensor_{nullptr};
uint16_t handle;
espbt::ESPBTUUID service_uuid;
espbt::ESPBTUUID sensors_data_characteristic_uuid;
uint16_t handle_;
esp32_ble_tracker::ESPBTUUID service_uuid_;
esp32_ble_tracker::ESPBTUUID sensors_data_characteristic_uuid_;
struct WavePlusReadings {
uint8_t version;

View File

@ -6,7 +6,7 @@
namespace esphome {
namespace am43 {
static const char *TAG = "am43";
static const char *const TAG = "am43";
void Am43::dump_config() {
ESP_LOGCONFIG(TAG, "AM43");
@ -15,8 +15,8 @@ void Am43::dump_config() {
}
void Am43::setup() {
this->encoder_ = new Am43Encoder();
this->decoder_ = new Am43Decoder();
this->encoder_ = make_unique<Am43Encoder>();
this->decoder_ = make_unique<Am43Decoder>();
this->logged_in_ = false;
this->last_battery_update_ = 0;
this->current_sensor_ = 0;

View File

@ -28,8 +28,8 @@ class Am43 : public esphome::ble_client::BLEClientNode, public PollingComponent
protected:
uint16_t char_handle_;
Am43Encoder *encoder_;
Am43Decoder *decoder_;
std::unique_ptr<Am43Encoder> encoder_;
std::unique_ptr<Am43Decoder> decoder_;
bool logged_in_;
sensor::Sensor *battery_{nullptr};
sensor::Sensor *illuminance_{nullptr};

View File

@ -6,7 +6,7 @@
namespace esphome {
namespace am43 {
static const char *TAG = "am43_cover";
static const char *const TAG = "am43_cover";
using namespace esphome::cover;
@ -18,8 +18,8 @@ void Am43Component::dump_config() {
void Am43Component::setup() {
this->position = COVER_OPEN;
this->encoder_ = new Am43Encoder();
this->decoder_ = new Am43Decoder();
this->encoder_ = make_unique<Am43Encoder>();
this->decoder_ = make_unique<Am43Decoder>();
this->logged_in_ = false;
}

View File

@ -32,8 +32,8 @@ class Am43Component : public cover::Cover, public esphome::ble_client::BLEClient
uint16_t char_handle_;
uint16_t pin_;
bool invert_position_;
Am43Encoder *encoder_;
Am43Decoder *decoder_;
std::unique_ptr<Am43Encoder> encoder_;
std::unique_ptr<Am43Decoder> decoder_;
bool logged_in_;
float position_;

View File

@ -6,14 +6,14 @@
namespace esphome {
namespace anova {
static const char *TAG = "anova";
static const char *const TAG = "anova";
using namespace esphome::climate;
void Anova::dump_config() { LOG_CLIMATE("", "Anova BLE Cooker", this); }
void Anova::setup() {
this->codec_ = new AnovaCodec();
this->codec_ = make_unique<AnovaCodec>();
this->current_request_ = 0;
}
@ -135,7 +135,7 @@ void Anova::update() {
if (this->current_request_ < 2) {
auto pkt = this->codec_->get_read_device_status_request();
if (this->current_request_ == 0)
auto pkt = this->codec_->get_set_unit_request(this->fahrenheit_ ? 'f' : 'c');
this->codec_->get_set_unit_request(this->fahrenheit_ ? 'f' : 'c');
auto status = esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_,
pkt->length, pkt->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
if (status)

View File

@ -39,7 +39,7 @@ class Anova : public climate::Climate, public esphome::ble_client::BLEClientNode
void set_unit_of_measurement(const char *);
protected:
AnovaCodec *codec_;
std::unique_ptr<AnovaCodec> codec_;
void control(const climate::ClimateCall &call) override;
uint16_t char_handle_;
uint8_t current_request_;

View File

@ -633,7 +633,7 @@ void APIConnection::send_camera_state(std::shared_ptr<esp32_camera::CameraImage>
return;
if (this->image_reader_.available())
return;
this->image_reader_.set_image(image);
this->image_reader_.set_image(std::move(image));
}
bool APIConnection::send_camera_info(esp32_camera::ESP32Camera *camera) {
ListEntitiesCameraResponse msg;

View File

@ -76,11 +76,12 @@ void APIServer::setup() {
#ifdef USE_ESP32_CAMERA
if (esp32_camera::global_esp32_camera != nullptr) {
esp32_camera::global_esp32_camera->add_image_callback([this](std::shared_ptr<esp32_camera::CameraImage> image) {
for (auto &c : this->clients_)
if (!c->remove_)
c->send_camera_state(image);
});
esp32_camera::global_esp32_camera->add_image_callback(
[this](const std::shared_ptr<esp32_camera::CameraImage> &image) {
for (auto &c : this->clients_)
if (!c->remove_)
c->send_camera_state(image);
});
}
#endif
}

View File

@ -26,7 +26,7 @@ bool ATCMiThermometer::parse_device(const esp32_ble_tracker::ESPBTDevice &device
bool success = false;
for (auto &service_data : device.get_service_datas()) {
auto res = parse_header(service_data);
if (res->is_duplicate) {
if (!res.has_value()) {
continue;
}
if (!(parse_message(service_data.data, *res))) {
@ -46,11 +46,7 @@ bool ATCMiThermometer::parse_device(const esp32_ble_tracker::ESPBTDevice &device
success = true;
}
if (!success) {
return false;
}
return true;
return success;
}
optional<ParseResult> ATCMiThermometer::parse_header(const esp32_ble_tracker::ServiceData &service_data) {
@ -64,12 +60,10 @@ optional<ParseResult> ATCMiThermometer::parse_header(const esp32_ble_tracker::Se
static uint8_t last_frame_count = 0;
if (last_frame_count == raw[12]) {
ESP_LOGVV(TAG, "parse_header(): duplicate data packet received (%d).", static_cast<int>(last_frame_count));
result.is_duplicate = true;
ESP_LOGVV(TAG, "parse_header(): duplicate data packet received (%hhu).", last_frame_count);
return {};
}
last_frame_count = raw[12];
result.is_duplicate = false;
return result;
}

View File

@ -14,7 +14,6 @@ struct ParseResult {
optional<float> humidity;
optional<float> battery_level;
optional<float> battery_voltage;
bool is_duplicate;
int raw_offset;
};

View File

@ -130,7 +130,7 @@ void BLEClient::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t es
break;
}
ESP_LOGV(TAG, "cfg_mtu status %d, mtu %d", param->cfg_mtu.status, param->cfg_mtu.mtu);
esp_ble_gattc_search_service(esp_gattc_if, param->cfg_mtu.conn_id, NULL);
esp_ble_gattc_search_service(esp_gattc_if, param->cfg_mtu.conn_id, nullptr);
break;
}
case ESP_GATTC_DISCONNECT_EVT: {
@ -139,13 +139,13 @@ void BLEClient::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t es
}
ESP_LOGV(TAG, "[%s] ESP_GATTC_DISCONNECT_EVT", this->address_str().c_str());
for (auto &svc : this->services_)
delete svc;
delete svc; // NOLINT(cppcoreguidelines-owning-memory)
this->services_.clear();
this->set_states(espbt::ClientState::Idle);
break;
}
case ESP_GATTC_SEARCH_RES_EVT: {
BLEService *ble_service = new BLEService();
BLEService *ble_service = new BLEService(); // NOLINT(cppcoreguidelines-owning-memory)
ble_service->uuid = espbt::ESPBTUUID::from_uuid(param->search_res.srvc_id.uuid);
ble_service->start_handle = param->search_res.start_handle;
ble_service->end_handle = param->search_res.end_handle;
@ -194,7 +194,7 @@ void BLEClient::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t es
// Delete characteristics after clients have used them to save RAM.
if (!all_established && this->all_nodes_established()) {
for (auto &svc : this->services_)
delete svc;
delete svc; // NOLINT(cppcoreguidelines-owning-memory)
this->services_.clear();
}
}
@ -307,7 +307,7 @@ BLEDescriptor *BLEClient::get_descriptor(uint16_t service, uint16_t chr, uint16_
BLEService::~BLEService() {
for (auto &chr : this->characteristics)
delete chr;
delete chr; // NOLINT(cppcoreguidelines-owning-memory)
}
void BLEService::parse_characteristics() {
@ -329,7 +329,7 @@ void BLEService::parse_characteristics() {
break;
}
BLECharacteristic *characteristic = new BLECharacteristic();
BLECharacteristic *characteristic = new BLECharacteristic(); // NOLINT(cppcoreguidelines-owning-memory)
characteristic->uuid = espbt::ESPBTUUID::from_uuid(result.uuid);
characteristic->properties = result.properties;
characteristic->handle = result.char_handle;
@ -344,7 +344,7 @@ void BLEService::parse_characteristics() {
BLECharacteristic::~BLECharacteristic() {
for (auto &desc : this->descriptors)
delete desc;
delete desc; // NOLINT(cppcoreguidelines-owning-memory)
}
void BLECharacteristic::parse_descriptors() {
@ -366,7 +366,7 @@ void BLECharacteristic::parse_descriptors() {
break;
}
BLEDescriptor *desc = new BLEDescriptor();
BLEDescriptor *desc = new BLEDescriptor(); // NOLINT(cppcoreguidelines-owning-memory)
desc->uuid = espbt::ESPBTUUID::from_uuid(result.uuid);
desc->handle = result.handle;
desc->characteristic = this;

View File

@ -27,7 +27,7 @@ void ESP32BLE::setup() {
return;
}
this->advertising_ = new BLEAdvertising();
this->advertising_ = new BLEAdvertising(); // NOLINT(cppcoreguidelines-owning-memory)
this->advertising_->set_scan_response(true);
this->advertising_->set_min_preferred_interval(0x06);
@ -123,25 +123,25 @@ void ESP32BLE::loop() {
BLEEvent *ble_event = this->ble_events_.pop();
while (ble_event != nullptr) {
switch (ble_event->type_) {
case ble_event->GATTS:
case BLEEvent::GATTS:
this->real_gatts_event_handler_(ble_event->event_.gatts.gatts_event, ble_event->event_.gatts.gatts_if,
&ble_event->event_.gatts.gatts_param);
break;
case ble_event->GAP:
case BLEEvent::GAP:
this->real_gap_event_handler_(ble_event->event_.gap.gap_event, &ble_event->event_.gap.gap_param);
break;
default:
break;
}
delete ble_event;
delete ble_event; // NOLINT(cppcoreguidelines-owning-memory)
ble_event = this->ble_events_.pop();
}
}
void ESP32BLE::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
BLEEvent *new_event = new BLEEvent(event, param);
BLEEvent *new_event = new BLEEvent(event, param); // NOLINT(cppcoreguidelines-owning-memory)
global_ble->ble_events_.push(new_event);
}
} // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
void ESP32BLE::real_gap_event_handler_(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
ESP_LOGV(TAG, "(BLE) gap_event_handler - %d", event);
@ -153,9 +153,9 @@ void ESP32BLE::real_gap_event_handler_(esp_gap_ble_cb_event_t event, esp_ble_gap
void ESP32BLE::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t *param) {
BLEEvent *new_event = new BLEEvent(event, gatts_if, param);
BLEEvent *new_event = new BLEEvent(event, gatts_if, param); // NOLINT(cppcoreguidelines-owning-memory)
global_ble->ble_events_.push(new_event);
}
} // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
void ESP32BLE::real_gatts_event_handler_(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t *param) {
@ -174,7 +174,7 @@ float ESP32BLE::get_setup_priority() const { return setup_priority::BLUETOOTH; }
void ESP32BLE::dump_config() { ESP_LOGCONFIG(TAG, "ESP32 BLE:"); }
ESP32BLE *global_ble = nullptr;
ESP32BLE *global_ble = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace esp32_ble
} // namespace esphome

View File

@ -45,6 +45,7 @@ void BLEAdvertising::start() {
this->advertising_data_.service_uuid_len = 0;
} else {
this->advertising_data_.service_uuid_len = 16 * num_services;
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
this->advertising_data_.p_service_uuid = new uint8_t[this->advertising_data_.service_uuid_len];
uint8_t *p = this->advertising_data_.p_service_uuid;
for (int i = 0; i < num_services; i++) {

View File

@ -33,28 +33,28 @@ ESPBTUUID ESPBTUUID::from_raw(const std::string &data) {
ret.uuid_.len = ESP_UUID_LEN_16;
ret.uuid_.uuid.uuid16 = 0;
for (int i = 0; i < data.length();) {
uint8_t MSB = data.c_str()[i];
uint8_t LSB = data.c_str()[i + 1];
uint8_t msb = data.c_str()[i];
uint8_t lsb = data.c_str()[i + 1];
if (MSB > '9')
MSB -= 7;
if (LSB > '9')
LSB -= 7;
ret.uuid_.uuid.uuid16 += (((MSB & 0x0F) << 4) | (LSB & 0x0F)) << (2 - i) * 4;
if (msb > '9')
msb -= 7;
if (lsb > '9')
lsb -= 7;
ret.uuid_.uuid.uuid16 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (2 - i) * 4;
i += 2;
}
} else if (data.length() == 8) {
ret.uuid_.len = ESP_UUID_LEN_32;
ret.uuid_.uuid.uuid32 = 0;
for (int i = 0; i < data.length();) {
uint8_t MSB = data.c_str()[i];
uint8_t LSB = data.c_str()[i + 1];
uint8_t msb = data.c_str()[i];
uint8_t lsb = data.c_str()[i + 1];
if (MSB > '9')
MSB -= 7;
if (LSB > '9')
LSB -= 7;
ret.uuid_.uuid.uuid32 += (((MSB & 0x0F) << 4) | (LSB & 0x0F)) << (6 - i) * 4;
if (msb > '9')
msb -= 7;
if (lsb > '9')
lsb -= 7;
ret.uuid_.uuid.uuid32 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (6 - i) * 4;
i += 2;
}
} else if (data.length() == 16) { // how we can have 16 byte length string reprezenting 128 bit uuid??? needs to be
@ -69,14 +69,14 @@ ESPBTUUID ESPBTUUID::from_raw(const std::string &data) {
for (int i = 0; i < data.length();) {
if (data.c_str()[i] == '-')
i++;
uint8_t MSB = data.c_str()[i];
uint8_t LSB = data.c_str()[i + 1];
uint8_t msb = data.c_str()[i];
uint8_t lsb = data.c_str()[i + 1];
if (MSB > '9')
MSB -= 7;
if (LSB > '9')
LSB -= 7;
ret.uuid_.uuid.uuid128[15 - n++] = ((MSB & 0x0F) << 4) | (LSB & 0x0F);
if (msb > '9')
msb -= 7;
if (lsb > '9')
lsb -= 7;
ret.uuid_.uuid.uuid128[15 - n++] = ((msb & 0x0F) << 4) | (lsb & 0x0F);
i += 2;
}
} else {

View File

@ -15,6 +15,7 @@ namespace esp32_ble_beacon {
static const char *const TAG = "esp32_ble_beacon";
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static esp_ble_adv_params_t ble_adv_params = {
.adv_int_min = 0x20,
.adv_int_max = 0x40,
@ -28,7 +29,7 @@ static esp_ble_adv_params_t ble_adv_params = {
#define ENDIAN_CHANGE_U16(x) ((((x) &0xFF00) >> 8) + (((x) &0xFF) << 8))
static esp_ble_ibeacon_head_t ibeacon_common_head = {
static const esp_ble_ibeacon_head_t IBEACON_COMMON_HEAD = {
.flags = {0x02, 0x01, 0x06}, .length = 0x1A, .type = 0xFF, .company_id = 0x004C, .beacon_type = 0x1502};
void ESP32BLEBeacon::dump_config() {
@ -90,7 +91,7 @@ void ESP32BLEBeacon::ble_setup() {
}
esp_ble_ibeacon_t ibeacon_adv_data;
memcpy(&ibeacon_adv_data.ibeacon_head, &ibeacon_common_head, sizeof(esp_ble_ibeacon_head_t));
memcpy(&ibeacon_adv_data.ibeacon_head, &IBEACON_COMMON_HEAD, sizeof(esp_ble_ibeacon_head_t));
memcpy(&ibeacon_adv_data.ibeacon_vendor.proximity_uuid, global_esp32_ble_beacon->uuid_.data(),
sizeof(ibeacon_adv_data.ibeacon_vendor.proximity_uuid));
ibeacon_adv_data.ibeacon_vendor.minor = ENDIAN_CHANGE_U16(global_esp32_ble_beacon->minor_);
@ -131,7 +132,7 @@ void ESP32BLEBeacon::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap
}
}
ESP32BLEBeacon *global_esp32_ble_beacon = nullptr;
ESP32BLEBeacon *global_esp32_ble_beacon = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace esp32_ble_beacon
} // namespace esphome

View File

@ -27,7 +27,7 @@ BLECharacteristic::BLECharacteristic(const ESPBTUUID uuid, uint32_t properties)
void BLECharacteristic::set_value(std::vector<uint8_t> value) {
xSemaphoreTake(this->set_value_lock_, 0L);
this->value_ = value;
this->value_ = std::move(value);
xSemaphoreGive(this->set_value_lock_);
}
void BLECharacteristic::set_value(const std::string &value) {

View File

@ -15,10 +15,10 @@ BLEDescriptor::BLEDescriptor(ESPBTUUID uuid, uint16_t max_len) {
this->uuid_ = uuid;
this->value_.attr_len = 0;
this->value_.attr_max_len = max_len;
this->value_.attr_value = (uint8_t *) malloc(max_len);
this->value_.attr_value = (uint8_t *) malloc(max_len); // NOLINT
}
BLEDescriptor::~BLEDescriptor() { free(this->value_.attr_value); }
BLEDescriptor::~BLEDescriptor() { free(this->value_.attr_value); } // NOLINT
void BLEDescriptor::do_create(BLECharacteristic *characteristic) {
this->characteristic_ = characteristic;

View File

@ -109,7 +109,7 @@ BLEService *BLEServer::create_service(const std::string &uuid, bool advertise) {
}
BLEService *BLEServer::create_service(ESPBTUUID uuid, bool advertise, uint16_t num_handles, uint8_t inst_id) {
ESP_LOGV(TAG, "Creating service - %s", uuid.to_string().c_str());
BLEService *service = new BLEService(uuid, num_handles, inst_id);
BLEService *service = new BLEService(uuid, num_handles, inst_id); // NOLINT(cppcoreguidelines-owning-memory)
this->services_.push_back(service);
if (advertise) {
esp32_ble::global_ble->get_advertising()->add_service_uuid(uuid);
@ -158,7 +158,7 @@ float BLEServer::get_setup_priority() const { return setup_priority::BLUETOOTH -
void BLEServer::dump_config() { ESP_LOGCONFIG(TAG, "ESP32 BLE Server:"); }
BLEServer *global_ble_server = nullptr;
BLEServer *global_ble_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace esp32_ble_server
} // namespace esphome

View File

@ -14,7 +14,7 @@ BLEService::BLEService(ESPBTUUID uuid, uint16_t num_handles, uint8_t inst_id)
BLEService::~BLEService() {
for (auto &chr : this->characteristics_)
delete chr;
delete chr; // NOLINT(cppcoreguidelines-owning-memory)
}
BLECharacteristic *BLEService::get_characteristic(ESPBTUUID uuid) {
@ -34,6 +34,7 @@ BLECharacteristic *BLEService::create_characteristic(const std::string &uuid, es
return create_characteristic(ESPBTUUID::from_raw(uuid), properties);
}
BLECharacteristic *BLEService::create_characteristic(ESPBTUUID uuid, esp_gatt_char_prop_t properties) {
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
BLECharacteristic *characteristic = new BLECharacteristic(uuid, properties);
this->characteristics_.push_back(characteristic);
return characteristic;

View File

@ -21,7 +21,7 @@ namespace esp32_ble_tracker {
static const char *const TAG = "esp32_ble_tracker";
ESP32BLETracker *global_esp32_ble_tracker = nullptr;
ESP32BLETracker *global_esp32_ble_tracker = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
uint64_t ble_addr_to_uint64(const esp_bd_addr_t address) {
uint64_t u = 0;
@ -55,7 +55,7 @@ void ESP32BLETracker::loop() {
&ble_event->event_.gattc.gattc_param);
else
this->real_gap_event_handler(ble_event->event_.gap.gap_event, &ble_event->event_.gap.gap_param);
delete ble_event;
delete ble_event; // NOLINT(cppcoreguidelines-owning-memory)
ble_event = this->ble_events_.pop();
}
@ -204,9 +204,9 @@ void ESP32BLETracker::register_client(ESPBTClient *client) {
}
void ESP32BLETracker::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
BLEEvent *gap_event = new BLEEvent(event, param);
BLEEvent *gap_event = new BLEEvent(event, param); // NOLINT(cppcoreguidelines-owning-memory)
global_esp32_ble_tracker->ble_events_.push(gap_event);
}
} // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
void ESP32BLETracker::real_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
switch (event) {
@ -254,9 +254,9 @@ void ESP32BLETracker::gap_scan_result(const esp_ble_gap_cb_param_t::ble_scan_res
void ESP32BLETracker::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) {
BLEEvent *gattc_event = new BLEEvent(event, gattc_if, param);
BLEEvent *gattc_event = new BLEEvent(event, gattc_if, param); // NOLINT(cppcoreguidelines-owning-memory)
global_esp32_ble_tracker->ble_events_.push(gattc_event);
}
} // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
void ESP32BLETracker::real_gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) {

View File

@ -275,10 +275,10 @@ void ESP32Camera::set_idle_update_interval(uint32_t idle_update_interval) {
}
void ESP32Camera::set_test_pattern(bool test_pattern) { this->test_pattern_ = test_pattern; }
ESP32Camera *global_esp32_camera;
ESP32Camera *global_esp32_camera; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
void CameraImageReader::set_image(std::shared_ptr<CameraImage> image) {
this->image_ = image;
this->image_ = std::move(image);
this->offset_ = 0;
}
size_t CameraImageReader::available() const {

View File

@ -32,7 +32,7 @@ void ESP32ImprovComponent::setup_characteristics() {
this->rpc_ = this->service_->create_characteristic(improv::RPC_COMMAND_UUID, BLECharacteristic::PROPERTY_WRITE);
this->rpc_->on_write([this](const std::vector<uint8_t> &data) {
if (data.size() > 0) {
if (!data.empty()) {
this->incoming_data_.insert(this->incoming_data_.end(), data.begin(), data.end());
}
});
@ -56,7 +56,7 @@ void ESP32ImprovComponent::setup_characteristics() {
}
void ESP32ImprovComponent::loop() {
if (this->incoming_data_.size() > 0)
if (!this->incoming_data_.empty())
this->process_incoming_data_();
uint32_t now = millis();
@ -162,7 +162,7 @@ bool ESP32ImprovComponent::check_identify_() {
void ESP32ImprovComponent::set_state_(improv::State state) {
ESP_LOGV(TAG, "Setting state: %d", state);
this->state_ = state;
if (this->status_->get_value().size() == 0 || this->status_->get_value()[0] != state) {
if (this->status_->get_value().empty() || this->status_->get_value()[0] != state) {
uint8_t data[1]{state};
this->status_->set_value(data, 1);
if (state != improv::STATE_STOPPED)
@ -173,7 +173,7 @@ void ESP32ImprovComponent::set_state_(improv::State state) {
void ESP32ImprovComponent::set_error_(improv::Error error) {
if (error != improv::ERROR_NONE)
ESP_LOGE(TAG, "Error: %d", error);
if (this->error_->get_value().size() == 0 || this->error_->get_value()[0] != error) {
if (this->error_->get_value().empty() || this->error_->get_value()[0] != error) {
uint8_t data[1]{error};
this->error_->set_value(data, 1);
if (this->state_ != improv::STATE_STOPPED)
@ -274,7 +274,7 @@ void ESP32ImprovComponent::on_wifi_connect_timeout_() {
void ESP32ImprovComponent::on_client_disconnect() { this->set_error_(improv::ERROR_NONE); };
ESP32ImprovComponent *global_improv_component = nullptr;
ESP32ImprovComponent *global_improv_component = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace esp32_improv
} // namespace esphome

View File

@ -1,3 +1,5 @@
#ifdef ARDUINO_ARCH_ESP8266
#include "esp8266_pwm.h"
#include "esphome/core/macros.h"
#include "esphome/core/log.h"
@ -55,3 +57,5 @@ void HOT ESP8266PWM::write_state(float state) {
} // namespace esp8266_pwm
} // namespace esphome
#endif

View File

@ -1,5 +1,7 @@
#pragma once
#ifdef ARDUINO_ARCH_ESP8266
#include "esphome/core/component.h"
#include "esphome/core/esphal.h"
#include "esphome/core/automation.h"
@ -48,3 +50,5 @@ template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
} // namespace esp8266_pwm
} // namespace esphome
#endif

View File

@ -16,17 +16,17 @@
// Defined in WiFiGeneric.cpp, sets global initialized flag, starts network event task queue and calls
// tcpip_adapter_init()
extern void tcpipInit();
extern void tcpipInit(); // NOLINT(readability-identifier-naming)
namespace esphome {
namespace ethernet {
static const char *const TAG = "ethernet";
EthernetComponent *global_eth_component;
EthernetComponent *global_eth_component; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
#define ESPHL_ERROR_CHECK(err, message) \
if (err != ESP_OK) { \
if ((err) != ESP_OK) { \
ESP_LOGE(TAG, message ": (%d) %s", err, esp_err_to_name(err)); \
this->mark_failed(); \
return; \
@ -258,7 +258,7 @@ void EthernetComponent::set_mdc_pin(uint8_t mdc_pin) { this->mdc_pin_ = mdc_pin;
void EthernetComponent::set_mdio_pin(uint8_t mdio_pin) { this->mdio_pin_ = mdio_pin; }
void EthernetComponent::set_type(EthernetType type) { this->type_ = type; }
void EthernetComponent::set_clk_mode(eth_clock_mode_t clk_mode) { this->clk_mode_ = clk_mode; }
void EthernetComponent::set_manual_ip(ManualIP manual_ip) { this->manual_ip_ = manual_ip; }
void EthernetComponent::set_manual_ip(const ManualIP &manual_ip) { this->manual_ip_ = manual_ip; }
std::string EthernetComponent::get_use_address() const {
if (this->use_address_.empty()) {
return App.get_name() + ".local";

View File

@ -48,7 +48,7 @@ class EthernetComponent : public Component {
void set_mdio_pin(uint8_t mdio_pin);
void set_type(EthernetType type);
void set_clk_mode(eth_clock_mode_t clk_mode);
void set_manual_ip(ManualIP manual_ip);
void set_manual_ip(const ManualIP &manual_ip);
IPAddress get_ip_address();
std::string get_use_address() const;

View File

@ -10,11 +10,12 @@ static const char *const TAG = "i2c";
I2CComponent::I2CComponent() {
#ifdef ARDUINO_ARCH_ESP32
if (next_i2c_bus_num_ == 0)
static uint8_t next_i2c_bus_num = 0;
if (next_i2c_bus_num == 0)
this->wire_ = &Wire;
else
this->wire_ = new TwoWire(next_i2c_bus_num_);
next_i2c_bus_num_++;
this->wire_ = new TwoWire(next_i2c_bus_num); // NOLINT(cppcoreguidelines-owning-memory)
next_i2c_bus_num++;
#else
this->wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer)
#endif
@ -273,10 +274,6 @@ bool I2CDevice::write_byte_16(uint8_t a_register, uint16_t data) { // NOLINT
}
void I2CDevice::set_i2c_parent(I2CComponent *parent) { this->parent_ = parent; }
#ifdef ARDUINO_ARCH_ESP32
uint8_t next_i2c_bus_num_ = 0;
#endif
I2CRegister &I2CRegister::operator=(uint8_t value) {
this->parent_->write_byte(this->register_, value);
return *this;

View File

@ -131,10 +131,6 @@ class I2CComponent : public Component {
bool scan_;
};
#ifdef ARDUINO_ARCH_ESP32
extern uint8_t next_i2c_bus_num_;
#endif
class I2CDevice;
class I2CMultiplexer;
class I2CRegister {

View File

@ -37,25 +37,25 @@ bool InkbirdIBSTH1_MINI::parse_device(const esp32_ble_tracker::ESPBTDevice &devi
ESP_LOGVV(TAG, "parse_device(): address is not public");
return false;
}
if (device.get_service_datas().size() != 0) {
if (!device.get_service_datas().empty()) {
ESP_LOGVV(TAG, "parse_device(): service_data is expected to be empty");
return false;
}
auto mnfDatas = device.get_manufacturer_datas();
if (mnfDatas.size() != 1) {
auto mnf_datas = device.get_manufacturer_datas();
if (mnf_datas.size() != 1) {
ESP_LOGVV(TAG, "parse_device(): manufacturer_datas is expected to have a single element");
return false;
}
auto mnfData = mnfDatas[0];
if (mnfData.uuid.get_uuid().len != ESP_UUID_LEN_16) {
auto mnf_data = mnf_datas[0];
if (mnf_data.uuid.get_uuid().len != ESP_UUID_LEN_16) {
ESP_LOGVV(TAG, "parse_device(): manufacturer data element is expected to have uuid of length 16");
return false;
}
if (mnfData.data.size() != 7) {
if (mnf_data.data.size() != 7) {
ESP_LOGVV(TAG, "parse_device(): manufacturer data element length is expected to be of length 7");
return false;
}
if (mnfData.data[6] != 8) {
if (mnf_data.data[6] != 8) {
ESP_LOGVV(TAG, "parse_device(): unexpected data");
return false;
}
@ -72,20 +72,20 @@ bool InkbirdIBSTH1_MINI::parse_device(const esp32_ble_tracker::ESPBTDevice &devi
auto external_temperature = NAN;
// Read bluetooth data into variable
auto measured_temperature = mnfData.uuid.get_uuid().uuid.uuid16 / 100.0f;
auto measured_temperature = mnf_data.uuid.get_uuid().uuid.uuid16 / 100.0f;
// Set temperature or external_temperature based on which sensor is in use
if (mnfData.data[2] == 0) {
if (mnf_data.data[2] == 0) {
temperature = measured_temperature;
} else if (mnfData.data[2] == 1) {
} else if (mnf_data.data[2] == 1) {
external_temperature = measured_temperature;
} else {
ESP_LOGVV(TAG, "parse_device(): unknown sensor type");
return false;
}
auto battery_level = mnfData.data[5];
auto humidity = ((mnfData.data[1] << 8) + mnfData.data[0]) / 100.0f;
auto battery_level = mnf_data.data[5];
auto humidity = ((mnf_data.data[1] << 8) + mnf_data.data[0]) / 100.0f;
// Send temperature only if the value is set
if (!isnan(temperature) && this->temperature_ != nullptr) {

View File

@ -150,7 +150,6 @@ void Inkplate6::dump_config() {
}
void Inkplate6::eink_off_() {
ESP_LOGV(TAG, "Eink off called");
unsigned long start_time = millis();
if (panel_on_ == 0)
return;
panel_on_ = 0;
@ -170,7 +169,6 @@ void Inkplate6::eink_off_() {
}
void Inkplate6::eink_on_() {
ESP_LOGV(TAG, "Eink on called");
unsigned long start_time = millis();
if (panel_on_ == 1)
return;
panel_on_ = 1;
@ -200,7 +198,7 @@ void Inkplate6::eink_on_() {
}
void Inkplate6::fill(Color color) {
ESP_LOGV(TAG, "Fill called");
unsigned long start_time = millis();
uint32_t start_time = millis();
if (this->greyscale_) {
uint8_t fill = ((color.red * 2126 / 10000) + (color.green * 7152 / 10000) + (color.blue * 722 / 10000)) >> 5;
@ -214,7 +212,7 @@ void Inkplate6::fill(Color color) {
}
void Inkplate6::display() {
ESP_LOGV(TAG, "Display called");
unsigned long start_time = millis();
uint32_t start_time = millis();
if (this->greyscale_) {
this->display3b_();
@ -229,7 +227,7 @@ void Inkplate6::display() {
}
void Inkplate6::display1b_() {
ESP_LOGV(TAG, "Display1b called");
unsigned long start_time = millis();
uint32_t start_time = millis();
memcpy(this->buffer_, this->partial_buffer_, this->get_buffer_length_());
@ -348,7 +346,7 @@ void Inkplate6::display1b_() {
}
void Inkplate6::display3b_() {
ESP_LOGV(TAG, "Display3b called");
unsigned long start_time = millis();
uint32_t start_time = millis();
eink_on_();
clean_fast_(0, 1);
@ -424,7 +422,7 @@ void Inkplate6::display3b_() {
}
bool Inkplate6::partial_update_() {
ESP_LOGV(TAG, "Partial update called");
unsigned long start_time = millis();
uint32_t start_time = millis();
if (this->greyscale_)
return false;
if (this->block_partial_)
@ -531,7 +529,7 @@ void Inkplate6::vscan_end_() {
}
void Inkplate6::clean() {
ESP_LOGV(TAG, "Clean called");
unsigned long start_time = millis();
uint32_t start_time = millis();
eink_on_();
clean_fast_(0, 1); // White
@ -544,7 +542,7 @@ void Inkplate6::clean() {
}
void Inkplate6::clean_fast_(uint8_t c, uint8_t rep) {
ESP_LOGV(TAG, "Clean fast called with: (%d, %d)", c, rep);
unsigned long start_time =