From 9ff838bf35d75319adc36cf0fe8352d6bdfde9e6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 29 Sep 2025 18:13:46 -0500 Subject: [PATCH] wip --- .../esp32_ble_server/ble_characteristic.h | 14 +++++++++----- .../components/esp32_ble_server/ble_descriptor.h | 1 - 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/esphome/components/esp32_ble_server/ble_characteristic.h b/esphome/components/esp32_ble_server/ble_characteristic.h index 3404cca55b..4a29683f41 100644 --- a/esphome/components/esp32_ble_server/ble_characteristic.h +++ b/esphome/components/esp32_ble_server/ble_characteristic.h @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef USE_ESP32 @@ -65,11 +66,14 @@ class BLECharacteristic { bool is_created(); bool is_failed(); - // Direct callback registration + // Direct callback registration - only allocates when callback is set void on_write(std::function, uint16_t)> &&callback) { - this->on_write_callback_ = std::move(callback); + this->on_write_callback_ = + std::make_unique, uint16_t)>>(std::move(callback)); + } + void on_read(std::function &&callback) { + this->on_read_callback_ = std::make_unique>(std::move(callback)); } - void on_read(std::function &&callback) { this->on_read_callback_ = std::move(callback); } protected: bool write_event_{false}; @@ -93,8 +97,8 @@ class BLECharacteristic { void remove_client_from_notify_list_(uint16_t conn_id); ClientNotificationEntry *find_client_in_notify_list_(uint16_t conn_id); - std::function, uint16_t)> on_write_callback_{nullptr}; - std::function on_read_callback_{nullptr}; + std::unique_ptr, uint16_t)>> on_write_callback_; + std::unique_ptr> on_read_callback_; esp_gatt_perm_t permissions_ = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; diff --git a/esphome/components/esp32_ble_server/ble_descriptor.h b/esphome/components/esp32_ble_server/ble_descriptor.h index 00138d306d..a43d9a84a0 100644 --- a/esphome/components/esp32_ble_server/ble_descriptor.h +++ b/esphome/components/esp32_ble_server/ble_descriptor.h @@ -1,7 +1,6 @@ #pragma once #include "esphome/components/esp32_ble/ble_uuid.h" -#include "esphome/components/event_emitter/event_emitter.h" #include "esphome/components/bytebuffer/bytebuffer.h" #ifdef USE_ESP32