Skip to content

Commit dad42b4

Browse files
RobertoRoberto
authored andcommitted
Force New Connection
Add functionalities for #40 issue.
1 parent 5c42e14 commit dad42b4

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/hardware/BLEMIDI_Client_ESP32.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static uint32_t userOnPassKeyRequest()
9696
return passkey;
9797
};
9898

99-
/*
99+
/*
100100
###### BLE COMMUNICATION PARAMS ######
101101
*/
102102
/** Set connection parameters:
@@ -117,6 +117,23 @@ static uint32_t userOnPassKeyRequest()
117117
#define BLEMIDI_CLIENT_COMM_LATENCY 0 //
118118
#define BLEMIDI_CLIENT_COMM_TIMEOUT 200 //2000ms
119119

120+
/*
121+
###### BLE FORCE NEW CONNECTION ######
122+
*/
123+
124+
/**
125+
* This parameter force to skip the "soft-reconnection" and force to create a new connection after a disconnect event.
126+
* "Soft-reconnection" save some time and energy in comparation with performming a new connection, but some BLE devices
127+
* don't support or don't perform correctly a "soft-reconnection" after a disconnection event.
128+
* Uncomment this define if your device doesn't work propertily after a reconnection.
129+
*
130+
*/
131+
#define BLEMIDI_FORCE_NEW_CONNECTION
132+
133+
/**
134+
*
135+
*/
136+
120137
/*
121138
#############################################
122139
############ USER DEFINES END ###############
@@ -340,6 +357,13 @@ class MyClientCallbacks : public BLEClientCallbacks
340357
_bluetoothEsp32->disconnected();
341358
}
342359

360+
#ifdef BLEMIDI_FORCE_NEW_CONNECTION
361+
// Renew Client
362+
NimBLEDevice::deleteClient(pClient);
363+
//NimBLEDevice::createClient();
364+
pClient = nullptr;
365+
#endif // BLEMIDI_FORCE_NEW_CONNECTION
366+
343367
//Try reconnection or search a new one
344368
NimBLEDevice::getScan()->start(1, scanEndedCB);
345369
}
@@ -481,6 +505,7 @@ bool BLEMIDI_Client_ESP32::connect()
481505
{
482506
using namespace std::placeholders; //<- for bind funtion in callback notification
483507

508+
#ifndef BLEMIDI_FORCE_NEW_CONNECTION
484509
/** Check if we have a client we should reuse first
485510
* Special case when we already know this device
486511
* This saves considerable time and power.
@@ -512,6 +537,7 @@ bool BLEMIDI_Client_ESP32::connect()
512537
NimBLEDevice::deleteClient(_client);
513538
_client = nullptr;
514539
}
540+
#endif //BLEMIDI_FORCE_NEW_CONNECTION
515541

516542
if (NimBLEDevice::getClientListSize() >= NIMBLE_MAX_CONNECTIONS)
517543
{

0 commit comments

Comments
 (0)