Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
events-debug.c
Go to the documentation of this file.
1#ifdef ESP32
2#include <sdkconfig.h>
3#if CONFIG_BT_BLE_ENABLED
4
5#include "events-debug.h"
6#include "esp_enums2string.h"
7#include "logging.h"
8
9#include <stdlib.h> // malloc
10
11void print_gatts_event(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
12 esp_ble_gatts_cb_param_t *param) {
13 ESP_LOGI("MIDIBLE", "GATTS event: %s", esp_gatts_cb_event_to_string(event));
14}
15
16void show_bonded_devices(void) {
17 int dev_num = esp_ble_get_bond_device_num();
18 esp_ble_bond_dev_t *dev_list =
19 (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
20 esp_ble_get_bond_device_list(&dev_num, dev_list);
21 ESP_LOGI("MIDIBLE", "Bonded devices list [%d]:", dev_num);
22 for (int i = 0; i < dev_num; i++) {
23 ESP_LOGI("MIDIBLE", " - %02x:%02x:%02x:%02x:%02x:%02x",
24 dev_list[i].bd_addr[0], dev_list[i].bd_addr[1],
25 dev_list[i].bd_addr[2], dev_list[i].bd_addr[3],
26 dev_list[i].bd_addr[4], dev_list[i].bd_addr[5]);
27 }
28 free(dev_list);
29}
30
31void print_gap_event(esp_gap_ble_cb_event_t event,
32 esp_ble_gap_cb_param_t *param) {
33 ESP_LOGI("MIDIBLE", "GAP event: %s", esp_gap_ble_cb_event_to_string(event));
34
35 switch (event) {
36 case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
37 ESP_LOGI("MIDIBLE",
38 "status: %d, min_int: %d, max_int: %d, conn_int: %d, "
39 "latency: %d, timeout: %d",
40 param->update_conn_params.status,
41 param->update_conn_params.min_int,
42 param->update_conn_params.max_int,
43 param->update_conn_params.conn_int,
44 param->update_conn_params.latency,
45 param->update_conn_params.timeout);
46 break;
47
48 case ESP_GAP_BLE_PASSKEY_NOTIF_EVT:
49 // The app will receive this evt when the IO has Output capability
50 // and the peer device IO has Input capability.
51 // Show the passkey number to the user to input on the peer device.
52 ESP_LOGI("MIDIBLE", "The passkey Notify number: %06d",
53 param->ble_security.key_notif.passkey);
54 break;
55
56 case ESP_GAP_BLE_KEY_EVT:
57 ESP_LOGI("MIDIBLE", "key type: %s",
59 param->ble_security.ble_key.key_type));
60 break;
61
62 case ESP_GAP_BLE_AUTH_CMPL_EVT:
63 ESP_LOGI("MIDIBLE", "%02x:%02x:%02x:%02x:%02x:%02x",
64 param->ble_security.auth_cmpl.bd_addr[0],
65 param->ble_security.auth_cmpl.bd_addr[1],
66 param->ble_security.auth_cmpl.bd_addr[2],
67 param->ble_security.auth_cmpl.bd_addr[3],
68 param->ble_security.auth_cmpl.bd_addr[4],
69 param->ble_security.auth_cmpl.bd_addr[5]);
70 ESP_LOGI("MIDIBLE", "address type: %d",
71 param->ble_security.auth_cmpl.addr_type);
72 ESP_LOGI("MIDIBLE", "pair status: %s",
73 param->ble_security.auth_cmpl.success ? "success"
74 : "fail");
75 if (!param->ble_security.auth_cmpl.success) {
76 ESP_LOGI("MIDIBLE", "fail reason: 0x%x",
77 param->ble_security.auth_cmpl.fail_reason);
78 } else {
79 ESP_LOGI("MIDIBLE", "auth mode: %s",
81 param->ble_security.auth_cmpl.auth_mode));
82 }
84 break;
85
86 case ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT:
87 ESP_LOGI("MIDIBLE", "status: %d",
88 param->remove_bond_dev_cmpl.status);
89 ESP_LOGI("MIDIBLE", "%02x:%02x:%02x:%02x:%02x:%02x",
90 param->remove_bond_dev_cmpl.bd_addr[0],
91 param->remove_bond_dev_cmpl.bd_addr[1],
92 param->remove_bond_dev_cmpl.bd_addr[2],
93 param->remove_bond_dev_cmpl.bd_addr[3],
94 param->remove_bond_dev_cmpl.bd_addr[4],
95 param->remove_bond_dev_cmpl.bd_addr[5]);
96 break;
97
98 default: break;
99 }
100}
101
102#endif
103#endif
Helpers for printing the names of enum values of the ESP32 Bluetooth API.
const char * esp_gatts_cb_event_to_string(esp_gatts_cb_event_t event)
const char * esp_ble_key_type_to_string(esp_ble_key_type_t key_type)
const char * esp_gap_ble_cb_event_to_string(esp_gap_ble_cb_event_t event)
const char * esp_ble_auth_req_to_string(esp_ble_auth_req_t auth_type)
Helpers for printing Bluetooth events and status.
void print_gatts_event(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void show_bonded_devices(void)
void print_gap_event(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)