From 39c16474b30b6dd88d106ee326be0d0fe2867f73 Mon Sep 17 00:00:00 2001 From: RobertoHE Date: Tue, 21 Jun 2022 18:53:46 +0200 Subject: [PATCH] Increased readability in onResult Improved IF-syntaxis --- src/hardware/BLEMIDI_Client_ESP32.h | 50 +++++++++++++++-------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/hardware/BLEMIDI_Client_ESP32.h b/src/hardware/BLEMIDI_Client_ESP32.h index 33e7fdb..a92d9f8 100644 --- a/src/hardware/BLEMIDI_Client_ESP32.h +++ b/src/hardware/BLEMIDI_Client_ESP32.h @@ -196,32 +196,34 @@ public: protected: void onResult(NimBLEAdvertisedDevice *advertisedDevice) { - if (enableConnection) //not begin() or end() + if (!enableConnection) // not begin() or end() { - DEBUGCLIENT("Advertised Device found: "); - DEBUGCLIENT(advertisedDevice->toString().c_str()); - if (advertisedDevice->isAdvertisingService(NimBLEUUID(SERVICE_UUID))) - { - DEBUGCLIENT("Found MIDI Service"); - if (!specificTarget || (advertisedDevice->getName() == nameTarget.c_str() || advertisedDevice->getAddress() == nameTarget)) - { - /** Ready to connect now */ - doConnect = true; - /** Save the device reference in a public variable that the client can use*/ - advDevice = *advertisedDevice; - /** stop scan before connecting */ - NimBLEDevice::getScan()->stop(); - } - else - { - DEBUGCLIENT("Name error"); - } - } - else - { - doConnect = false; - } + return; } + + DEBUGCLIENT("Advertised Device found: "); + DEBUGCLIENT(advertisedDevice->toString().c_str()); + if (!advertisedDevice->isAdvertisingService(NimBLEUUID(SERVICE_UUID))) + { + doConnect = false; + return; + } + + DEBUGCLIENT("Found MIDI Service"); + if (!(!specificTarget || (advertisedDevice->getName() == nameTarget.c_str() || advertisedDevice->getAddress() == nameTarget))) + { + DEBUGCLIENT("Name error"); + return; + } + + /** Ready to connect now */ + doConnect = true; + /** Save the device reference in a public variable that the client can use*/ + advDevice = *advertisedDevice; + /** stop scan before connecting */ + NimBLEDevice::getScan()->stop(); + + return; }; };