Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
midi-connection.c
Go to the documentation of this file.
1#ifdef ESP32
2#include <sdkconfig.h>
3#if CONFIG_BT_BLE_ENABLED
4
11#include "advertising.h"
12#include "app.h"
13#include "logging.h"
14#include "midi-private.h"
15
16#include <string.h> // memcpy
17
18#include <esp_gap_ble_api.h>
19
20void midi_handle_connect_event(esp_gatt_if_t gatts_if,
21 esp_ble_gatts_cb_param_t *param) {
22 ESP_LOGI("MIDIBLE",
23 "Connection ID: %d, remote: "
24 "%02x:%02x:%02x:%02x:%02x:%02x:",
25 param->connect.conn_id, param->connect.remote_bda[0],
26 param->connect.remote_bda[1], param->connect.remote_bda[2],
27 param->connect.remote_bda[3], param->connect.remote_bda[4],
28 param->connect.remote_bda[5]);
29
30 midi_ble_instance_handle_connect(param->connect.conn_id);
31
32 // <?> Do we need to update the connection parameters?
33 // Can we just rely on the central picking sensible defaults or
34 // honoring the advertising connection interval range?
35
36 // For the IOS system, please reference the apple official documents about
37 // the ble connection parameters restrictions:
38 // https://web.archive.org/web/20240318204212/https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf
39 // https://developer.apple.com/library/archive/qa/qa1931/_index.html
40
41 esp_ble_conn_update_params_t conn_params;
42 memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
43 advertising_get_connection_interval(&conn_params.min_int,
44 &conn_params.max_int);
45 conn_params.latency = 0;
46 conn_params.timeout = 400; // timeout = 400*10ms = 4s
47 esp_ble_gap_update_conn_params(&conn_params);
48}
49
50void midi_handle_disconnect_event(esp_gatt_if_t gatts_if,
51 esp_ble_gatts_cb_param_t *param) {
52 ESP_LOGI("MIDIBLE", "Disconnect reason: %d", param->disconnect.reason);
53 midi_ble_instance_handle_disconnect(param->disconnect.conn_id);
54 // Start advertising again
56}
57
58#endif
59#endif
Advertising the MIDI service for Bluetooth Low Energy.
void advertising_get_connection_interval(uint16_t *itvl_min, uint16_t *itvl_max)
Get the connection interval range from the advertising data.
void advertising_start(void)
Start advertising, after already being configured.
void midi_ble_instance_handle_disconnect(uint16_t conn_handle)
void midi_ble_instance_handle_connect(uint16_t conn_handle)
Declarations of internal functions for the MIDI over BLE system, used in the midi-*....
void midi_handle_disconnect_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)