Skip to content

Commit 53e0139

Browse files
authored
Debug Verbose
Serial.print changed by debugging verbose. It may be abled using #define MIDIBLECLIENTVERBOSE
1 parent 3fc460e commit 53e0139

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/hardware/BLEMIDI_Client_ESP32.h

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#pragma once
22

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+
312
/*
413
#############################################
514
########## USER DEFINES BEGINNING ###########
@@ -189,11 +198,11 @@ class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
189198
{
190199
if (enableConnection) //not begin() or end()
191200
{
192-
Serial.print("Advertised Device found: ");
193-
Serial.println(advertisedDevice->toString().c_str());
201+
DEBUGCLIENT("Advertised Device found: ");
202+
DEBUGCLIENT(advertisedDevice->toString().c_str());
194203
if (advertisedDevice->isAdvertisingService(NimBLEUUID(SERVICE_UUID)))
195204
{
196-
Serial.println("Found MIDI Service");
205+
DEBUGCLIENT("Found MIDI Service");
197206
if (!specificTarget || (advertisedDevice->getName() == nameTarget.c_str() || advertisedDevice->getAddress() == nameTarget))
198207
{
199208
/** Ready to connect now */
@@ -205,7 +214,7 @@ class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
205214
}
206215
else
207216
{
208-
Serial.println("Name error");
217+
DEBUGCLIENT("Name error");
209218
}
210219
}
211220
else
@@ -332,7 +341,7 @@ class MyClientCallbacks : public BLEClientCallbacks
332341

333342
void onConnect(BLEClient*)
334343
{
335-
//Serial.println("##Connected##");
344+
DEBUGCLIENT("##Connected##");
336345
//pClient->updateConnParams(BLEMIDI_CLIENT_COMM_MIN_INTERVAL, BLEMIDI_CLIENT_COMM_MAX_INTERVAL, BLEMIDI_CLIENT_COMM_LATENCY, BLEMIDI_CLIENT_COMM_TIMEOUT);
337346
vTaskDelay(1);
338347
if (_bluetoothEsp32)
@@ -341,8 +350,8 @@ class MyClientCallbacks : public BLEClientCallbacks
341350

342351
void onDisconnect(BLEClient*)
343352
{
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");
346355

347356
if (_bluetoothEsp32)
348357
{
@@ -422,7 +431,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::begin(const char *deviceName, BLEMIDI_Tran
422431
strDeviceName = BLEMIDI_CLIENT_NAME_PREFIX + strDeviceName + BLEMIDI_CLIENT_NAME_SUBFIX;
423432
#endif
424433
}
425-
Serial.println(strDeviceName.c_str());
434+
DEBUGCLIENT(strDeviceName.c_str());
426435

427436
NimBLEDevice::init(strDeviceName);
428437

@@ -496,7 +505,7 @@ void BLEMIDI_Client_ESP32<_Settings>::scan()
496505
pBLEScan->setWindow(500);
497506
pBLEScan->setActiveScan(true);
498507

499-
Serial.println("Scanning...");
508+
DEBUGCLIENT("Scanning...");
500509
pBLEScan->start(1, scanEndedCB);
501510
}
502511
};
@@ -542,7 +551,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
542551

543552
if (NimBLEDevice::getClientListSize() >= NIMBLE_MAX_CONNECTIONS)
544553
{
545-
Serial.println("Max clients reached - no more connections available");
554+
DEBUGCLIENT("Max clients reached - no more connections available");
546555
return false;
547556
}
548557

@@ -561,29 +570,24 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
561570
/** Created a client but failed to connect, don't need to keep it as it has no data */
562571
NimBLEDevice::deleteClient(_client);
563572
_client = nullptr;
564-
//Serial.println("Failed to connect, deleted client");
573+
DEBUGCLIENT("Failed to connect, deleted client");
565574
return false;
566575
}
567576

568577
if (!_client->isConnected())
569578
{
570-
//Serial.println("Failed to connect");
579+
DEBUGCLIENT("Failed to connect");
571580
_client->disconnect();
572581
NimBLEDevice::deleteClient(_client);
573582
_client = nullptr;
574583
return false;
575584
}
576585

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());
586587

588+
DEBUGCLIENT("RSSI: ");
589+
DEBUGCLIENT(_client->getRssi());
590+
587591
/** Now we can read/write/subscribe the charateristics of the services we are interested in */
588592
pSvc = _client->getService(SERVICE_UUID);
589593
if (pSvc) /** make sure it's not null */
@@ -613,7 +617,7 @@ bool BLEMIDI_Client_ESP32<_Settings>::connect()
613617
/** Callback to process the results of the last scan or restart it */
614618
void scanEndedCB(NimBLEScanResults results)
615619
{
616-
// Serial.println("Scan Ended");
620+
DEBUGCLIENT("Scan Ended");
617621
}
618622

619623
END_BLEMIDI_NAMESPACE

0 commit comments

Comments
 (0)