mirror of
https://github.com/esphome/esphome.git
synced 2025-10-03 18:42:23 +01:00
wip
This commit is contained in:
@@ -160,7 +160,6 @@ esphome/components/esp_ldo/* @clydebarrow
|
||||
esphome/components/espnow/* @jesserockz
|
||||
esphome/components/ethernet_info/* @gtjadsonsantos
|
||||
esphome/components/event/* @nohat
|
||||
esphome/components/event_emitter/* @Rapsssito
|
||||
esphome/components/exposure_notifications/* @OttoWinter
|
||||
esphome/components/ezo/* @ssieb
|
||||
esphome/components/ezo_pmp/* @carlos-sarmiento
|
||||
|
@@ -209,7 +209,7 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
|
||||
break; // For some reason you can request a read but not want a response
|
||||
|
||||
if (this->on_read_callback_) {
|
||||
this->on_read_callback_(param->read.conn_id);
|
||||
(*this->on_read_callback_)(param->read.conn_id);
|
||||
}
|
||||
|
||||
uint16_t max_offset = 22;
|
||||
@@ -279,7 +279,7 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
|
||||
|
||||
if (!param->write.is_prep) {
|
||||
if (this->on_write_callback_) {
|
||||
this->on_write_callback_(this->value_, param->write.conn_id);
|
||||
(*this->on_write_callback_)(this->value_, param->write.conn_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
|
||||
this->write_event_ = false;
|
||||
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) {
|
||||
if (this->on_write_callback_) {
|
||||
this->on_write_callback_(this->value_, param->exec_write.conn_id);
|
||||
(*this->on_write_callback_)(this->value_, param->exec_write.conn_id);
|
||||
}
|
||||
}
|
||||
esp_err_t err =
|
||||
|
@@ -75,7 +75,8 @@ void BLEDescriptor::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
|
||||
this->value_.attr_len = param->write.len;
|
||||
memcpy(this->value_.attr_value, param->write.value, param->write.len);
|
||||
if (this->on_write_callback_) {
|
||||
this->on_write_callback_(std::span<const uint8_t>(param->write.value, param->write.len), param->write.conn_id);
|
||||
(*this->on_write_callback_)(std::span<const uint8_t>(param->write.value, param->write.len),
|
||||
param->write.conn_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -8,13 +8,14 @@
|
||||
#include <esp_gatt_defs.h>
|
||||
#include <esp_gatts_api.h>
|
||||
#include <span>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace esphome {
|
||||
namespace esp32_ble_server {
|
||||
|
||||
using namespace esp32_ble;
|
||||
using namespace bytebuffer;
|
||||
using namespace event_emitter;
|
||||
|
||||
class BLECharacteristic;
|
||||
|
||||
@@ -34,9 +35,10 @@ class BLEDescriptor {
|
||||
bool is_created() { return this->state_ == CREATED; }
|
||||
bool is_failed() { return this->state_ == FAILED; }
|
||||
|
||||
// Direct callback registration
|
||||
// Direct callback registration - only allocates when callback is set
|
||||
void on_write(std::function<void(std::span<const uint8_t>, uint16_t)> &&callback) {
|
||||
this->on_write_callback_ = std::move(callback);
|
||||
this->on_write_callback_ =
|
||||
std::make_unique<std::function<void(std::span<const uint8_t>, uint16_t)>>(std::move(callback));
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -46,7 +48,7 @@ class BLEDescriptor {
|
||||
|
||||
esp_attr_value_t value_{};
|
||||
|
||||
std::function<void(std::span<const uint8_t>, uint16_t)> on_write_callback_{nullptr};
|
||||
std::unique_ptr<std::function<void(std::span<const uint8_t>, uint16_t)>> on_write_callback_;
|
||||
|
||||
esp_gatt_perm_t permissions_{};
|
||||
|
||||
|
@@ -154,7 +154,7 @@ void BLEServer::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t ga
|
||||
ESP_LOGD(TAG, "BLE Client connected");
|
||||
this->add_client_(param->connect.conn_id);
|
||||
if (this->on_connect_callback_) {
|
||||
this->on_connect_callback_(param->connect.conn_id);
|
||||
(*this->on_connect_callback_)(param->connect.conn_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ void BLEServer::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t ga
|
||||
this->remove_client_(param->disconnect.conn_id);
|
||||
this->parent_->advertising_start();
|
||||
if (this->on_disconnect_callback_) {
|
||||
this->on_disconnect_callback_(param->disconnect.conn_id);
|
||||
(*this->on_disconnect_callback_)(param->disconnect.conn_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <functional>
|
||||
|
||||
#ifdef USE_ESP32
|
||||
|
||||
@@ -55,9 +56,13 @@ class BLEServer : public Component, public GATTsEventHandler, public BLEStatusEv
|
||||
|
||||
void ble_before_disabled_event_handler() override;
|
||||
|
||||
// Direct callback registration
|
||||
void on_connect(std::function<void(uint16_t)> &&callback) { this->on_connect_callback_ = std::move(callback); }
|
||||
void on_disconnect(std::function<void(uint16_t)> &&callback) { this->on_disconnect_callback_ = std::move(callback); }
|
||||
// Direct callback registration - only allocates when callback is set
|
||||
void on_connect(std::function<void(uint16_t)> &&callback) {
|
||||
this->on_connect_callback_ = std::make_unique<std::function<void(uint16_t)>>(std::move(callback));
|
||||
}
|
||||
void on_disconnect(std::function<void(uint16_t)> &&callback) {
|
||||
this->on_disconnect_callback_ = std::make_unique<std::function<void(uint16_t)>>(std::move(callback));
|
||||
}
|
||||
|
||||
protected:
|
||||
struct ServiceEntry {
|
||||
@@ -71,8 +76,8 @@ class BLEServer : public Component, public GATTsEventHandler, public BLEStatusEv
|
||||
void add_client_(uint16_t conn_id) { this->clients_.insert(conn_id); }
|
||||
void remove_client_(uint16_t conn_id) { this->clients_.erase(conn_id); }
|
||||
|
||||
std::function<void(uint16_t)> on_connect_callback_{nullptr};
|
||||
std::function<void(uint16_t)> on_disconnect_callback_{nullptr};
|
||||
std::unique_ptr<std::function<void(uint16_t)>> on_connect_callback_;
|
||||
std::unique_ptr<std::function<void(uint16_t)>> on_disconnect_callback_;
|
||||
|
||||
std::vector<uint8_t> manufacturer_data_{};
|
||||
esp_gatt_if_t gatts_if_{0};
|
||||
|
Reference in New Issue
Block a user