@@ -40,7 +40,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
40
40
*/
41
41
static constexpr char *name = " BleMidiClient" ;
42
42
43
-
44
43
/*
45
44
###### TX POWER #####
46
45
*/
@@ -59,7 +58,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
59
58
*/
60
59
static const esp_power_level_t clientTXPwr = ESP_PWR_LVL_P9;
61
60
62
-
63
61
/*
64
62
###### SECURITY #####
65
63
*/
@@ -88,7 +86,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
88
86
*/
89
87
static constexpr PasskeyRequestCallback userOnPassKeyRequest = defautlPasskeyRequest;
90
88
91
-
92
89
/*
93
90
###### BLE COMMUNICATION PARAMS ######
94
91
*/
@@ -111,7 +108,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
111
108
static const uint16_t commLatency = 0 ; //
112
109
static const uint16_t commTimeOut = 200 ; // 2000ms
113
110
114
-
115
111
/*
116
112
###### BLE FORCE NEW CONNECTION ######
117
113
*/
@@ -124,6 +120,21 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
124
120
*
125
121
*/
126
122
static const bool forceNewConnection = false ;
123
+
124
+ /*
125
+ ###### BLE SUBSCRIPTION: NOTIFICATION & RESPONSE ######
126
+ */
127
+
128
+ /* *
129
+ * Subscribe in Notification Mode [true] or Indication Mode [false]
130
+ * Don't modify this parameter except is completely necessary.
131
+ */
132
+ static const bool notification = true ;
133
+ /* *
134
+ * Respond to after a notification message.
135
+ * Don't modify this parameter except is completely necessary.
136
+ */
137
+ static const bool response = true ;
127
138
};
128
139
129
140
/* * Define a class to handle the callbacks when advertisments are received */
@@ -206,9 +217,11 @@ class BLEMIDI_Client_ESP32
206
217
myAdvCB.enableConnection = false ;
207
218
xQueueReset (mRxQueue );
208
219
_client->disconnect ();
209
- _client = nullptr ;
220
+ bool success = !_client->isConnected ();
221
+ if (success)
222
+ _client = nullptr ;
210
223
211
- return !_client-> isConnected () ;
224
+ return success ;
212
225
}
213
226
214
227
void write (uint8_t *data, uint8_t length)
@@ -397,7 +410,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::available(byte *pvBuffer)
397
410
}
398
411
399
412
// Try to connect/reconnect
400
- if (_client == nullptr || !_client->isConnected ())
413
+ if (_client == nullptr || !_client->isConnected ())
401
414
{
402
415
if (myAdvCB.doConnect )
403
416
{
@@ -468,7 +481,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
468
481
{
469
482
if (_characteristic->canNotify ())
470
483
{
471
- if (_characteristic->subscribe (true , std::bind (&BLEMIDI_Client_ESP32::notifyCB, this , _1, _2, _3, _4)))
484
+ if (_characteristic->subscribe (_Settings::notification , std::bind (&BLEMIDI_Client_ESP32::notifyCB, this , _1, _2, _3, _4), _Settings::response ))
472
485
{
473
486
// Re-connection SUCCESS
474
487
return true ;
@@ -537,7 +550,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
537
550
{
538
551
if (_characteristic->canNotify ())
539
552
{
540
- if (_characteristic->subscribe (true , std::bind (&BLEMIDI_Client_ESP32::notifyCB, this , _1, _2, _3, _4)))
553
+ if (_characteristic->subscribe (_Settings::notification , std::bind (&BLEMIDI_Client_ESP32::notifyCB, this , _1, _2, _3, _4), _Settings::response ))
541
554
{
542
555
// Connection SUCCESS
543
556
return true ;
0 commit comments