Skip to content

Commit 81462be

Browse files
authored
Add Notification and Response parameters to Config
Added after Nimble Lib update. end() updated.
1 parent 24f4add commit 81462be

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/hardware/BLEMIDI_Client_ESP32.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
4040
*/
4141
static constexpr char *name = "BleMidiClient";
4242

43-
4443
/*
4544
###### TX POWER #####
4645
*/
@@ -59,7 +58,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
5958
*/
6059
static const esp_power_level_t clientTXPwr = ESP_PWR_LVL_P9;
6160

62-
6361
/*
6462
###### SECURITY #####
6563
*/
@@ -88,7 +86,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
8886
*/
8987
static constexpr PasskeyRequestCallback userOnPassKeyRequest = defautlPasskeyRequest;
9088

91-
9289
/*
9390
###### BLE COMMUNICATION PARAMS ######
9491
*/
@@ -111,7 +108,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
111108
static const uint16_t commLatency = 0; //
112109
static const uint16_t commTimeOut = 200; // 2000ms
113110

114-
115111
/*
116112
###### BLE FORCE NEW CONNECTION ######
117113
*/
@@ -124,6 +120,21 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
124120
*
125121
*/
126122
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;
127138
};
128139

129140
/** Define a class to handle the callbacks when advertisments are received */
@@ -206,9 +217,11 @@ class BLEMIDI_Client_ESP32
206217
myAdvCB.enableConnection = false;
207218
xQueueReset(mRxQueue);
208219
_client->disconnect();
209-
_client = nullptr;
220+
bool success = !_client->isConnected();
221+
if (success)
222+
_client = nullptr;
210223

211-
return !_client->isConnected();
224+
return success;
212225
}
213226

214227
void write(uint8_t *data, uint8_t length)
@@ -397,7 +410,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::available(byte *pvBuffer)
397410
}
398411

399412
// Try to connect/reconnect
400-
if (_client == nullptr || !_client->isConnected())
413+
if (_client == nullptr || !_client->isConnected())
401414
{
402415
if (myAdvCB.doConnect)
403416
{
@@ -468,7 +481,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
468481
{
469482
if (_characteristic->canNotify())
470483
{
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))
472485
{
473486
// Re-connection SUCCESS
474487
return true;
@@ -537,7 +550,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
537550
{
538551
if (_characteristic->canNotify())
539552
{
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))
541554
{
542555
// Connection SUCCESS
543556
return true;

0 commit comments

Comments
 (0)