From 7ef247c8db065d760432a8281e24a6e83dfa5b69 Mon Sep 17 00:00:00 2001 From: h2zero Date: Tue, 25 Feb 2025 14:18:56 -0700 Subject: [PATCH] Partially revert Commit 052c0a04 to restore client connect with device parameter. --- src/NimBLEClient.cpp | 16 ++++++++++++++++ src/NimBLEClient.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/NimBLEClient.cpp b/src/NimBLEClient.cpp index ef3c85d..8ec2a64 100644 --- a/src/NimBLEClient.cpp +++ b/src/NimBLEClient.cpp @@ -126,6 +126,22 @@ size_t NimBLEClient::deleteService(const NimBLEUUID& uuid) { return m_svcVec.size(); } // deleteService +/** + * @brief Connect to an advertising device. + * @param [in] pDevice A pointer to the advertised device instance to connect to. + * @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n + * have created when last connected. + * @param [in] asyncConnect If true, the connection will be made asynchronously and this function will return immediately.\n + * If false, this function will block until the connection is established or the connection attempt times out. + * @param [in] exchangeMTU If true, the client will attempt to exchange MTU with the server after connection.\n + * If false, the client will use the default MTU size and the application will need to call exchangeMTU() later. + * @return true on success. + */ +bool NimBLEClient::connect(const NimBLEAdvertisedDevice* pDevice, bool deleteAttributes, bool asyncConnect, bool exchangeMTU) { + NimBLEAddress address(pDevice->getAddress()); + return connect(address, deleteAttributes, asyncConnect, exchangeMTU); +} // connect + /** * @brief Connect to the BLE Server using the address of the last connected device, or the address\n * passed to the constructor. diff --git a/src/NimBLEClient.h b/src/NimBLEClient.h index 0406346..79e51d9 100644 --- a/src/NimBLEClient.h +++ b/src/NimBLEClient.h @@ -48,6 +48,10 @@ struct NimBLETaskData; */ class NimBLEClient { public: + bool connect(const NimBLEAdvertisedDevice* device, + bool deleteAttributes = true, + bool asyncConnect = false, + bool exchangeMTU = true); bool connect(const NimBLEAddress& address, bool deleteAttributes = true, bool asyncConnect = false, bool exchangeMTU = true); bool connect(bool deleteAttributes = true, bool asyncConnect = false, bool exchangeMTU = true); bool disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);