ESPHome  2022.6.3
ble.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ble_advertising.h"
4 
6 #include "esphome/core/defines.h"
7 #include "esphome/core/helpers.h"
8 #include "queue.h"
9 
10 #ifdef USE_ESP32_BLE_SERVER
12 #endif
13 
14 #ifdef USE_ESP32
15 
16 #include <esp_gap_ble_api.h>
17 #include <esp_gatts_api.h>
18 #include <esp_gattc_api.h>
19 namespace esphome {
20 namespace esp32_ble {
21 
22 // NOLINTNEXTLINE(modernize-use-using)
23 typedef struct {
24  void *peer_device;
25  bool connected;
26  uint16_t mtu;
28 
29 class ESP32BLE : public Component {
30  public:
31  void setup() override;
32  void loop() override;
33  void dump_config() override;
34  float get_setup_priority() const override;
35  void mark_failed() override;
36 
37  bool has_server() {
38 #ifdef USE_ESP32_BLE_SERVER
39  return this->server_ != nullptr;
40 #else
41  return false;
42 #endif
43  }
44  bool has_client() { return false; }
45 
47 
48 #ifdef USE_ESP32_BLE_SERVER
49  void set_server(esp32_ble_server::BLEServer *server) { this->server_ = server; }
50 #endif
51  protected:
52  static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
53  static void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
54  static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
55 
56  void real_gatts_event_handler_(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
57  void real_gattc_event_handler_(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
58  void real_gap_event_handler_(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
59 
60  bool ble_setup_();
61 
62 #ifdef USE_ESP32_BLE_SERVER
64 #endif
67 };
68 
69 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
70 extern ESP32BLE *global_ble;
71 
72 } // namespace esp32_ble
73 } // namespace esphome
74 
75 #endif
esp32_ble_server::BLEServer * server_
Definition: ble.h:63
ESP32BLE * global_ble
Definition: ble.cpp:208
void set_server(esp32_ble_server::BLEServer *server)
Definition: ble.h:49
static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
Definition: ble.cpp:185
Queue< BLEEvent > ble_events_
Definition: ble.h:65
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
Definition: ble.cpp:172
void real_gattc_event_handler_(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
Definition: ble.cpp:199
float get_setup_priority() const override
Definition: ble.cpp:204
void real_gatts_event_handler_(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
Definition: ble.cpp:191
void setup() override
Definition: ble.cpp:24
void mark_failed() override
Definition: ble.cpp:43
BLEAdvertising * get_advertising()
Definition: ble.h:46
void dump_config() override
Definition: ble.cpp:206
void loop() override
Definition: ble.cpp:153
void real_gap_event_handler_(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
Definition: ble.cpp:177
static void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
Definition: a4988.cpp:4
BLEAdvertising * advertising_
Definition: ble.h:66