Skip to content

Commit fe3412b

Browse files
authored
Minor Syntax correction
Tabulation indentation fixed after last commit changes and other minor changes in comments
1 parent 24dce9a commit fe3412b

File tree

1 file changed

+53
-47
lines changed

1 file changed

+53
-47
lines changed

src/hardware/BLEMIDI_Client_ESP32.h

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
3333
/*
3434
##### BLE DEVICE NAME #####
3535
*/
36+
3637
/**
3738
* Set name of ble device (not affect to connection with server)
3839
* max 16 characters
3940
*/
40-
static constexpr char *name = "BleMidiClient";
41-
41+
static constexpr char *name = "BleMidiClient";
42+
43+
4244
/*
4345
###### TX POWER #####
4446
*/
47+
4548
/**
4649
* Set power transmision
4750
*
@@ -56,9 +59,11 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
5659
*/
5760
static const esp_power_level_t clientTXPwr = ESP_PWR_LVL_P9;
5861

62+
5963
/*
6064
###### SECURITY #####
6165
*/
66+
6267
/** Set the IO capabilities of the device, each option will trigger a different pairing method.
6368
* BLE_HS_IO_KEYBOARD_ONLY - Passkey pairing
6469
* BLE_HS_IO_DISPLAY_YESNO - Numeric comparison pairing
@@ -83,9 +88,11 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
8388
*/
8489
static constexpr PasskeyRequestCallback userOnPassKeyRequest = defautlPasskeyRequest;
8590

91+
8692
/*
8793
###### BLE COMMUNICATION PARAMS ######
8894
*/
95+
8996
/** Set connection parameters:
9097
* If you only use one connection, put recomended BLE server param communication
9198
* (you may scan it ussing "nRF Connect" app or other similar apps).
@@ -104,6 +111,7 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
104111
static const uint16_t commLatency = 0; //
105112
static const uint16_t commTimeOut = 200; // 2000ms
106113

114+
107115
/*
108116
###### BLE FORCE NEW CONNECTION ######
109117
*/
@@ -118,7 +126,6 @@ struct DefaultSettingsClient : public BLEMIDI_NAMESPACE::DefaultSettings
118126
static const bool forceNewConnection = false;
119127
};
120128

121-
122129
/** Define a class to handle the callbacks when advertisments are received */
123130
class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
124131
{
@@ -275,15 +282,15 @@ class MyClientCallbacks : public BLEClientCallbacks
275282

276283
uint32_t onPassKeyRequest()
277284
{
278-
//if (nullptr != _Settings::userOnPassKeyRequest)
279-
return _Settings::userOnPassKeyRequest();
280-
//return 0;
285+
// if (nullptr != _Settings::userOnPassKeyRequest)
286+
return _Settings::userOnPassKeyRequest();
287+
// return 0;
281288
};
282289

283290
void onConnect(BLEClient *pClient)
284291
{
285292
DEBUGCLIENT("##Connected##");
286-
//pClient->updateConnParams(_Settings::commMinInterval, _Settings::commMaxInterval, _Settings::commLatency, _Settings::commTimeOut);
293+
// pClient->updateConnParams(_Settings::commMinInterval, _Settings::commMaxInterval, _Settings::commLatency, _Settings::commTimeOut);
287294
vTaskDelay(1);
288295
if (_bluetoothEsp32)
289296
_bluetoothEsp32->connected();
@@ -299,18 +306,18 @@ class MyClientCallbacks : public BLEClientCallbacks
299306
_bluetoothEsp32->disconnected();
300307
}
301308

302-
if (_Settings::forceNewConnection)
303-
{
304-
// Renew Client
305-
NimBLEDevice::deleteClient(pClient);
306-
pClient = nullptr;
307-
}
309+
if (_Settings::forceNewConnection)
310+
{
311+
// Renew Client
312+
NimBLEDevice::deleteClient(pClient);
313+
pClient = nullptr;
314+
}
308315

309316
// Try reconnection or search a new one
310317
NimBLEDevice::getScan()->start(1, scanEndedCB);
311318
}
312319

