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 - key: readability-identifier-naming.StaticConstantCase
value: 'UPPER_CASE' value: 'UPPER_CASE'
- key: readability-identifier-naming.StaticVariableCase - key: readability-identifier-naming.StaticVariableCase
value: 'UPPER_CASE' value: 'lower_case'
- key: readability-identifier-naming.GlobalConstantCase - key: readability-identifier-naming.GlobalConstantCase
value: 'UPPER_CASE' value: 'UPPER_CASE'
- key: readability-identifier-naming.ParameterCase - key: readability-identifier-naming.ParameterCase

View file

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

View file

@ -141,7 +141,7 @@ void ICACHE_RAM_ATTR HOT AcDimmerDataStore::s_gpio_intr(AcDimmerDataStore *store
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
// ESP32 implementation, uses basically the same code but needs to wrap // ESP32 implementation, uses basically the same code but needs to wrap
// timer_interrupt() function to auto-reschedule // 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(); } void ICACHE_RAM_ATTR HOT AcDimmerDataStore::s_timer_intr() { timer_interrupt(); }
#endif #endif

View file

@ -6,7 +6,7 @@
namespace esphome { namespace esphome {
namespace airthings_ble { 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) { bool AirthingsListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
for (auto &it : device.get_manufacturer_datas()) { for (auto &it : device.get_manufacturer_datas()) {

View file

@ -5,6 +5,8 @@
namespace esphome { namespace esphome {
namespace airthings_wave_plus { 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, void AirthingsWavePlus::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) { esp_ble_gattc_cb_param_t *param) {
switch (event) { 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: { case ESP_GATTC_SEARCH_CMPL_EVT: {
this->handle = 0; this->handle_ = 0;
auto chr = this->parent()->get_characteristic(service_uuid, sensors_data_characteristic_uuid); auto chr = this->parent()->get_characteristic(service_uuid_, sensors_data_characteristic_uuid_);
if (chr == nullptr) { if (chr == nullptr) {
ESP_LOGW(TAG, "No sensor characteristic found at service %s char %s", service_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()); sensors_data_characteristic_uuid_.to_string().c_str());
break; break;
} }
this->handle = chr->handle; this->handle_ = chr->handle;
this->node_state = espbt::ClientState::Established; this->node_state = esp32_ble_tracker::ClientState::Established;
request_read_values_(); request_read_values_();
break; 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); ESP_LOGW(TAG, "Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
break; break;
} }
if (param->read.handle == this->handle) { if (param->read.handle == this->handle_) {
read_sensors_(param->read.value, param->read.value_len); read_sensors_(param->read.value, param->read.value_len);
} }
break; 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::loop() {}
void AirthingsWavePlus::update() { void AirthingsWavePlus::update() {
if (this->node_state != espbt::ClientState::Established) { if (this->node_state != esp32_ble_tracker::ClientState::Established) {
if (!parent()->enabled) { if (!parent()->enabled) {
ESP_LOGW(TAG, "Reconnecting to device"); ESP_LOGW(TAG, "Reconnecting to device");
parent()->set_enabled(true); parent()->set_enabled(true);
@ -110,7 +112,7 @@ void AirthingsWavePlus::update() {
void AirthingsWavePlus::request_read_values_() { void AirthingsWavePlus::request_read_values_() {
auto status = 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) { if (status) {
ESP_LOGW(TAG, "Error sending read request for sensor, status=%d", 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 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(); auto characteristic_bt = *BLEUUID::fromString(std::string("b42e2a68-ade7-11e4-89d3-123b93f75cba")).getNative();
service_uuid = espbt::ESPBTUUID::from_uuid(service_bt); service_uuid_ = esp32_ble_tracker::ESPBTUUID::from_uuid(service_bt);
sensors_data_characteristic_uuid = espbt::ESPBTUUID::from_uuid(characteristic_bt); sensors_data_characteristic_uuid_ = esp32_ble_tracker::ESPBTUUID::from_uuid(characteristic_bt);
} }
void AirthingsWavePlus::setup() {} void AirthingsWavePlus::setup() {}

View file

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

View file

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

View file

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

View file

@ -6,7 +6,7 @@
namespace esphome { namespace esphome {
namespace am43 { namespace am43 {
static const char *TAG = "am43_cover"; static const char *const TAG = "am43_cover";
using namespace esphome::cover; using namespace esphome::cover;
@ -18,8 +18,8 @@ void Am43Component::dump_config() {
void Am43Component::setup() { void Am43Component::setup() {
this->position = COVER_OPEN; this->position = COVER_OPEN;
this->encoder_ = new Am43Encoder(); this->encoder_ = make_unique<Am43Encoder>();
this->decoder_ = new Am43Decoder(); this->decoder_ = make_unique<Am43Decoder>();
this->logged_in_ = false; 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 char_handle_;
uint16_t pin_; uint16_t pin_;
bool invert_position_; bool invert_position_;
Am43Encoder *encoder_; std::unique_ptr<Am43Encoder> encoder_;
Am43Decoder *decoder_; std::unique_ptr<Am43Decoder> decoder_;
bool logged_in_; bool logged_in_;
float position_; float position_;

View file

@ -6,14 +6,14 @@
namespace esphome { namespace esphome {
namespace anova { namespace anova {
static const char *TAG = "anova"; static const char *const TAG = "anova";
using namespace esphome::climate; using namespace esphome::climate;
void Anova::dump_config() { LOG_CLIMATE("", "Anova BLE Cooker", this); } void Anova::dump_config() { LOG_CLIMATE("", "Anova BLE Cooker", this); }
void Anova::setup() { void Anova::setup() {
this->codec_ = new AnovaCodec(); this->codec_ = make_unique<AnovaCodec>();
this->current_request_ = 0; this->current_request_ = 0;
} }
@ -135,7 +135,7 @@ void Anova::update() {
if (this->current_request_ < 2) { if (this->current_request_ < 2) {
auto pkt = this->codec_->get_read_device_status_request(); auto pkt = this->codec_->get_read_device_status_request();
if (this->current_request_ == 0) 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_, 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); pkt->length, pkt->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
if (status) 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 *); void set_unit_of_measurement(const char *);
protected: protected:
AnovaCodec *codec_; std::unique_ptr<AnovaCodec> codec_;
void control(const climate::ClimateCall &call) override; void control(const climate::ClimateCall &call) override;
uint16_t char_handle_; uint16_t char_handle_;
uint8_t current_request_; uint8_t current_request_;

View file

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

View file

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

View file

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

View file

@ -14,7 +14,6 @@ struct ParseResult {
optional<float> humidity; optional<float> humidity;
optional<float> battery_level; optional<float> battery_level;
optional<float> battery_voltage; optional<float> battery_voltage;
bool is_duplicate;
int raw_offset; 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; break;
} }
ESP_LOGV(TAG, "cfg_mtu status %d, mtu %d", param->cfg_mtu.status, param->cfg_mtu.mtu); 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; break;
} }
case ESP_GATTC_DISCONNECT_EVT: { 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()); ESP_LOGV(TAG, "[%s] ESP_GATTC_DISCONNECT_EVT", this->address_str().c_str());
for (auto &svc : this->services_) for (auto &svc : this->services_)
delete svc; delete svc; // NOLINT(cppcoreguidelines-owning-memory)
this->services_.clear(); this->services_.clear();
this->set_states(espbt::ClientState::Idle); this->set_states(espbt::ClientState::Idle);
break; break;
} }
case ESP_GATTC_SEARCH_RES_EVT: { 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->uuid = espbt::ESPBTUUID::from_uuid(param->search_res.srvc_id.uuid);
ble_service->start_handle = param->search_res.start_handle; ble_service->start_handle = param->search_res.start_handle;
ble_service->end_handle = param->search_res.end_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. // Delete characteristics after clients have used them to save RAM.
if (!all_established && this->all_nodes_established()) { if (!all_established && this->all_nodes_established()) {
for (auto &svc : this->services_) for (auto &svc : this->services_)
delete svc; delete svc; // NOLINT(cppcoreguidelines-owning-memory)
this->services_.clear(); this->services_.clear();
} }
} }
@ -307,7 +307,7 @@ BLEDescriptor *BLEClient::get_descriptor(uint16_t service, uint16_t chr, uint16_
BLEService::~BLEService() { BLEService::~BLEService() {
for (auto &chr : this->characteristics) for (auto &chr : this->characteristics)
delete chr; delete chr; // NOLINT(cppcoreguidelines-owning-memory)
} }
void BLEService::parse_characteristics() { void BLEService::parse_characteristics() {
@ -329,7 +329,7 @@ void BLEService::parse_characteristics() {
break; break;
} }
BLECharacteristic *characteristic = new BLECharacteristic(); BLECharacteristic *characteristic = new BLECharacteristic(); // NOLINT(cppcoreguidelines-owning-memory)
characteristic->uuid = espbt::ESPBTUUID::from_uuid(result.uuid); characteristic->uuid = espbt::ESPBTUUID::from_uuid(result.uuid);
characteristic->properties = result.properties; characteristic->properties = result.properties;
characteristic->handle = result.char_handle; characteristic->handle = result.char_handle;
@ -344,7 +344,7 @@ void BLEService::parse_characteristics() {
BLECharacteristic::~BLECharacteristic() { BLECharacteristic::~BLECharacteristic() {
for (auto &desc : this->descriptors) for (auto &desc : this->descriptors)
delete desc; delete desc; // NOLINT(cppcoreguidelines-owning-memory)
} }
void BLECharacteristic::parse_descriptors() { void BLECharacteristic::parse_descriptors() {
@ -366,7 +366,7 @@ void BLECharacteristic::parse_descriptors() {
break; break;
} }
BLEDescriptor *desc = new BLEDescriptor(); BLEDescriptor *desc = new BLEDescriptor(); // NOLINT(cppcoreguidelines-owning-memory)
desc->uuid = espbt::ESPBTUUID::from_uuid(result.uuid); desc->uuid = espbt::ESPBTUUID::from_uuid(result.uuid);
desc->handle = result.handle; desc->handle = result.handle;
desc->characteristic = this; desc->characteristic = this;

View file

@ -27,7 +27,7 @@ void ESP32BLE::setup() {
return; return;
} }
this->advertising_ = new BLEAdvertising(); this->advertising_ = new BLEAdvertising(); // NOLINT(cppcoreguidelines-owning-memory)
this->advertising_->set_scan_response(true); this->advertising_->set_scan_response(true);
this->advertising_->set_min_preferred_interval(0x06); this->advertising_->set_min_preferred_interval(0x06);
@ -123,25 +123,25 @@ void ESP32BLE::loop() {
BLEEvent *ble_event = this->ble_events_.pop(); BLEEvent *ble_event = this->ble_events_.pop();
while (ble_event != nullptr) { while (ble_event != nullptr) {
switch (ble_event->type_) { 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, this->real_gatts_event_handler_(ble_event->event_.gatts.gatts_event, ble_event->event_.gatts.gatts_if,
&ble_event->event_.gatts.gatts_param); &ble_event->event_.gatts.gatts_param);
break; 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); this->real_gap_event_handler_(ble_event->event_.gap.gap_event, &ble_event->event_.gap.gap_param);
break; break;
default: default:
break; break;
} }
delete ble_event; delete ble_event; // NOLINT(cppcoreguidelines-owning-memory)
ble_event = this->ble_events_.pop(); 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) { 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); 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) { 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); 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, void ESP32BLE::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t *param) { 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); 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, 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) { 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:"); } 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 esp32_ble
} // namespace esphome } // namespace esphome

View file

@ -45,6 +45,7 @@ void BLEAdvertising::start() {
this->advertising_data_.service_uuid_len = 0; this->advertising_data_.service_uuid_len = 0;
} else { } else {
this->advertising_data_.service_uuid_len = 16 * num_services; 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]; this->advertising_data_.p_service_uuid = new uint8_t[this->advertising_data_.service_uuid_len];
uint8_t *p = this->advertising_data_.p_service_uuid; uint8_t *p = this->advertising_data_.p_service_uuid;
for (int i = 0; i < num_services; i++) { 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_.len = ESP_UUID_LEN_16;
ret.uuid_.uuid.uuid16 = 0; ret.uuid_.uuid.uuid16 = 0;
for (int i = 0; i < data.length();) { for (int i = 0; i < data.length();) {
uint8_t MSB = data.c_str()[i]; uint8_t msb = data.c_str()[i];
uint8_t LSB = data.c_str()[i + 1]; uint8_t lsb = data.c_str()[i + 1];
if (MSB > '9') if (msb > '9')
MSB -= 7; msb -= 7;
if (LSB > '9') if (lsb > '9')
LSB -= 7; lsb -= 7;
ret.uuid_.uuid.uuid16 += (((MSB & 0x0F) << 4) | (LSB & 0x0F)) << (2 - i) * 4; ret.uuid_.uuid.uuid16 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (2 - i) * 4;
i += 2; i += 2;
} }
} else if (data.length() == 8) { } else if (data.length() == 8) {
ret.uuid_.len = ESP_UUID_LEN_32; ret.uuid_.len = ESP_UUID_LEN_32;
ret.uuid_.uuid.uuid32 = 0; ret.uuid_.uuid.uuid32 = 0;
for (int i = 0; i < data.length();) { for (int i = 0; i < data.length();) {
uint8_t MSB = data.c_str()[i]; uint8_t msb = data.c_str()[i];
uint8_t LSB = data.c_str()[i + 1]; uint8_t lsb = data.c_str()[i + 1];
if (MSB > '9') if (msb > '9')
MSB -= 7; msb -= 7;
if (LSB > '9') if (lsb > '9')
LSB -= 7; lsb -= 7;
ret.uuid_.uuid.uuid32 += (((MSB & 0x0F) << 4) | (LSB & 0x0F)) << (6 - i) * 4; ret.uuid_.uuid.uuid32 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (6 - i) * 4;
i += 2; i += 2;
} }
} else if (data.length() == 16) { // how we can have 16 byte length string reprezenting 128 bit uuid??? needs to be } 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();) { for (int i = 0; i < data.length();) {
if (data.c_str()[i] == '-') if (data.c_str()[i] == '-')
i++; i++;
uint8_t MSB = data.c_str()[i]; uint8_t msb = data.c_str()[i];
uint8_t LSB = data.c_str()[i + 1]; uint8_t lsb = data.c_str()[i + 1];
if (MSB > '9') if (msb > '9')
MSB -= 7; msb -= 7;
if (LSB > '9') if (lsb > '9')
LSB -= 7; lsb -= 7;
ret.uuid_.uuid.uuid128[15 - n++] = ((MSB & 0x0F) << 4) | (LSB & 0x0F); ret.uuid_.uuid.uuid128[15 - n++] = ((msb & 0x0F) << 4) | (lsb & 0x0F);
i += 2; i += 2;
} }
} else { } else {

View file

@ -15,6 +15,7 @@ namespace esp32_ble_beacon {
static const char *const TAG = "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 = { static esp_ble_adv_params_t ble_adv_params = {
.adv_int_min = 0x20, .adv_int_min = 0x20,
.adv_int_max = 0x40, .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)) #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}; .flags = {0x02, 0x01, 0x06}, .length = 0x1A, .type = 0xFF, .company_id = 0x004C, .beacon_type = 0x1502};
void ESP32BLEBeacon::dump_config() { void ESP32BLEBeacon::dump_config() {
@ -90,7 +91,7 @@ void ESP32BLEBeacon::ble_setup() {
} }
esp_ble_ibeacon_t ibeacon_adv_data; 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(), memcpy(&ibeacon_adv_data.ibeacon_vendor.proximity_uuid, global_esp32_ble_beacon->uuid_.data(),
sizeof(ibeacon_adv_data.ibeacon_vendor.proximity_uuid)); sizeof(ibeacon_adv_data.ibeacon_vendor.proximity_uuid));
ibeacon_adv_data.ibeacon_vendor.minor = ENDIAN_CHANGE_U16(global_esp32_ble_beacon->minor_); 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 esp32_ble_beacon
} // namespace esphome } // 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) { void BLECharacteristic::set_value(std::vector<uint8_t> value) {
xSemaphoreTake(this->set_value_lock_, 0L); xSemaphoreTake(this->set_value_lock_, 0L);
this->value_ = value; this->value_ = std::move(value);
xSemaphoreGive(this->set_value_lock_); xSemaphoreGive(this->set_value_lock_);
} }
void BLECharacteristic::set_value(const std::string &value) { 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->uuid_ = uuid;
this->value_.attr_len = 0; this->value_.attr_len = 0;
this->value_.attr_max_len = max_len; 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) { void BLEDescriptor::do_create(BLECharacteristic *characteristic) {
this->characteristic_ = 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) { 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()); 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); this->services_.push_back(service);
if (advertise) { if (advertise) {
esp32_ble::global_ble->get_advertising()->add_service_uuid(uuid); 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:"); } 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 esp32_ble_server
} // namespace esphome } // namespace esphome

View file

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

View file

@ -21,7 +21,7 @@ namespace esp32_ble_tracker {
static const char *const TAG = "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 ble_addr_to_uint64(const esp_bd_addr_t address) {
uint64_t u = 0; uint64_t u = 0;
@ -55,7 +55,7 @@ void ESP32BLETracker::loop() {
&ble_event->event_.gattc.gattc_param); &ble_event->event_.gattc.gattc_param);
else else
this->real_gap_event_handler(ble_event->event_.gap.gap_event, &ble_event->event_.gap.gap_param); 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(); 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) { 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); 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) { void ESP32BLETracker::real_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
switch (event) { 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, void ESP32BLETracker::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) { 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); 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, 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) { 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; } 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) { void CameraImageReader::set_image(std::shared_ptr<CameraImage> image) {
this->image_ = image; this->image_ = std::move(image);
this->offset_ = 0; this->offset_ = 0;
} }
size_t CameraImageReader::available() const { 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_ = this->service_->create_characteristic(improv::RPC_COMMAND_UUID, BLECharacteristic::PROPERTY_WRITE);
this->rpc_->on_write([this](const std::vector<uint8_t> &data) { 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()); this->incoming_data_.insert(this->incoming_data_.end(), data.begin(), data.end());
} }
}); });
@ -56,7 +56,7 @@ void ESP32ImprovComponent::setup_characteristics() {
} }
void ESP32ImprovComponent::loop() { void ESP32ImprovComponent::loop() {
if (this->incoming_data_.size() > 0) if (!this->incoming_data_.empty())
this->process_incoming_data_(); this->process_incoming_data_();
uint32_t now = millis(); uint32_t now = millis();
@ -162,7 +162,7 @@ bool ESP32ImprovComponent::check_identify_() {
void ESP32ImprovComponent::set_state_(improv::State state) { void ESP32ImprovComponent::set_state_(improv::State state) {
ESP_LOGV(TAG, "Setting state: %d", state); ESP_LOGV(TAG, "Setting state: %d", state);
this->state_ = 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}; uint8_t data[1]{state};
this->status_->set_value(data, 1); this->status_->set_value(data, 1);
if (state != improv::STATE_STOPPED) if (state != improv::STATE_STOPPED)
@ -173,7 +173,7 @@ void ESP32ImprovComponent::set_state_(improv::State state) {
void ESP32ImprovComponent::set_error_(improv::Error error) { void ESP32ImprovComponent::set_error_(improv::Error error) {
if (error != improv::ERROR_NONE) if (error != improv::ERROR_NONE)
ESP_LOGE(TAG, "Error: %d", error); 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}; uint8_t data[1]{error};
this->error_->set_value(data, 1); this->error_->set_value(data, 1);
if (this->state_ != improv::STATE_STOPPED) 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); }; 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 esp32_improv
} // namespace esphome } // namespace esphome

View file

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

View file

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

View file

@ -16,17 +16,17 @@
// Defined in WiFiGeneric.cpp, sets global initialized flag, starts network event task queue and calls // Defined in WiFiGeneric.cpp, sets global initialized flag, starts network event task queue and calls
// tcpip_adapter_init() // tcpip_adapter_init()
extern void tcpipInit(); extern void tcpipInit(); // NOLINT(readability-identifier-naming)
namespace esphome { namespace esphome {
namespace ethernet { namespace ethernet {
static const char *const TAG = "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) \ #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)); \ ESP_LOGE(TAG, message ": (%d) %s", err, esp_err_to_name(err)); \
this->mark_failed(); \ this->mark_failed(); \
return; \ 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_mdio_pin(uint8_t mdio_pin) { this->mdio_pin_ = mdio_pin; }
void EthernetComponent::set_type(EthernetType type) { this->type_ = type; } 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_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 { std::string EthernetComponent::get_use_address() const {
if (this->use_address_.empty()) { if (this->use_address_.empty()) {
return App.get_name() + ".local"; 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_mdio_pin(uint8_t mdio_pin);
void set_type(EthernetType type); void set_type(EthernetType type);
void set_clk_mode(eth_clock_mode_t clk_mode); 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(); IPAddress get_ip_address();
std::string get_use_address() const; std::string get_use_address() const;

View file

@ -10,11 +10,12 @@ static const char *const TAG = "i2c";
I2CComponent::I2CComponent() { I2CComponent::I2CComponent() {
#ifdef ARDUINO_ARCH_ESP32 #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; this->wire_ = &Wire;
else else
this->wire_ = new TwoWire(next_i2c_bus_num_); this->wire_ = new TwoWire(next_i2c_bus_num); // NOLINT(cppcoreguidelines-owning-memory)
next_i2c_bus_num_++; next_i2c_bus_num++;
#else #else
this->wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer) this->wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer)
#endif #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; } 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) { I2CRegister &I2CRegister::operator=(uint8_t value) {
this->parent_->write_byte(this->register_, value); this->parent_->write_byte(this->register_, value);
return *this; return *this;

View file

@ -131,10 +131,6 @@ class I2CComponent : public Component {
bool scan_; bool scan_;
}; };
#ifdef ARDUINO_ARCH_ESP32
extern uint8_t next_i2c_bus_num_;
#endif
class I2CDevice; class I2CDevice;
class I2CMultiplexer; class I2CMultiplexer;
class I2CRegister { 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"); ESP_LOGVV(TAG, "parse_device(): address is not public");
return false; 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"); ESP_LOGVV(TAG, "parse_device(): service_data is expected to be empty");
return false; return false;
} }
auto mnfDatas = device.get_manufacturer_datas(); auto mnf_datas = device.get_manufacturer_datas();
if (mnfDatas.size() != 1) { if (mnf_datas.size() != 1) {
ESP_LOGVV(TAG, "parse_device(): manufacturer_datas is expected to have a single element"); ESP_LOGVV(TAG, "parse_device(): manufacturer_datas is expected to have a single element");
return false; return false;
} }
auto mnfData = mnfDatas[0]; auto mnf_data = mnf_datas[0];
if (mnfData.uuid.get_uuid().len != ESP_UUID_LEN_16) { 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"); ESP_LOGVV(TAG, "parse_device(): manufacturer data element is expected to have uuid of length 16");
return false; 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"); ESP_LOGVV(TAG, "parse_device(): manufacturer data element length is expected to be of length 7");
return false; return false;
} }
if (mnfData.data[6] != 8) { if (mnf_data.data[6] != 8) {
ESP_LOGVV(TAG, "parse_device(): unexpected data"); ESP_LOGVV(TAG, "parse_device(): unexpected data");
return false; return false;
} }
@ -72,20 +72,20 @@ bool InkbirdIBSTH1_MINI::parse_device(const esp32_ble_tracker::ESPBTDevice &devi
auto external_temperature = NAN; auto external_temperature = NAN;
// Read bluetooth data into variable // 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 // 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; temperature = measured_temperature;
} else if (mnfData.data[2] == 1) { } else if (mnf_data.data[2] == 1) {
external_temperature = measured_temperature; external_temperature = measured_temperature;
} else { } else {
ESP_LOGVV(TAG, "parse_device(): unknown sensor type"); ESP_LOGVV(TAG, "parse_device(): unknown sensor type");
return false; return false;
} }
auto battery_level = mnfData.data[5]; auto battery_level = mnf_data.data[5];
auto humidity = ((mnfData.data[1] << 8) + mnfData.data[0]) / 100.0f; auto humidity = ((mnf_data.data[1] << 8) + mnf_data.data[0]) / 100.0f;
// Send temperature only if the value is set // Send temperature only if the value is set
if (!isnan(temperature) && this->temperature_ != nullptr) { if (!isnan(temperature) && this->temperature_ != nullptr) {

View file

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

View file

@ -63,7 +63,7 @@ void LEDCOutput::update_frequency(float frequency) {
this->write_state(this->duty_); this->write_state(this->duty_);
} }
uint8_t next_ledc_channel = 0; uint8_t next_ledc_channel = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace ledc } // namespace ledc
} // namespace esphome } // namespace esphome

View file

@ -88,8 +88,8 @@ void MQTTClientComponent::start_dnslookup_() {
this->dns_resolved_ = false; this->dns_resolved_ = false;
ip_addr_t addr; ip_addr_t addr;
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
err_t err = dns_gethostbyname_addrtype(this->credentials_.address.c_str(), &addr, this->dns_found_callback, this, err_t err = dns_gethostbyname_addrtype(this->credentials_.address.c_str(), &addr,
LWIP_DNS_ADDRTYPE_IPV4); MQTTClientComponent::dns_found_callback, this, LWIP_DNS_ADDRTYPE_IPV4);
#endif #endif
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
err_t err = dns_gethostbyname(this->credentials_.address.c_str(), &addr, err_t err = dns_gethostbyname(this->credentials_.address.c_str(), &addr,

View file

@ -25,15 +25,10 @@ int Nextion::upload_by_chunks_(HTTPClient *http, int range_start) {
if (range_end > this->tft_size_) if (range_end > this->tft_size_)
range_end = this->tft_size_; range_end = this->tft_size_;
bool begin_status = false;
#ifdef ARDUINO_ARCH_ESP32
begin_status = http->begin(this->tft_url_.c_str());
#endif
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
#ifndef CLANG_TIDY #ifndef CLANG_TIDY
http->setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); http->setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
http->setRedirectLimit(3); http->setRedirectLimit(3);
begin_status = http->begin(*this->get_wifi_client_(), this->tft_url_.c_str());
#endif #endif
#endif #endif
@ -44,6 +39,7 @@ int Nextion::upload_by_chunks_(HTTPClient *http, int range_start) {
int tries = 1; int tries = 1;
int code = 0; int code = 0;
bool begin_status = false;
while (tries <= 5) { while (tries <= 5) {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
begin_status = http->begin(this->tft_url_.c_str()); begin_status = http->begin(this->tft_url_.c_str());
@ -156,7 +152,7 @@ void Nextion::upload_tft() {
ESP_LOGD(TAG, "connection failed"); ESP_LOGD(TAG, "connection failed");
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
if (psramFound()) if (psramFound())
free(this->transfer_buffer_); free(this->transfer_buffer_); // NOLINT
else else
#endif #endif
delete this->transfer_buffer_; delete this->transfer_buffer_;

View file

@ -45,10 +45,11 @@ pulse_counter_t PulseCounterStorage::read_raw_value() {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
bool PulseCounterStorage::pulse_counter_setup(GPIOPin *pin) { bool PulseCounterStorage::pulse_counter_setup(GPIOPin *pin) {
static pcnt_unit_t next_pcnt_unit = PCNT_UNIT_0;
this->pin = pin; this->pin = pin;
this->pin->setup(); this->pin->setup();
this->pcnt_unit = next_pcnt_unit; this->pcnt_unit = next_pcnt_unit;
next_pcnt_unit = pcnt_unit_t(int(next_pcnt_unit) + 1); // NOLINT next_pcnt_unit = pcnt_unit_t(int(next_pcnt_unit) + 1);
ESP_LOGCONFIG(TAG, " PCNT Unit Number: %u", this->pcnt_unit); ESP_LOGCONFIG(TAG, " PCNT Unit Number: %u", this->pcnt_unit);
@ -166,9 +167,5 @@ void PulseCounterSensor::update() {
} }
} }
#ifdef ARDUINO_ARCH_ESP32
pcnt_unit_t next_pcnt_unit = PCNT_UNIT_0;
#endif
} // namespace pulse_counter } // namespace pulse_counter
} // namespace esphome } // namespace esphome

View file

@ -69,9 +69,5 @@ class PulseCounterSensor : public sensor::Sensor, public PollingComponent {
sensor::Sensor *total_sensor_; sensor::Sensor *total_sensor_;
}; };
#ifdef ARDUINO_ARCH_ESP32
extern pcnt_unit_t next_pcnt_unit;
#endif
} // namespace pulse_counter } // namespace pulse_counter
} // namespace esphome } // namespace esphome

View file

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

View file

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

View file

@ -10,7 +10,7 @@ static const uint32_t BIT_TIME_US = 889;
static const uint8_t NBITS = 14; static const uint8_t NBITS = 14;
void RC5Protocol::encode(RemoteTransmitData *dst, const RC5Data &data) { void RC5Protocol::encode(RemoteTransmitData *dst, const RC5Data &data) {
static bool TOGGLE = false; static bool toggle = false;
dst->set_carrier_frequency(36000); dst->set_carrier_frequency(36000);
uint64_t out_data = 0; uint64_t out_data = 0;
@ -21,7 +21,7 @@ void RC5Protocol::encode(RemoteTransmitData *dst, const RC5Data &data) {
} else { } else {
out_data |= 0b11 << 12; out_data |= 0b11 << 12;
} }
out_data |= TOGGLE << 11; out_data |= toggle << 11;
out_data |= data.address << 6; out_data |= data.address << 6;
out_data |= command; out_data |= command;
@ -34,7 +34,7 @@ void RC5Protocol::encode(RemoteTransmitData *dst, const RC5Data &data) {
dst->space(BIT_TIME_US); dst->space(BIT_TIME_US);
} }
} }
TOGGLE = !TOGGLE; toggle = !toggle;
} }
optional<RC5Data> RC5Protocol::decode(RemoteReceiveData src) { optional<RC5Data> RC5Protocol::decode(RemoteReceiveData src) {
RC5Data out{ RC5Data out{

View file

@ -3,7 +3,7 @@
#ifdef USE_SOCKET_IMPL_BSD_SOCKETS #ifdef USE_SOCKET_IMPL_BSD_SOCKETS
#include <string.h> #include <cstring>
namespace esphome { namespace esphome {
namespace socket { namespace socket {
@ -13,14 +13,14 @@ std::string format_sockaddr(const struct sockaddr_storage &storage) {
const struct sockaddr_in *addr = reinterpret_cast<const struct sockaddr_in *>(&storage); const struct sockaddr_in *addr = reinterpret_cast<const struct sockaddr_in *>(&storage);
char buf[INET_ADDRSTRLEN]; char buf[INET_ADDRSTRLEN];
const char *ret = inet_ntop(AF_INET, &addr->sin_addr, buf, sizeof(buf)); const char *ret = inet_ntop(AF_INET, &addr->sin_addr, buf, sizeof(buf));
if (ret == NULL) if (ret == nullptr)
return {}; return {};
return std::string{buf}; return std::string{buf};
} else if (storage.ss_family == AF_INET6) { } else if (storage.ss_family == AF_INET6) {
const struct sockaddr_in6 *addr = reinterpret_cast<const struct sockaddr_in6 *>(&storage); const struct sockaddr_in6 *addr = reinterpret_cast<const struct sockaddr_in6 *>(&storage);
char buf[INET6_ADDRSTRLEN]; char buf[INET6_ADDRSTRLEN];
const char *ret = inet_ntop(AF_INET6, &addr->sin6_addr, buf, sizeof(buf)); const char *ret = inet_ntop(AF_INET6, &addr->sin6_addr, buf, sizeof(buf));
if (ret == NULL) if (ret == nullptr)
return {}; return {};
return std::string{buf}; return std::string{buf};
} }
@ -32,7 +32,7 @@ class BSDSocketImpl : public Socket {
BSDSocketImpl(int fd) : Socket(), fd_(fd) {} BSDSocketImpl(int fd) : Socket(), fd_(fd) {}
~BSDSocketImpl() override { ~BSDSocketImpl() override {
if (!closed_) { if (!closed_) {
close(); close(); // NOLINT(clang-analyzer-optin.cplusplus.VirtualCall)
} }
} }
std::unique_ptr<Socket> accept(struct sockaddr *addr, socklen_t *addrlen) override { std::unique_ptr<Socket> accept(struct sockaddr *addr, socklen_t *addrlen) override {

View file

@ -61,7 +61,7 @@ void SPIComponent::setup() {
if (spi_bus_num == 0) { if (spi_bus_num == 0) {
this->hw_spi_ = &SPI; this->hw_spi_ = &SPI;
} else { } else {
this->hw_spi_ = new SPIClass(VSPI); this->hw_spi_ = new SPIClass(VSPI); // NOLINT(cppcoreguidelines-owning-memory)
} }
spi_bus_num++; spi_bus_num++;
this->hw_spi_->begin(clk_pin, miso_pin, mosi_pin); this->hw_spi_->begin(clk_pin, miso_pin, mosi_pin);

View file

@ -458,26 +458,26 @@ void HOT ST7735::write_display_data_() {
} }
void ST7735::spi_master_write_addr_(uint16_t addr1, uint16_t addr2) { void ST7735::spi_master_write_addr_(uint16_t addr1, uint16_t addr2) {
static uint8_t BYTE[4]; static uint8_t byte[4];
BYTE[0] = (addr1 >> 8) & 0xFF; byte[0] = (addr1 >> 8) & 0xFF;
BYTE[1] = addr1 & 0xFF; byte[1] = addr1 & 0xFF;
BYTE[2] = (addr2 >> 8) & 0xFF; byte[2] = (addr2 >> 8) & 0xFF;
BYTE[3] = addr2 & 0xFF; byte[3] = addr2 & 0xFF;
this->dc_pin_->digital_write(true); this->dc_pin_->digital_write(true);
this->write_array(BYTE, 4); this->write_array(byte, 4);
} }
void ST7735::spi_master_write_color_(uint16_t color, uint16_t size) { void ST7735::spi_master_write_color_(uint16_t color, uint16_t size) {
static uint8_t BYTE[1024]; static uint8_t byte[1024];
int index = 0; int index = 0;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
BYTE[index++] = (color >> 8) & 0xFF; byte[index++] = (color >> 8) & 0xFF;
BYTE[index++] = color & 0xFF; byte[index++] = color & 0xFF;
} }
this->dc_pin_->digital_write(true); this->dc_pin_->digital_write(true);
return write_array(BYTE, size * 2); return write_array(byte, size * 2);
} }
} // namespace st7735 } // namespace st7735

View file

@ -197,26 +197,26 @@ void ST7789V::write_data_(uint8_t value) {
} }
void ST7789V::write_addr_(uint16_t addr1, uint16_t addr2) { void ST7789V::write_addr_(uint16_t addr1, uint16_t addr2) {
static uint8_t BYTE[4]; static uint8_t byte[4];
BYTE[0] = (addr1 >> 8) & 0xFF; byte[0] = (addr1 >> 8) & 0xFF;
BYTE[1] = addr1 & 0xFF; byte[1] = addr1 & 0xFF;
BYTE[2] = (addr2 >> 8) & 0xFF; byte[2] = (addr2 >> 8) & 0xFF;
BYTE[3] = addr2 & 0xFF; byte[3] = addr2 & 0xFF;
this->dc_pin_->digital_write(true); this->dc_pin_->digital_write(true);
this->write_array(BYTE, 4); this->write_array(byte, 4);
} }
void ST7789V::write_color_(uint16_t color, uint16_t size) { void ST7789V::write_color_(uint16_t color, uint16_t size) {
static uint8_t BYTE[1024]; static uint8_t byte[1024];
int index = 0; int index = 0;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
BYTE[index++] = (color >> 8) & 0xFF; byte[index++] = (color >> 8) & 0xFF;
BYTE[index++] = color & 0xFF; byte[index++] = color & 0xFF;
} }
this->dc_pin_->digital_write(true); this->dc_pin_->digital_write(true);
return write_array(BYTE, size * 2); return write_array(byte, size * 2);
} }
int ST7789V::get_height_internal() { int ST7789V::get_height_internal() {

View file

@ -126,10 +126,6 @@ class UARTComponent : public Component, public Stream {
#endif #endif
}; };
#ifdef ARDUINO_ARCH_ESP32
extern uint8_t next_uart_num;
#endif
class UARTDevice : public Stream { class UARTDevice : public Stream {
public: public:
UARTDevice() = default; UARTDevice() = default;

View file

@ -8,7 +8,6 @@
namespace esphome { namespace esphome {
namespace uart { namespace uart {
static const char *const TAG = "uart_esp32"; static const char *const TAG = "uart_esp32";
uint8_t next_uart_num = 1;
static const uint32_t UART_PARITY_EVEN = 0 << 0; static const uint32_t UART_PARITY_EVEN = 0 << 0;
static const uint32_t UART_PARITY_ODD = 1 << 0; static const uint32_t UART_PARITY_ODD = 1 << 0;
@ -80,7 +79,8 @@ void UARTComponent::setup() {
#endif #endif
this->hw_serial_ = &Serial; this->hw_serial_ = &Serial;
} else { } else {
this->hw_serial_ = new HardwareSerial(next_uart_num++); static uint8_t next_uart_num = 1;
this->hw_serial_ = new HardwareSerial(next_uart_num++); // NOLINT(cppcoreguidelines-owning-memory)
} }
int8_t tx = this->tx_pin_.has_value() ? *this->tx_pin_ : -1; int8_t tx = this->tx_pin_.has_value() ? *this->tx_pin_ : -1;
int8_t rx = this->rx_pin_.has_value() ? *this->rx_pin_ : -1; int8_t rx = this->rx_pin_.has_value() ? *this->rx_pin_ : -1;
@ -99,7 +99,7 @@ void UARTComponent::dump_config() {
} }
ESP_LOGCONFIG(TAG, " Baud Rate: %u baud", this->baud_rate_); ESP_LOGCONFIG(TAG, " Baud Rate: %u baud", this->baud_rate_);
ESP_LOGCONFIG(TAG, " Data Bits: %u", this->data_bits_); ESP_LOGCONFIG(TAG, " Data Bits: %u", this->data_bits_);
ESP_LOGCONFIG(TAG, " Parity: %s", parity_to_str(this->parity_)); ESP_LOGCONFIG(TAG, " Parity: %s", LOG_STR_ARG(parity_to_str(this->parity_)));
ESP_LOGCONFIG(TAG, " Stop bits: %u", this->stop_bits_); ESP_LOGCONFIG(TAG, " Stop bits: %u", this->stop_bits_);
this->check_logger_conflict_(); this->check_logger_conflict_();
} }

View file

@ -25,31 +25,31 @@ namespace wifi {
static const char *const TAG = "wifi_esp32"; static const char *const TAG = "wifi_esp32";
bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) { bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
uint8_t current_mode = WiFi.getMode(); uint8_t current_mode = WiFiClass::getMode();
bool current_sta = current_mode & 0b01; bool current_sta = current_mode & 0b01;
bool current_ap = current_mode & 0b10; bool current_ap = current_mode & 0b10;
bool sta_ = sta.value_or(current_sta); bool enable_sta = sta.value_or(current_sta);
bool ap_ = ap.value_or(current_ap); bool enable_ap = ap.value_or(current_ap);
if (current_sta == sta_ && current_ap == ap_) if (current_sta == enable_sta && current_ap == enable_ap)
return true; return true;
if (sta_ && !current_sta) { if (enable_sta && !current_sta) {
ESP_LOGV(TAG, "Enabling STA."); ESP_LOGV(TAG, "Enabling STA.");
} else if (!sta_ && current_sta) { } else if (!enable_sta && current_sta) {
ESP_LOGV(TAG, "Disabling STA."); ESP_LOGV(TAG, "Disabling STA.");
} }
if (ap_ && !current_ap) { if (enable_ap && !current_ap) {
ESP_LOGV(TAG, "Enabling AP."); ESP_LOGV(TAG, "Enabling AP.");
} else if (!ap_ && current_ap) { } else if (!enable_ap && current_ap) {
ESP_LOGV(TAG, "Disabling AP."); ESP_LOGV(TAG, "Disabling AP.");
} }
uint8_t mode = 0; uint8_t mode = 0;
if (sta_) if (enable_sta)
mode |= 0b01; mode |= 0b01;
if (ap_) if (enable_ap)
mode |= 0b10; mode |= 0b10;
bool ret = WiFi.mode(static_cast<wifi_mode_t>(mode)); bool ret = WiFiClass::mode(static_cast<wifi_mode_t>(mode));
if (!ret) { if (!ret) {
ESP_LOGW(TAG, "Setting WiFi mode failed!"); ESP_LOGW(TAG, "Setting WiFi mode failed!");
@ -159,8 +159,8 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv417wifi_sta_config_t // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv417wifi_sta_config_t
wifi_config_t conf; wifi_config_t conf;
memset(&conf, 0, sizeof(conf)); memset(&conf, 0, sizeof(conf));
strcpy(reinterpret_cast<char *>(conf.sta.ssid), ap.get_ssid().c_str()); strlcpy(reinterpret_cast<char *>(conf.sta.ssid), ap.get_ssid().c_str(), sizeof(conf.sta.ssid));
strcpy(reinterpret_cast<char *>(conf.sta.password), ap.get_password().c_str()); strlcpy(reinterpret_cast<char *>(conf.sta.password), ap.get_password().c_str(), sizeof(conf.sta.password));
// The weakest authmode to accept in the fast scan mode // The weakest authmode to accept in the fast scan mode
if (ap.get_password().empty()) { if (ap.get_password().empty()) {
@ -176,10 +176,10 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
#endif #endif
if (ap.get_bssid().has_value()) { if (ap.get_bssid().has_value()) {
conf.sta.bssid_set = 1; conf.sta.bssid_set = true;
memcpy(conf.sta.bssid, ap.get_bssid()->data(), 6); memcpy(conf.sta.bssid, ap.get_bssid()->data(), 6);
} else { } else {
conf.sta.bssid_set = 0; conf.sta.bssid_set = false;
} }
if (ap.get_channel().has_value()) { if (ap.get_channel().has_value()) {
conf.sta.channel = *ap.get_channel(); conf.sta.channel = *ap.get_channel();
@ -559,7 +559,7 @@ void WiFiComponent::wifi_pre_setup_() {
// Make sure WiFi is in clean state before anything starts // Make sure WiFi is in clean state before anything starts
this->wifi_mode_(false, false); this->wifi_mode_(false, false);
} }
wl_status_t WiFiComponent::wifi_sta_status_() { return WiFi.status(); } wl_status_t WiFiComponent::wifi_sta_status_() { return WiFiClass::status(); }
bool WiFiComponent::wifi_scan_start_() { bool WiFiComponent::wifi_scan_start_() {
// enable STA // enable STA
if (!this->wifi_mode_(true, {})) if (!this->wifi_mode_(true, {}))
@ -660,7 +660,7 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
wifi_config_t conf; wifi_config_t conf;
memset(&conf, 0, sizeof(conf)); memset(&conf, 0, sizeof(conf));
strcpy(reinterpret_cast<char *>(conf.ap.ssid), ap.get_ssid().c_str()); strlcpy(reinterpret_cast<char *>(conf.ap.ssid), ap.get_ssid().c_str(), sizeof(conf.ap.ssid));
conf.ap.channel = ap.get_channel().value_or(1); conf.ap.channel = ap.get_channel().value_or(1);
conf.ap.ssid_hidden = ap.get_ssid().size(); conf.ap.ssid_hidden = ap.get_ssid().size();
conf.ap.max_connection = 5; conf.ap.max_connection = 5;
@ -671,7 +671,7 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
*conf.ap.password = 0; *conf.ap.password = 0;
} else { } else {
conf.ap.authmode = WIFI_AUTH_WPA2_PSK; conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
strcpy(reinterpret_cast<char *>(conf.ap.password), ap.get_password().c_str()); strlcpy(reinterpret_cast<char *>(conf.ap.password), ap.get_password().c_str(), sizeof(conf.ap.ssid));
} }
#if ESP_IDF_VERSION_MAJOR >= 4 #if ESP_IDF_VERSION_MAJOR >= 4

View file

@ -581,7 +581,7 @@ wl_status_t WiFiComponent::wifi_sta_status_() {
} }
} }
bool WiFiComponent::wifi_scan_start_() { bool WiFiComponent::wifi_scan_start_() {
static bool FIRST_SCAN = false; static bool first_scan = false;
// enable STA // enable STA
if (!this->wifi_mode_(true, {})) if (!this->wifi_mode_(true, {}))
@ -595,7 +595,7 @@ bool WiFiComponent::wifi_scan_start_() {
config.show_hidden = 1; config.show_hidden = 1;
#if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 4, 0) #if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 4, 0)
config.scan_type = WIFI_SCAN_TYPE_ACTIVE; config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
if (FIRST_SCAN) { if (first_scan) {
config.scan_time.active.min = 100; config.scan_time.active.min = 100;
config.scan_time.active.max = 200; config.scan_time.active.max = 200;
} else { } else {
@ -603,7 +603,7 @@ bool WiFiComponent::wifi_scan_start_() {
config.scan_time.active.max = 500; config.scan_time.active.max = 500;
} }
#endif #endif
FIRST_SCAN = false; first_scan = false;
bool ret = wifi_station_scan(&config, &WiFiComponent::s_wifi_scan_done_callback); bool ret = wifi_station_scan(&config, &WiFiComponent::s_wifi_scan_done_callback);
if (!ret) { if (!ret) {
ESP_LOGV(TAG, "wifi_station_scan failed!"); ESP_LOGV(TAG, "wifi_station_scan failed!");

View file

@ -15,7 +15,7 @@ static const char *const TAG = "xiaomi_ble";
bool parse_xiaomi_value(uint8_t value_type, const uint8_t *data, uint8_t value_length, XiaomiParseResult &result) { bool parse_xiaomi_value(uint8_t value_type, const uint8_t *data, uint8_t value_length, XiaomiParseResult &result) {
// motion detection, 1 byte, 8-bit unsigned integer // motion detection, 1 byte, 8-bit unsigned integer
if ((value_type == 0x03) && (value_length == 1)) { if ((value_type == 0x03) && (value_length == 1)) {
result.has_motion = (data[0]) ? true : false; result.has_motion = data[0];
} }
// temperature, 2 bytes, 16-bit signed integer (LE), 0.1 °C // temperature, 2 bytes, 16-bit signed integer (LE), 0.1 °C
else if ((value_type == 0x04) && (value_length == 2)) { else if ((value_type == 0x04) && (value_length == 2)) {
@ -31,7 +31,7 @@ bool parse_xiaomi_value(uint8_t value_type, const uint8_t *data, uint8_t value_l
else if (((value_type == 0x07) || (value_type == 0x0F)) && (value_length == 3)) { else if (((value_type == 0x07) || (value_type == 0x0F)) && (value_length == 3)) {
const uint32_t illuminance = uint32_t(data[0]) | (uint32_t(data[1]) << 8) | (uint32_t(data[2]) << 16); const uint32_t illuminance = uint32_t(data[0]) | (uint32_t(data[1]) << 8) | (uint32_t(data[2]) << 16);
result.illuminance = illuminance; result.illuminance = illuminance;
result.is_light = (illuminance == 100) ? true : false; result.is_light = illuminance == 100;
if (value_type == 0x0F) if (value_type == 0x0F)
result.has_motion = true; result.has_motion = true;
} }
@ -62,7 +62,7 @@ bool parse_xiaomi_value(uint8_t value_type, const uint8_t *data, uint8_t value_l
} }
// on/off state, 1 byte, 8-bit unsigned integer // on/off state, 1 byte, 8-bit unsigned integer
else if ((value_type == 0x12) && (value_length == 1)) { else if ((value_type == 0x12) && (value_length == 1)) {
result.is_active = (data[0]) ? true : false; result.is_active = data[0];
} }
// mosquito tablet, 1 byte, 8-bit unsigned integer, 1 % // mosquito tablet, 1 byte, 8-bit unsigned integer, 1 %
else if ((value_type == 0x13) && (value_length == 1)) { else if ((value_type == 0x13) && (value_length == 1)) {
@ -72,7 +72,7 @@ bool parse_xiaomi_value(uint8_t value_type, const uint8_t *data, uint8_t value_l
else if ((value_type == 0x17) && (value_length == 4)) { else if ((value_type == 0x17) && (value_length == 4)) {
const uint32_t idle_time = encode_uint32(data[3], data[2], data[1], data[0]); const uint32_t idle_time = encode_uint32(data[3], data[2], data[1], data[0]);
result.idle_time = idle_time / 60.0f; result.idle_time = idle_time / 60.0f;
result.has_motion = (idle_time) ? false : true; result.has_motion = !idle_time;
} else { } else {
return false; return false;
} }
@ -81,7 +81,7 @@ bool parse_xiaomi_value(uint8_t value_type, const uint8_t *data, uint8_t value_l
} }
bool parse_xiaomi_message(const std::vector<uint8_t> &message, XiaomiParseResult &result) { bool parse_xiaomi_message(const std::vector<uint8_t> &message, XiaomiParseResult &result) {
result.has_encryption = (message[0] & 0x08) ? true : false; // update encryption status result.has_encryption = message[0] & 0x08; // update encryption status
if (result.has_encryption) { if (result.has_encryption) {
ESP_LOGVV(TAG, "parse_xiaomi_message(): payload is encrypted, stop reading message."); ESP_LOGVV(TAG, "parse_xiaomi_message(): payload is encrypted, stop reading message.");
return false; return false;
@ -136,9 +136,9 @@ optional<XiaomiParseResult> parse_xiaomi_header(const esp32_ble_tracker::Service
} }
auto raw = service_data.data; auto raw = service_data.data;
result.has_data = (raw[0] & 0x40) ? true : false; result.has_data = raw[0] & 0x40;
result.has_capability = (raw[0] & 0x20) ? true : false; result.has_capability = raw[0] & 0x20;
result.has_encryption = (raw[0] & 0x08) ? true : false; result.has_encryption = raw[0] & 0x08;
if (!result.has_data) { if (!result.has_data) {
ESP_LOGVV(TAG, "parse_xiaomi_header(): service data has no DATA flag."); ESP_LOGVV(TAG, "parse_xiaomi_header(): service data has no DATA flag.");

View file

@ -52,11 +52,7 @@ bool XiaomiCGD1::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
void XiaomiCGD1::set_bindkey(const std::string &bindkey) { void XiaomiCGD1::set_bindkey(const std::string &bindkey) {
@ -67,7 +63,7 @@ void XiaomiCGD1::set_bindkey(const std::string &bindkey) {
char temp[3] = {0}; char temp[3] = {0};
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
strncpy(temp, &(bindkey.c_str()[i * 2]), 2); strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
bindkey_[i] = std::strtoul(temp, NULL, 16); bindkey_[i] = std::strtoul(temp, nullptr, 16);
} }
} }

View file

@ -52,11 +52,7 @@ bool XiaomiCGDK2::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
void XiaomiCGDK2::set_bindkey(const std::string &bindkey) { void XiaomiCGDK2::set_bindkey(const std::string &bindkey) {
@ -67,7 +63,7 @@ void XiaomiCGDK2::set_bindkey(const std::string &bindkey) {
char temp[3] = {0}; char temp[3] = {0};
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
strncpy(temp, &(bindkey.c_str()[i * 2]), 2); strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
bindkey_[i] = std::strtoul(temp, NULL, 16); bindkey_[i] = std::strtoul(temp, nullptr, 16);
} }
} }

View file

@ -52,11 +52,7 @@ bool XiaomiCGG1::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
void XiaomiCGG1::set_bindkey(const std::string &bindkey) { void XiaomiCGG1::set_bindkey(const std::string &bindkey) {
@ -67,7 +63,7 @@ void XiaomiCGG1::set_bindkey(const std::string &bindkey) {
char temp[3] = {0}; char temp[3] = {0};
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
strncpy(temp, &(bindkey.c_str()[i * 2]), 2); strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
bindkey_[i] = std::strtoul(temp, NULL, 16); bindkey_[i] = std::strtoul(temp, nullptr, 16);
} }
} }

View file

@ -6,7 +6,7 @@
namespace esphome { namespace esphome {
namespace xiaomi_cgpr1 { namespace xiaomi_cgpr1 {
static const char *TAG = "xiaomi_cgpr1"; static const char *const TAG = "xiaomi_cgpr1";
void XiaomiCGPR1::dump_config() { void XiaomiCGPR1::dump_config() {
ESP_LOGCONFIG(TAG, "Xiaomi CGPR1"); ESP_LOGCONFIG(TAG, "Xiaomi CGPR1");
@ -54,11 +54,7 @@ bool XiaomiCGPR1::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
void XiaomiCGPR1::set_bindkey(const std::string &bindkey) { void XiaomiCGPR1::set_bindkey(const std::string &bindkey) {
@ -69,7 +65,7 @@ void XiaomiCGPR1::set_bindkey(const std::string &bindkey) {
char temp[3] = {0}; char temp[3] = {0};
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
strncpy(temp, &(bindkey.c_str()[i * 2]), 2); strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
bindkey_[i] = std::strtoul(temp, NULL, 16); bindkey_[i] = std::strtoul(temp, nullptr, 16);
} }
} }

View file

@ -53,11 +53,7 @@ bool XiaomiGCLS002::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
} // namespace xiaomi_gcls002 } // namespace xiaomi_gcls002

View file

@ -56,11 +56,7 @@ bool XiaomiHHCCJCY01::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
} // namespace xiaomi_hhccjcy01 } // namespace xiaomi_hhccjcy01

View file

@ -47,11 +47,7 @@ bool XiaomiHHCCPOT002::parse_device(const esp32_ble_tracker::ESPBTDevice &device
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
} // namespace xiaomi_hhccpot002 } // namespace xiaomi_hhccpot002

View file

@ -53,11 +53,7 @@ bool XiaomiJQJCY01YM::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
} // namespace xiaomi_jqjcy01ym } // namespace xiaomi_jqjcy01ym

View file

@ -50,11 +50,7 @@ bool XiaomiLYWSD02::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
} // namespace xiaomi_lywsd02 } // namespace xiaomi_lywsd02

View file

@ -56,11 +56,7 @@ bool XiaomiLYWSD03MMC::parse_device(const esp32_ble_tracker::ESPBTDevice &device
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
void XiaomiLYWSD03MMC::set_bindkey(const std::string &bindkey) { void XiaomiLYWSD03MMC::set_bindkey(const std::string &bindkey) {
@ -71,7 +67,7 @@ void XiaomiLYWSD03MMC::set_bindkey(const std::string &bindkey) {
char temp[3] = {0}; char temp[3] = {0};
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
strncpy(temp, &(bindkey.c_str()[i * 2]), 2); strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
bindkey_[i] = std::strtoul(temp, NULL, 16); bindkey_[i] = std::strtoul(temp, nullptr, 16);
} }
} }

View file

@ -50,11 +50,7 @@ bool XiaomiLYWSDCGQ::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
} // namespace xiaomi_lywsdcgq } // namespace xiaomi_lywsdcgq

View file

@ -56,11 +56,7 @@ bool XiaomiMHOC401::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
void XiaomiMHOC401::set_bindkey(const std::string &bindkey) { void XiaomiMHOC401::set_bindkey(const std::string &bindkey) {
@ -71,7 +67,7 @@ void XiaomiMHOC401::set_bindkey(const std::string &bindkey) {
char temp[3] = {0}; char temp[3] = {0};
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
strncpy(temp, &(bindkey.c_str()[i * 2]), 2); strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
bindkey_[i] = std::strtoul(temp, NULL, 16); bindkey_[i] = std::strtoul(temp, nullptr, 16);
} }
} }

View file

@ -71,8 +71,8 @@ bool XiaomiMiscale2::parse_message(const std::vector<uint8_t> &message, ParseRes
return false; return false;
} }
bool is_Stabilized = ((data[1] & (1 << 5)) != 0) ? true : false; bool is_stabilized = ((data[1] & (1 << 5)) != 0);
bool loadRemoved = ((data[1] & (1 << 7)) != 0) ? true : false; bool load_removed = ((data[1] & (1 << 7)) != 0);
// weight, 2 bytes, 16-bit unsigned integer, 1 kg // weight, 2 bytes, 16-bit unsigned integer, 1 kg
const int16_t weight = uint16_t(data[11]) | (uint16_t(data[12]) << 8); const int16_t weight = uint16_t(data[11]) | (uint16_t(data[12]) << 8);
@ -85,11 +85,7 @@ bool XiaomiMiscale2::parse_message(const std::vector<uint8_t> &message, ParseRes
const int16_t impedance = uint16_t(data[9]) | (uint16_t(data[10]) << 8); const int16_t impedance = uint16_t(data[9]) | (uint16_t(data[10]) << 8);
result.impedance = impedance; result.impedance = impedance;
if (!is_Stabilized || loadRemoved || impedance == 0 || impedance >= 3000) { return is_stabilized && !load_removed && impedance != 0 && impedance < 3000;
return false;
}
return true;
} }
bool XiaomiMiscale2::report_results(const optional<ParseResult> &result, const std::string &address) { bool XiaomiMiscale2::report_results(const optional<ParseResult> &result, const std::string &address) {

View file

@ -57,11 +57,7 @@ bool XiaomiMJYD02YLA::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
void XiaomiMJYD02YLA::set_bindkey(const std::string &bindkey) { void XiaomiMJYD02YLA::set_bindkey(const std::string &bindkey) {
@ -72,7 +68,7 @@ void XiaomiMJYD02YLA::set_bindkey(const std::string &bindkey) {
char temp[3] = {0}; char temp[3] = {0};
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
strncpy(temp, &(bindkey.c_str()[i * 2]), 2); strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
bindkey_[i] = std::strtoul(temp, NULL, 16); bindkey_[i] = std::strtoul(temp, nullptr, 16);
} }
} }

View file

@ -46,11 +46,7 @@ bool XiaomiMUE4094RT::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
} // namespace xiaomi_mue4094rt } // namespace xiaomi_mue4094rt

View file

@ -51,11 +51,7 @@ bool XiaomiWX08ZM::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
success = true; success = true;
} }
if (!success) { return success;
return false;
}
return true;
} }
} // namespace xiaomi_wx08zm } // namespace xiaomi_wx08zm

View file

@ -111,11 +111,11 @@ void Application::loop() {
} }
void ICACHE_RAM_ATTR HOT Application::feed_wdt() { void ICACHE_RAM_ATTR HOT Application::feed_wdt() {
static uint32_t LAST_FEED = 0; static uint32_t last_feed = 0;
uint32_t now = millis(); uint32_t now = millis();
if (now - LAST_FEED > 3) { if (now - last_feed > 3) {
this->feed_wdt_arch_(); this->feed_wdt_arch_();
LAST_FEED = now; last_feed = now;
#ifdef USE_STATUS_LED #ifdef USE_STATUS_LED
if (status_led::global_status_led != nullptr) { if (status_led::global_status_led != nullptr) {
status_led::global_status_led->call(); status_led::global_status_led->call();

View file

@ -11,7 +11,6 @@
#define ESPHOME_PROJECT_VERSION "v2" #define ESPHOME_PROJECT_VERSION "v2"
// Feature flags // Feature flags
#define USE_ADC_SENSOR_VCC
#define USE_API #define USE_API
#define USE_BINARY_SENSOR #define USE_BINARY_SENSOR
#define USE_CAPTIVE_PORTAL #define USE_CAPTIVE_PORTAL
@ -46,12 +45,12 @@
#define USE_ESP32_CAMERA #define USE_ESP32_CAMERA
#define USE_ETHERNET #define USE_ETHERNET
#define USE_IMPROV #define USE_IMPROV
#define USE_SOCKET_IMPL_BSD_SOCKETS
#endif #endif
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
#define USE_ADC_SENSOR_VCC
#define USE_SOCKET_IMPL_LWIP_TCP #define USE_SOCKET_IMPL_LWIP_TCP
#else
#define USE_SOCKET_IMPL_BSD_SOCKETS
#endif #endif
#define USE_API_PLAINTEXT #define USE_API_PLAINTEXT

View file

@ -69,7 +69,6 @@ lib_deps =
Update Update
build_flags = build_flags =
${common.build_flags} ${common.build_flags}
-DUSE_ETHERNET
src_filter = src_filter =
${common.src_filter} ${common.src_filter}
-<esphome/components/esp8266_pwm> -<esphome/components/esp8266_pwm>

View file

@ -16,7 +16,7 @@ import click
import pexpect import pexpect
sys.path.append(os.path.dirname(__file__)) sys.path.append(os.path.dirname(__file__))
from helpers import shlex_quote, get_output, \ from helpers import shlex_quote, get_output, filter_grep, \
build_all_include, temp_header_file, git_ls_files, filter_changed, load_idedata build_all_include, temp_header_file, git_ls_files, filter_changed, load_idedata
@ -27,13 +27,15 @@ def clang_options(idedata):
# disable built-in include directories from the host # disable built-in include directories from the host
'-nostdinc', '-nostdinc',
'-nostdinc++', '-nostdinc++',
# pretend we're an Xtensa compiler, which gates some features in the headers
'-D__XTENSA__',
# allow to condition code on the presence of clang-tidy # allow to condition code on the presence of clang-tidy
'-DCLANG_TIDY' '-DCLANG_TIDY'
] ]
# copy compiler flags, except those clang doesn't understand. # copy compiler flags, except those clang doesn't understand.
cmd.extend(flag for flag in idedata['cxx_flags'].split(' ') cmd.extend(flag for flag in idedata['cxx_flags'].split(' ')
if flag not in ('-free', '-fipa-pta', '-mlongcalls', '-mtext-section-literals')) if flag not in ('-free', '-fipa-pta', '-fstrict-volatile-bitfields', '-mlongcalls', '-mtext-section-literals'))
# defines # defines
cmd.extend(f'-D{define}' for define in idedata['defines']) cmd.extend(f'-D{define}' for define in idedata['defines'])
@ -97,6 +99,8 @@ def main():
parser.add_argument('-j', '--jobs', type=int, parser.add_argument('-j', '--jobs', type=int,
default=multiprocessing.cpu_count(), default=multiprocessing.cpu_count(),
help='number of tidy instances to be run in parallel.') help='number of tidy instances to be run in parallel.')
parser.add_argument('-e', '--environment', default='esp8266-tidy',
help='the PlatformIO environment to run against (esp8266-tidy or esp32-tidy)')
parser.add_argument('files', nargs='*', default=[], parser.add_argument('files', nargs='*', default=[],
help='files to be processed (regex on path)') help='files to be processed (regex on path)')
parser.add_argument('--fix', action='store_true', help='apply fix-its') parser.add_argument('--fix', action='store_true', help='apply fix-its')
@ -104,6 +108,7 @@ def main():
help='run clang-tidy in quiet mode') help='run clang-tidy in quiet mode')
parser.add_argument('-c', '--changed', action='store_true', parser.add_argument('-c', '--changed', action='store_true',
help='only run on changed files') help='only run on changed files')
parser.add_argument('-g', '--grep', help='only run on files containing value')
parser.add_argument('--split-num', type=int, help='split the files into X jobs.', parser.add_argument('--split-num', type=int, help='split the files into X jobs.',
default=None) default=None)
parser.add_argument('--split-at', type=int, help='which split is this? starts at 1', parser.add_argument('--split-at', type=int, help='which split is this? starts at 1',
@ -126,7 +131,7 @@ def main():
""") """)
return 1 return 1
idedata = load_idedata("esp8266-tidy") idedata = load_idedata(args.environment)
options = clang_options(idedata) options = clang_options(idedata)
files = [] files = []
@ -141,6 +146,9 @@ def main():
if args.changed: if args.changed:
files = filter_changed(files) files = filter_changed(files)
if args.grep:
files = filter_grep(files, args.grep)
files.sort() files.sort()
if args.split_num: if args.split_num:

View file

@ -92,6 +92,16 @@ def filter_changed(files):
return files return files
def filter_grep(files, value):
matched = []
for file in files:
with open(file, "r") as handle:
contents = handle.read()
if value in contents:
matched.append(file)
return matched
def git_ls_files(patterns=None): def git_ls_files(patterns=None):
command = ["git", "ls-files", "-s"] command = ["git", "ls-files", "-s"]
if patterns is not None: if patterns is not None: