Autodetection if NimBLE-Arduino v1 or v2 is used
I'm working on automatic BLE library detection in ArduinoBleOTA library https://github.com/vovagorodok/ArduinoBleOTA/blob/main/src/BleOtaDefines.h
#if __has_include("ArduinoBLE.h")
#include <ArduinoBLE.h>
#define BLE_OTA_BLE_LIB_ARDUINO_BLE
#define BLE_OTA_LIB_ARDUINO_BLE
#elif __has_include("NimBLEDevice.h")
#include <NimBLEDevice.h>
#define BLE_OTA_BLE_LIB_NIM_BLE_ARDUINO
#define BLE_OTA_LIB_NIM_BLE_ARDUINO
#elif defined(ARDUINO_ARCH_ESP32)
#include <BLEDevice.h>
#define BLE_OTA_BLE_LIB_ESP32
#define BLE_OTA_LIB_ESP32
#else
#error "Unsupported BLE library. Consider ArduinoBLE or NimBLE-Arduino."
#endif
What is the best way to detect if NimBLE-Arduino v1 or v2 is used? Here is some macro that define library version? Or some files that are not in v1 and are in v2 (and will be available all the time)?
Sorry for adding it here, maybe better place is Discussion session
You could probably use #ifdef CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED as that was added in 2.x
Maybe will be nice to add something like
#define NIMBLE_VERSION_MAJOR 2
#define NIMBLE_VERSION_MINOR 3
#define NIMBLE_VERSION_PATCH 6
#define NIMBLE_VERSION (NIMBLE_VERSION_MAJOR * 10000 + NIMBLE_VERSION_MINOR * 100 + NIMBLE_VERSION_PATCH)
#if NIMBLE_VERSION >= 020306
// Use new feature introduced in 2.3.6
#endif
#if NIMBLE_VERSION_MAJOR == 2
// Use new feature introduced in 2.x
#endif
Or you don't like idea to maintain such macros?
Yes, I was contemplating this some time ago, just haven't implemented it yet
Added
#if !defined(CONFIG_NIMBLE_MAX_CONNECTIONS) && \
!defined(CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED)
#define BLE_OTA_BLE_LIB_NIM_BLE_ARDUINO_V1
#else
#define BLE_OTA_BLE_LIB_NIM_BLE_ARDUINO_V2
#endif
as temporary solution.
Notice that __has_include doesn't work correctly in ArduinoIDE. PlatformIO handles it better
Notice that __has_include doesn't work correctly in ArduinoIDE. PlatformIO handles it better
I did not know this, I see it is used in the core as well so I would expect it to work fine?
As I correctly understand in ArduinoIDE libraries are compiled without considering of full project/sketch. That's why was added exception (autodetection turned off) for it in https://github.com/vovagorodok/ArduinoBleOTA/blob/main/src/BleOtaDefines.h
#if !defined(PLATFORMIO) && !defined(BLE_OTA_BLE_LIB_PREDEFINED)
#include <ArduinoBLE.h>
#define BLE_OTA_BLE_LIB_ARDUINO_BLE
#define BLE_OTA_LIB_ARDUINO_BLE
#define BLE_OTA_BLE_LIB_PREDEFINED
#endif
In PlatformIO it looks like
https://community.platformio.org/t/automatic-ble-library-detection/52762