Skip to content

Commit 39c1647

Browse files
authored
Increased readability in onResult
Improved IF-syntaxis
1 parent 53e0139 commit 39c1647

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/hardware/BLEMIDI_Client_ESP32.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -196,32 +196,34 @@ class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
196196
protected:
197197
void onResult(NimBLEAdvertisedDevice *advertisedDevice)
198198
{
199-
if (enableConnection) //not begin() or end()
199+
if (!enableConnection) // not begin() or end()
200200
{
201-
DEBUGCLIENT("Advertised Device found: ");
202-
DEBUGCLIENT(advertisedDevice->toString().c_str());
203-
if (advertisedDevice->isAdvertisingService(NimBLEUUID(SERVICE_UUID)))
204-
{
205-
DEBUGCLIENT("Found MIDI Service");
206-
if (!specificTarget || (advertisedDevice->getName() == nameTarget.c_str() || advertisedDevice->getAddress() == nameTarget))
207-
{
208-
/** Ready to connect now */
209-
doConnect = true;
210-
/** Save the device reference in a public variable that the client can use*/
211-
advDevice = *advertisedDevice;
212-
/** stop scan before connecting */
213-
NimBLEDevice::getScan()->stop();
214-
}
215-
else
216-
{
217-
DEBUGCLIENT("Name error");
218-
}
219-
}
220-
else
221-
{
222-
doConnect = false;
223-
}
201+
return;
202+
}
203+
204+
DEBUGCLIENT("Advertised Device found: ");
205+
DEBUGCLIENT(advertisedDevice->toString().c_str());
206+
if (!advertisedDevice->isAdvertisingService(NimBLEUUID(SERVICE_UUID)))
207+
{
208+
doConnect = false;
209+
return;
210+
}
211+
212+
DEBUGCLIENT("Found MIDI Service");
213+
if (!(!specificTarget || (advertisedDevice->getName() == nameTarget.c_str() || advertisedDevice->getAddress() == nameTarget)))
214+
{
215+
DEBUGCLIENT("Name error");
216+
return;
224217
}
218+
219+
/** Ready to connect now */
220+
doConnect = true;
221+
/** Save the device reference in a public variable that the client can use*/
222+
advDevice = *advertisedDevice;
223+
/** stop scan before connecting */
224+
NimBLEDevice::getScan()->stop();
225+
226+
return;
225227
};
226228
};
227229

0 commit comments

Comments
 (0)