Control Surface disable-pipes
MIDI Control Surface library for Arduino
ble2902.c
Go to the documentation of this file.
1#ifdef ESP32
2
3#include "ble2902.h"
4#include "logging.h"
5
6#include <string.h> // memcpy
7
8void ble2902_handle_write(esp_gatt_if_t gatts_if,
9 esp_ble_gatts_cb_param_t *param) {
10 // The actual writing of data and sending a response is already handled
11 // by Bluedroid.
12 uint16_t handle = param->write.handle;
13 if (ble2902_get_value(handle) == 0x0001) {
14 ESP_LOGI("MIDIBLE", "notify enable");
15 } else if (ble2902_get_value(handle) == 0x0002) {
16 ESP_LOGI("MIDIBLE", "indicate enable");
17 } else if (ble2902_get_value(handle) == 0x0003) {
18 ESP_LOGI("MIDIBLE", "notify & indicate enable");
19 } else if (ble2902_get_value(handle) == 0x0000) {
20 ESP_LOGI("MIDIBLE", "notify/indicate disable ");
21 } else {
22 ESP_LOGE("MIDIBLE", "Unknown descriptor value %04x",
23 ble2902_get_value(handle));
24 }
25}
26
27uint16_t ble2902_get_value(uint16_t handle) {
28 const uint8_t *data;
29 uint16_t length;
30 esp_ble_gatts_get_attr_value(handle, &length, &data);
31 if (length != 2) {
32 ESP_LOGE("MIDIBLE", "Unexpected descriptor value length (%d)", length);
33 return 0;
34 }
35 uint16_t ret;
36 memcpy(&ret, data, length);
37 return ret;
38}
39
40bool ble2902_notifications_enabled(uint16_t handle) {
41 return ble2902_get_value(handle) & 0x0001;
42}
43
44bool ble2902_indications_enabled(uint16_t handle) {
45 return ble2902_get_value(handle) & 0x0002;
46}
47
48#endif
Handling the Client Characteristic Configuration Descriptor (UUID 0x2902) for MIDI over Bluetooth Low...
bool ble2902_notifications_enabled(uint16_t handle)
Check if notifications are enabled by the client.
bool ble2902_indications_enabled(uint16_t handle)
Check if indications are enabled by the client.
void ble2902_handle_write(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
Callback when the client writes to the descriptor.
uint16_t ble2902_get_value(uint16_t handle)
Get the value of the descriptor.