From a2f4a6e72b9320b0693d44e46562fbe3db093a01 Mon Sep 17 00:00:00 2001 From: h2zero Date: Wed, 25 Mar 2026 13:19:14 -0600 Subject: [PATCH] [Bugfix] Arduino detection for headers. --- src/NimBLEAttValue.h | 24 +++++++++++++----------- src/NimBLEStream.h | 4 ++++ src/nimconfig.h | 7 ------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/NimBLEAttValue.h b/src/NimBLEAttValue.h index bddf020e4..266095c8e 100644 --- a/src/NimBLEAttValue.h +++ b/src/NimBLEAttValue.h @@ -21,8 +21,13 @@ #include "syscfg/syscfg.h" #if CONFIG_BT_NIMBLE_ENABLED -# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE -# include +/* Enables the use of Arduino String class for attribute values */ +# ifndef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE +# define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (__has_include()) +# endif + +# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE +# include # endif # include @@ -78,8 +83,7 @@ template struct Has_value_type : std::false_type {}; template -struct Has_value_type - : std::true_type {}; +struct Has_value_type : std::true_type {}; /** * @brief A specialized container class to hold BLE attribute values. @@ -103,7 +107,8 @@ class NimBLEAttValue { * @param[in] init_len The initial size in bytes. * @param[in] max_len The max size in bytes that the value can be. */ - NimBLEAttValue(uint16_t init_len = MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH), uint16_t max_len = BLE_ATT_ATTR_MAX_LEN); + NimBLEAttValue(uint16_t init_len = MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH), + uint16_t max_len = BLE_ATT_ATTR_MAX_LEN); /** * @brief Construct with an initial value from a buffer. @@ -145,7 +150,7 @@ class NimBLEAttValue { NimBLEAttValue(const std::vector vec, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN) : NimBLEAttValue(&vec[0], vec.size(), max_len) {} -# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE +# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE /** * @brief Construct with an initial value from an Arduino String. * @param str An Arduino String containing to the initial value to set. @@ -292,10 +297,7 @@ class NimBLEAttValue { typename std::enable_if::value && Has_value_type::value, bool>::type # endif setValue(const T& v) { - return setValue( - reinterpret_cast(v.data()), - v.size() * sizeof(typename T::value_type) - ); + return setValue(reinterpret_cast(v.data()), v.size() * sizeof(typename T::value_type)); } /** @@ -398,7 +400,7 @@ class NimBLEAttValue { /** @brief Inequality operator */ bool operator!=(const NimBLEAttValue& source) const { return !(*this == source); } -# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE +# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE /** @brief Operator; Get the value as an Arduino String value. */ operator String() const { return String(reinterpret_cast(m_attr_value)); } # endif diff --git a/src/NimBLEStream.h b/src/NimBLEStream.h index 6328b7c47..28d3d467f 100644 --- a/src/NimBLEStream.h +++ b/src/NimBLEStream.h @@ -31,6 +31,10 @@ # include # include +# ifndef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE +# define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (__has_include()) +# endif + # if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE # include # else diff --git a/src/nimconfig.h b/src/nimconfig.h index 0dcc9a0c7..40ed0e646 100644 --- a/src/nimconfig.h +++ b/src/nimconfig.h @@ -215,13 +215,6 @@ # define CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE (1) #endif // ESP_PLATFORM -/* Enables the use of Arduino String class for attribute values */ -#if defined __has_include -# if __has_include() -# define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (1) -# endif -#endif - /* Required macros for all supported devices */ #ifndef CONFIG_BT_NIMBLE_ENABLED