ESPHome 2025.5.0
Loading...
Searching...
No Matches
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
12namespace esphome {
13namespace esp32_ble_server {
14
15using namespace esp32_ble;
16using namespace bytebuffer;
17using namespace event_emitter;
18
19class BLECharacteristic;
20
21namespace BLEDescriptorEvt {
25} // namespace BLEDescriptorEvt
26
27class 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:
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
A class modelled on the Java ByteBuffer class.
Definition bytebuffer.h:38
std::vector< uint8_t > get_data()
Definition bytebuffer.h:300
enum esphome::esp32_ble_server::BLEDescriptor::State INIT
void do_create(BLECharacteristic *characteristic)
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
BLEDescriptor(ESPBTUUID uuid, uint16_t max_len=100, bool read=true, bool write=true)
void set_value(std::vector< uint8_t > buffer)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7