Skip to content

Commit c013189

Browse files
committed
[Bugfix] Arduino detection for headers.
1 parent 0dce7fb commit c013189

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

src/NimBLEAttValue.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
#include "syscfg/syscfg.h"
2222
#if CONFIG_BT_NIMBLE_ENABLED
2323

24-
# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
25-
# include <Arduino.h>
24+
/* Enables the use of Arduino String class for attribute values */
25+
# ifndef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
26+
# define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (__has_include(<Arduino.h>))
27+
# endif
28+
29+
# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
30+
# include <WString.h>
2631
# endif
2732

2833
# include <string>
@@ -78,8 +83,7 @@ template <typename T, typename = void>
7883
struct Has_value_type : std::false_type {};
7984

8085
template <typename T>
81-
struct Has_value_type<T, decltype(void(sizeof(typename T::value_type)))>
82-
: std::true_type {};
86+
struct Has_value_type<T, decltype(void(sizeof(typename T::value_type)))> : std::true_type {};
8387

8488
/**
8589
* @brief A specialized container class to hold BLE attribute values.
@@ -103,7 +107,8 @@ class NimBLEAttValue {
103107
* @param[in] init_len The initial size in bytes.
104108
* @param[in] max_len The max size in bytes that the value can be.
105109
*/
106-
NimBLEAttValue(uint16_t init_len = MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH), uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
110+
NimBLEAttValue(uint16_t init_len = MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH),
111+
uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
107112

108113
/**
109114
* @brief Construct with an initial value from a buffer.
@@ -145,7 +150,7 @@ class NimBLEAttValue {
145150
NimBLEAttValue(const std::vector<uint8_t> vec, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
146151
: NimBLEAttValue(&vec[0], vec.size(), max_len) {}
147152

148-
# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
153+
# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
149154
/**
150155
* @brief Construct with an initial value from an Arduino String.
151156
* @param str An Arduino String containing to the initial value to set.
@@ -292,10 +297,7 @@ class NimBLEAttValue {
292297
typename std::enable_if<Has_data_size<T>::value && Has_value_type<T>::value, bool>::type
293298
# endif
294299
setValue(const T& v) {
295-
return setValue(
296-
reinterpret_cast<const uint8_t*>(v.data()),
297-
v.size() * sizeof(typename T::value_type)
298-
);
300+
return setValue(reinterpret_cast<const uint8_t*>(v.data()), v.size() * sizeof(typename T::value_type));
299301
}
300302

301303
/**
@@ -398,7 +400,7 @@ class NimBLEAttValue {
398400
/** @brief Inequality operator */
399401
bool operator!=(const NimBLEAttValue& source) const { return !(*this == source); }
400402

401-
# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
403+
# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
402404
/** @brief Operator; Get the value as an Arduino String value. */
403405
operator String() const { return String(reinterpret_cast<char*>(m_attr_value)); }
404406
# endif

src/NimBLEStream.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
# include <type_traits>
3232
# include <cstdarg>
3333

34+
# ifndef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
35+
# define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (__has_include(<Arduino.h>))
36+
# endif
37+
3438
# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
3539
# include <Stream.h>
3640
# else

src/nimconfig.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,6 @@
215215
# define CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE (1)
216216
#endif // ESP_PLATFORM
217217

218-
/* Enables the use of Arduino String class for attribute values */
219-
#if defined __has_include
220-
# if __has_include(<Arduino.h>)
221-
# define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (1)
222-
# endif
223-
#endif
224-
225218
/* Required macros for all supported devices */
226219

227220
#ifndef CONFIG_BT_NIMBLE_ENABLED

0 commit comments

Comments
 (0)