ESPHome  2025.2.0
ble_descriptor.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #ifdef USE_ESP32
8 
9 #include <esp_gatt_defs.h>
10 #include <esp_gatts_api.h>
11 
12 namespace esphome {
13 namespace esp32_ble_server {
14 
15 using namespace esp32_ble;
16 using namespace bytebuffer;
17 using namespace event_emitter;
18 
19 class BLECharacteristic;
20 
21 namespace BLEDescriptorEvt {
22 enum VectorEvt {
24 };
25 } // namespace BLEDescriptorEvt
26 
27 class BLEDescriptor : public EventEmitter<BLEDescriptorEvt::VectorEvt, std::vector<uint8_t>, uint16_t> {
28  public:
29  BLEDescriptor(ESPBTUUID uuid, uint16_t max_len = 100, bool read = true, bool write = true);
30  virtual ~BLEDescriptor();
31  void do_create(BLECharacteristic *characteristic);
32  ESPBTUUID get_uuid() const { return this->uuid_; }
33 
34  void set_value(std::vector<uint8_t> buffer);
35  void set_value(ByteBuffer buffer) { this->set_value(buffer.get_data()); }
36 
37  void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
38 
39  bool is_created() { return this->state_ == CREATED; }
40  bool is_failed() { return this->state_ == FAILED; }
41 
42  protected:
43  BLECharacteristic *characteristic_{nullptr};
45  uint16_t handle_{0xFFFF};
46 
47  esp_attr_value_t value_{};
48 
49  esp_gatt_perm_t permissions_{};
50 
51  enum State : uint8_t {
52  FAILED = 0x00,
56  } state_{INIT};
57 };
58 
59 } // namespace esp32_ble_server
60 } // namespace esphome
61 
62 #endif
std::vector< uint8_t > get_data()
Definition: bytebuffer.h:300
A class modelled on the Java ByteBuffer class.
Definition: bytebuffer.h:38
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7