1
1
#pragma once
2
2
3
+ // #define MIDIBLECLIENTVERBOSE
4
+
5
+ #ifdef MIDIBLECLIENTVERBOSE
6
+ #define DEBUGCLIENT (_text_ ) Serial.println(" DbgBC: " + (String)_text_);
7
+ #else
8
+ #define DEBUGCLIENT (_text_ ) ;
9
+ #endif
10
+
11
+
3
12
/*
4
13
#############################################
5
14
########## USER DEFINES BEGINNING ###########
@@ -189,11 +198,11 @@ class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
189
198
{
190
199
if (enableConnection) // not begin() or end()
191
200
{
192
- Serial. print (" Advertised Device found: " );
193
- Serial. println (advertisedDevice->toString ().c_str ());
201
+ DEBUGCLIENT (" Advertised Device found: " );
202
+ DEBUGCLIENT (advertisedDevice->toString ().c_str ());
194
203
if (advertisedDevice->isAdvertisingService (NimBLEUUID (SERVICE_UUID)))
195
204
{
196
- Serial. println (" Found MIDI Service" );
205
+ DEBUGCLIENT (" Found MIDI Service" );
197
206
if (!specificTarget || (advertisedDevice->getName () == nameTarget.c_str () || advertisedDevice->getAddress () == nameTarget))
198
207
{
199
208
/* * Ready to connect now */
@@ -205,7 +214,7 @@ class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
205
214
}
206
215
else
207
216
{
208
- Serial. println (" Name error" );
217
+ DEBUGCLIENT (" Name error" );
209
218
}
210
219
}
211
220
else
@@ -332,7 +341,7 @@ class MyClientCallbacks : public BLEClientCallbacks
332
341
333
342
void onConnect (BLEClient*)
334
343
{
335
- // Serial.println ("##Connected##");
344
+ DEBUGCLIENT (" ##Connected##" );
336
345
// pClient->updateConnParams(BLEMIDI_CLIENT_COMM_MIN_INTERVAL, BLEMIDI_CLIENT_COMM_MAX_INTERVAL, BLEMIDI_CLIENT_COMM_LATENCY, BLEMIDI_CLIENT_COMM_TIMEOUT);
337
346
vTaskDelay (1 );
338
347
if (_bluetoothEsp32)
@@ -341,8 +350,8 @@ class MyClientCallbacks : public BLEClientCallbacks
341
350
342
351
void onDisconnect (BLEClient*)
343
352
{
344
- // Serial.print (pClient->getPeerAddress().toString().c_str());
345
- // Serial.println (" Disconnected - Starting scan");
353
+ DEBUGCLIENT (pClient->getPeerAddress ().toString ().c_str ());
354
+ DEBUGCLIENT (" Disconnected - Starting scan" );
346
355
347
356
if (_bluetoothEsp32)
348
357
{
@@ -422,7 +431,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::begin(const char *deviceName, BLEMIDI_Tran
422
431
strDeviceName = BLEMIDI_CLIENT_NAME_PREFIX + strDeviceName + BLEMIDI_CLIENT_NAME_SUBFIX;
423
432
#endif
424
433
}
425
- Serial. println (strDeviceName.c_str ());
434
+ DEBUGCLIENT (strDeviceName.c_str ());
426
435
427
436
NimBLEDevice::init (strDeviceName);
428
437
@@ -496,7 +505,7 @@ void BLEMIDI_Client_ESP32<_Settings>::scan()
496
505
pBLEScan->setWindow (500 );
497
506
pBLEScan->setActiveScan (true );
498
507
499
- Serial. println (" Scanning..." );
508
+ DEBUGCLIENT (" Scanning..." );
500
509
pBLEScan->start (1 , scanEndedCB);
501
510
}
502
511
};
@@ -542,7 +551,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
542
551
543
552
if (NimBLEDevice::getClientListSize () >= NIMBLE_MAX_CONNECTIONS)
544
553
{
545
- Serial. println (" Max clients reached - no more connections available" );
554
+ DEBUGCLIENT (" Max clients reached - no more connections available" );
546
555
return false ;
547
556
}
548
557
@@ -561,29 +570,24 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
561
570
/* * Created a client but failed to connect, don't need to keep it as it has no data */
562
571
NimBLEDevice::deleteClient (_client);
563
572
_client = nullptr ;
564
- // Serial.println ("Failed to connect, deleted client");
573
+ DEBUGCLIENT (" Failed to connect, deleted client" );
565
574
return false ;
566
575
}
567
576
568
577
if (!_client->isConnected ())
569
578
{
570
- // Serial.println ("Failed to connect");
579
+ DEBUGCLIENT (" Failed to connect" );
571
580
_client->disconnect ();
572
581
NimBLEDevice::deleteClient (_client);
573
582
_client = nullptr ;
574
583
return false ;
575
584
}
576
585
577
- Serial.print (" Connected to: " );
578
- Serial.print (myAdvCB.advDevice .getName ().c_str ());
579
- Serial.print (" / " );
580
- Serial.println (_client->getPeerAddress ().toString ().c_str ());
581
-
582
- /*
583
- Serial.print("RSSI: ");
584
- Serial.println(_client->getRssi());
585
- */
586
+ DEBUGCLIENT (" Connected to: " + myAdvCB.advDevice .getName ().c_str () + " / " + _client->getPeerAddress ().toString ().c_str ());
586
587
588
+ DEBUGCLIENT (" RSSI: " );
589
+ DEBUGCLIENT (_client->getRssi ());
590
+
587
591
/* * Now we can read/write/subscribe the charateristics of the services we are interested in */
588
592
pSvc = _client->getService (SERVICE_UUID);
589
593
if (pSvc) /* * make sure it's not null */
@@ -613,7 +617,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
613
617
/* * Callback to process the results of the last scan or restart it */
614
618
void scanEndedCB (NimBLEScanResults results)
615
619
{
616
- // Serial.println ("Scan Ended");
620
+ DEBUGCLIENT (" Scan Ended" );
617
621
}
618
622
619
623
END_BLEMIDI_NAMESPACE
0 commit comments