313-
bool onConnParamsUpdateRequest(NimBLEClient *pClient, const ble_gap_upd_params *params)
320+
bool onConnParamsUpdateRequest(NimBLEClient *pClient, const ble_gap_upd_params *params)
314321
{
315322
if (params->itvl_min < _Settings::commMinInterval)
316323
{ /** 1.25ms units */
@@ -346,24 +353,23 @@ bool BLEMIDI_Client_ESP32<_Settings>::begin(const char *deviceName, BLEMIDI_Tran
346353
_bleMidiTransport = bleMidiTransport;
347354

348355
std::string strDeviceName(deviceName);
349-
if (strDeviceName == "") // Connect to the first midi server found
356+
// Connect to the first midi server found
357+
if (strDeviceName == "")
350358
{
351359
myAdvCB.specificTarget = false;
352360
myAdvCB.nameTarget = "";
353361
}
354-
else // Connect to a specific name or address
362+
// Connect to a specific name or address
363+
else
355364
{
356365
myAdvCB.specificTarget = true;
357366
myAdvCB.nameTarget = strDeviceName;
358367
}
359368

360-
static char array[16] = "patata";
361-
369+
static char array[16];
362370
memcpy(array, _Settings::name, 16);
363371
strDeviceName = array;
364-
365372
DEBUGCLIENT(strDeviceName.c_str());
366-
367373
NimBLEDevice::init(strDeviceName);
368374

369375
// To communicate between the 2 cores.
@@ -390,7 +396,8 @@ bool BLEMIDI_Client_ESP32<_Settings>::available(byte *pvBuffer)
390396
return false;
391397
}
392398

393-
if (_client == nullptr || !_client->isConnected()) // Try to connect/reconnect
399+
// Try to connect/reconnect
400+
if (_client == nullptr || !_client->isConnected())
394401
{
395402
if (myAdvCB.doConnect)
396403
{
@@ -445,42 +452,41 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
445452
{
446453
using namespace std::placeholders; //<- for bind funtion in callback notification
447454

448-
//Retry to connecto to last one
449-
if (!_Settings::forceNewConnection)
450-
{
451-
/** Check if we have a client we should reuse first
452-
* Special case when we already know this device
453-
* This saves considerable time and power.
454-
*/
455-
456-
if (_client)
455+
// Retry to connecto to last one
456+
if (!_Settings::forceNewConnection)
457457
{
458-
if (_client == NimBLEDevice::getClientByPeerAddress(myAdvCB.advDevice.getAddress()))
458+
/** Check if we have a client we should reuse first
459+
* Special case when we already know this device
460+
* This saves considerable time and power.
461+
*/
462+
463+
if (_client)
459464
{
460-
if (_client->connect(&myAdvCB.advDevice, false))
465+
if (_client == NimBLEDevice::getClientByPeerAddress(myAdvCB.advDevice.getAddress()))
461466
{
462-
if (_characteristic->canNotify())
467+
if (_client->connect(&myAdvCB.advDevice, false))
463468
{
464-
if (_characteristic->subscribe(true, std::bind(&BLEMIDI_Client_ESP32::notifyCB, this, _1, _2, _3, _4)))
469+
if (_characteristic->canNotify())
465470
{
466-
// Re-connection SUCCESS
467-
return true;
471+
if (_characteristic->subscribe(true, std::bind(&BLEMIDI_Client_ESP32::notifyCB, this, _1, _2, _3, _4)))
472+
{
473+
// Re-connection SUCCESS
474+
return true;
475+
}
468476
}
477+
/** Disconnect if subscribe failed */
478+
_client->disconnect();
469479
}
470-
/** Disconnect if subscribe failed */
471-
_client->disconnect();
480+
/* If any connection problem exits, delete previous client and try again in the next attemp as new client*/
481+
NimBLEDevice::deleteClient(_client);
482+
_client = nullptr;
483+
return false;
472484
}
473-
/* If any connection problem exits, delete previous client and try again in the next attemp as new client*/
485+
/*If client does not match, delete previous client and create a new one*/
474486
NimBLEDevice::deleteClient(_client);
475487
_client = nullptr;
476-
return false;
477488
}
478-
/*If client does not match, delete previous client and create a new one*/
479-
NimBLEDevice::deleteClient(_client);
480-
_client = nullptr;
481489
}
482-
}
483-
484490

485491
if (NimBLEDevice::getClientListSize() >= NIMBLE_MAX_CONNECTIONS)
486492
{
@@ -493,7 +499,7 @@ if (!_Settings::forceNewConnection)
493499

494500
_client->setClientCallbacks(new MyClientCallbacks<_Settings>(this), false);
495501

496-
_client->setConnectionParams(_Settings::commMinInterval,_Settings::commMaxInterval, _Settings::commLatency, _Settings::commTimeOut);
502+
_client->setConnectionParams(_Settings::commMinInterval, _Settings::commMaxInterval, _Settings::commLatency, _Settings::commTimeOut);
497503

498504
/** Set how long we are willing to wait for the connection to complete (seconds), default is 30. */
499505
_client->setConnectTimeout(15);
@@ -517,7 +523,7 @@ if (!_Settings::forceNewConnection)
517523
}
518524

519525
DEBUGCLIENT("Connected to: " + myAdvCB.advDevice.getName().c_str() + " / " + _client->getPeerAddress().toString().c_str());
520-
526+
521527
DEBUGCLIENT("RSSI: ");
522528
DEBUGCLIENT(_client->getRssi());
523529

0 commit comments

Comments
 (0)