Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/NimBLECppVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Comment thread
h2zero marked this conversation as resolved.
* Copyright 2020-2025 Ryan Powell <ryan@nable-embedded.io> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef NIMBLE_CPP_VERSION_H_
#define NIMBLE_CPP_VERSION_H_

/** @brief NimBLE-Arduino library major version number. */
#define NIMBLE_CPP_VERSION_MAJOR 2

/** @brief NimBLE-Arduino library minor version number. */
#define NIMBLE_CPP_VERSION_MINOR 3

/** @brief NimBLE-Arduino library patch version number. */
#define NIMBLE_CPP_VERSION_PATCH 9

/**
* @brief Macro to create a version number for comparison.
* @param major Major version number.
* @param minor Minor version number.
* @param patch Patch version number.
* @details Example usage:
* @code{.cpp}
* #if NIMBLE_CPP_VERSION >= NIMBLE_CPP_VERSION_VAL(2, 0, 0)
* // Using NimBLE-Arduino v2 or later
* #endif
* @endcode
*/
#define NIMBLE_CPP_VERSION_VAL(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))

/**
* @brief The NimBLE-Arduino library version as a single integer for compile-time comparison.
* @details Format: (major << 16) | (minor << 8) | patch
*/
#define NIMBLE_CPP_VERSION \
NIMBLE_CPP_VERSION_VAL(NIMBLE_CPP_VERSION_MAJOR, NIMBLE_CPP_VERSION_MINOR, NIMBLE_CPP_VERSION_PATCH)

/** @cond NIMBLE_CPP_INTERNAL */
#define NIMBLE_CPP_VERSION_STRINGIFY_IMPL(x) #x
#define NIMBLE_CPP_VERSION_STRINGIFY(x) NIMBLE_CPP_VERSION_STRINGIFY_IMPL(x)
/** @endcond */

/** @brief NimBLE-Arduino library version as a string. */
#define NIMBLE_CPP_VERSION_STR \
NIMBLE_CPP_VERSION_STRINGIFY(NIMBLE_CPP_VERSION_MAJOR) "." \
NIMBLE_CPP_VERSION_STRINGIFY(NIMBLE_CPP_VERSION_MINOR) "." \
NIMBLE_CPP_VERSION_STRINGIFY(NIMBLE_CPP_VERSION_PATCH)

#endif // NIMBLE_CPP_VERSION_H_
8 changes: 8 additions & 0 deletions src/NimBLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,14 @@ std::string NimBLEDevice::toString() {
return getAddress().toString();
} // toString

/**
* @brief Return the library version as a string.
* @return A const char* containing the version string in the format "major.minor.patch".
*/
const char* NimBLEDevice::getVersion() {
return NIMBLE_CPP_VERSION_STR;
} // getVersion

# if MYNEWT_VAL(NIMBLE_CPP_DEBUG_ASSERT_ENABLED) || __DOXYGEN__
/**
* @brief Debug assert - weak function.
Expand Down
2 changes: 2 additions & 0 deletions src/NimBLEDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef NIMBLE_CPP_DEVICE_H_
#define NIMBLE_CPP_DEVICE_H_

#include "NimBLECppVersion.h"
#include "syscfg/syscfg.h"
#if CONFIG_BT_NIMBLE_ENABLED
# ifdef ESP_PLATFORM
Expand Down Expand Up @@ -123,6 +124,7 @@ class NimBLEDevice {
static bool isInitialized();
static NimBLEAddress getAddress();
static std::string toString();
static const char* getVersion();
static bool whiteListAdd(const NimBLEAddress& address);
static bool whiteListRemove(const NimBLEAddress& address);
static bool onWhiteList(const NimBLEAddress& address);
Expand Down
Loading