Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
midi-events.c
Go to the documentation of this file.
1#ifdef ESP32
2#include <sdkconfig.h>
3#if CONFIG_BT_BLE_ENABLED
4
13#include "ble2902.h"
14#include "logging.h"
15#include "midi-private.h"
16#include <esp_gap_ble_api.h>
17#include <stdbool.h>
18
19static bool security_initiate_encryption = false;
20
21void set_security_initiate_encryption(bool security_initiate_encryption_) {
22 security_initiate_encryption = security_initiate_encryption_;
23}
24
25void midi_handle_gatts_event(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
26 esp_ble_gatts_cb_param_t *param) {
27 // If this event is not specific to an interface, we're interested
28 // If this event is for our interface, we're interested as well.
29 bool for_us = gatts_if == ESP_GATT_IF_NONE || //
30 gatts_if == midi_get_gatts_if();
31 if (!for_us)
32 return;
33
34 switch (event) {
35 case ESP_GATTS_REG_EVT:
36 esp_ble_gap_config_local_privacy(true);
37 midi_handle_register_app_event(gatts_if, param);
38 break;
39
40 case ESP_GATTS_READ_EVT:
41 if (param->read.handle == midi_get_characteristic_handle())
42 midi_handle_read_event(gatts_if, param);
43 break;
44
45 case ESP_GATTS_WRITE_EVT:
46 // If it's a short write to our 2902 descriptor
47 if (param->write.is_prep == false &&
48 midi_get_descriptor_handle() == param->write.handle) {
49 ble2902_handle_write(gatts_if, param);
50 }
51 // If it's a write (short or long) to our MIDI characteristic
52 if (midi_get_characteristic_handle() == param->write.handle)
53 midi_handle_write_event(gatts_if, param);
54 break;
55 case ESP_GATTS_EXEC_WRITE_EVT:
56 midi_handle_write_exec_event(gatts_if, param);
57 break;
58
59 case ESP_GATTS_MTU_EVT: midi_handle_mtu_event(gatts_if, param); break;
60
61 case ESP_GATTS_CONF_EVT: break;
62 case ESP_GATTS_UNREG_EVT: break;
63 case ESP_GATTS_CREATE_EVT: break;
64 case ESP_GATTS_ADD_INCL_SRVC_EVT: break;
65 case ESP_GATTS_ADD_CHAR_EVT: break;
66 case ESP_GATTS_ADD_CHAR_DESCR_EVT: break;
67 case ESP_GATTS_DELETE_EVT: break;
68 case ESP_GATTS_START_EVT: break;
69 case ESP_GATTS_STOP_EVT: break;
70 case ESP_GATTS_CONNECT_EVT:
71 if (security_initiate_encryption)
72 esp_ble_set_encryption(param->connect.remote_bda,
73 ESP_BLE_SEC_ENCRYPT_MITM);
74 midi_handle_connect_event(gatts_if, param);
75 break;
76 case ESP_GATTS_DISCONNECT_EVT:
77 midi_handle_disconnect_event(gatts_if, param);
78 break;
79 case ESP_GATTS_OPEN_EVT: break;
80 case ESP_GATTS_CANCEL_OPEN_EVT: break;
81 case ESP_GATTS_CLOSE_EVT: break;
82 case ESP_GATTS_LISTEN_EVT: break;
83 case ESP_GATTS_CONGEST_EVT: break;
84 case ESP_GATTS_RESPONSE_EVT: break;
85 case ESP_GATTS_CREAT_ATTR_TAB_EVT:
86 if (param->add_attr_tab.status != ESP_GATT_OK) {
87 ESP_LOGE("MIDIBLE",
88 "create attribute table failed, error code=0x%x",
89 param->add_attr_tab.status);
90 break;
91 }
93 break;
94
95 case ESP_GATTS_SET_ATTR_VAL_EVT: break;
96 case ESP_GATTS_SEND_SERVICE_CHANGE_EVT: break;
97 default: break;
98 }
99}
100
101#endif
102#endif
Handling the Client Characteristic Configuration Descriptor (UUID 0x2902) for MIDI over Bluetooth Low...
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.
Declarations of internal functions for the MIDI over BLE system, used in the midi-*....
void midi_handle_read_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void midi_handle_register_app_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void midi_handle_mtu_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void midi_handle_disconnect_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void midi_handle_write_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
uint16_t midi_get_gatts_if(void)
void midi_handle_create_attribute_table_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void midi_handle_gatts_event(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void midi_handle_connect_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
uint16_t midi_get_descriptor_handle(void)
uint16_t midi_get_characteristic_handle(void)
void midi_handle_write_exec_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void set_security_initiate_encryption(bool security_initiate_encryption_)
Configure whether the Arduino should initiate the bonding/secure connection.