diff --git a/libraries/BLE/src/BLEAdvertising.cpp b/libraries/BLE/src/BLEAdvertising.cpp index 0c105cfb8d3..b3e4d9cde97 100644 --- a/libraries/BLE/src/BLEAdvertising.cpp +++ b/libraries/BLE/src/BLEAdvertising.cpp @@ -79,6 +79,41 @@ void BLEAdvertising::addServiceUUID(const char* serviceUUID) { } // addServiceUUID +/** + * @brief Remove a service uuid to exposed list of services. + * @param [in] index The index of the service to stop exposing. + */ +bool BLEAdvertising::removeServiceUUID(int index) { + + // If index is larger than the size of the + // advertised services, return false + if(index > m_serviceUUIDs.size()) return false; + + m_serviceUUIDs.erase(m_serviceUUIDs.begin() + i); + return true; +} + +/** + * @brief Remove a service uuid to exposed list of services. + * @param [in] serviceUUID The BLEUUID of the service to stop exposing. + */ +bool BLEAdvertising::removeServiceUUID(BLEUUID serviceUUID) { + for(int i = 0; i < m_serviceUUIDs.size(); i++) { + if(m_serviceUUIDs.at(i).equals(serviceUUID)) { + return removeServiceUUID(i); + } + } + return false; +} + +/** + * @brief Remove a service uuid to exposed list of services. + * @param [in] serviceUUID The string of the service to stop exposing. + */ +bool BLEAdvertising::removeServiceUUID(const char* serviceUUID) { + return removeServiceUUID(BLEUUID(serviceUUID)); +} + /** * @brief Set the device appearance in the advertising data. * The appearance attribute is of type 0x19. The codes for distinct appearances can be found here: diff --git a/libraries/BLE/src/BLEAdvertising.h b/libraries/BLE/src/BLEAdvertising.h index 775400f557b..b10c0228698 100644 --- a/libraries/BLE/src/BLEAdvertising.h +++ b/libraries/BLE/src/BLEAdvertising.h @@ -51,7 +51,10 @@ class BLEAdvertising { public: BLEAdvertising(); void addServiceUUID(BLEUUID serviceUUID); - void addServiceUUID(const char* serviceUUID); + void addServiceUUID(const char* serviceUUID); + bool removeServiceUUID(int index); + bool removeServiceUUID(BLEUUID serviceUUID); + bool removeServiceUUID(const char* serviceUUID); void start(); void stop(); void setAppearance(uint16_t appearance);