ESPHome  2024.11.0
ble_descriptor.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #ifdef USE_ESP32
6 
7 #include <esp_gatt_defs.h>
8 #include <esp_gatts_api.h>
9 
10 namespace esphome {
11 namespace esp32_ble_server {
12 
13 using namespace esp32_ble;
14 
15 class BLECharacteristic;
16 
18  public:
19  BLEDescriptor(ESPBTUUID uuid, uint16_t max_len = 100);
20  virtual ~BLEDescriptor();
21  void do_create(BLECharacteristic *characteristic);
22 
23  void set_value(const std::string &value);
24  void set_value(const uint8_t *data, size_t length);
25 
26  void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
27 
28  bool is_created() { return this->state_ == CREATED; }
29  bool is_failed() { return this->state_ == FAILED; }
30 
31  protected:
32  BLECharacteristic *characteristic_{nullptr};
34  uint16_t handle_{0xFFFF};
35 
36  esp_attr_value_t value_;
37 
38  esp_gatt_perm_t permissions_ = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
39 
40  enum State : uint8_t {
41  FAILED = 0x00,
45  } state_{INIT};
46 };
47 
48 } // namespace esp32_ble_server
49 } // namespace esphome
50 
51 #endif
uint16_t length
Definition: tt21100.cpp:12
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7