mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-12-27 17:18:11 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da48844e2f | ||
|
|
ea1c055826 | ||
|
|
65f6ee18ca | ||
|
|
fd0187bfc9 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
||||
docs/doxydocs
|
||||
docs/doxydocs
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [2.0.2] 2024-12-21
|
||||
|
||||
## Fixed
|
||||
- Compile error when only advertising role is enabled.
|
||||
- Possible crash if bonded client reconnects.
|
||||
|
||||
## Changed
|
||||
- `NimBLEHIDDevice` can now create more than one in/out/feature report map.
|
||||
|
||||
## [2.0.1] 2024-12-16
|
||||
|
||||
## Fixed
|
||||
|
||||
@@ -48,7 +48,7 @@ PROJECT_NAME = esp-nimble-cpp
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 2.0.1
|
||||
PROJECT_NUMBER = 2.0.2
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
## IDF Component Manager Manifest File
|
||||
version: "2.0.1"
|
||||
version: "2.0.2"
|
||||
license: "Apache-2.0"
|
||||
description: "C++ wrapper for the NimBLE BLE stack"
|
||||
url: "https://github.com/h2zero/esp-nimble-cpp"
|
||||
|
||||
@@ -1154,6 +1154,7 @@ bool NimBLEDevice::startSecurity(uint16_t connHandle, int* rcPtr) {
|
||||
return rc == 0 || rc == BLE_HS_EALREADY;
|
||||
} // startSecurity
|
||||
|
||||
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
/**
|
||||
* @brief Inject the provided passkey into the Security Manager.
|
||||
* @param [in] peerInfo Connection information for the peer.
|
||||
@@ -1178,6 +1179,7 @@ bool NimBLEDevice::injectConfirmPasskey(const NimBLEConnInfo& peerInfo, bool acc
|
||||
NIMBLE_LOGD(LOG_TAG, "BLE_SM_IOACT_NUMCMP; ble_sm_inject_io result: %d", rc);
|
||||
return rc == 0;
|
||||
}
|
||||
# endif // CONFIG_BT_NIMBLE_ROLE_CENTRAL || CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* UTILITIES */
|
||||
|
||||
@@ -149,14 +149,41 @@ void NimBLEHIDDevice::setBatteryLevel(uint8_t level, bool notify) {
|
||||
}
|
||||
} // setBatteryLevel
|
||||
|
||||
/**
|
||||
* @brief Locate the characteristic for a report ID.
|
||||
*
|
||||
* @param [in] reportId Report identifier to locate.
|
||||
* @param [out] reportType Type of report (input/output/feature). Not meaningful if the return value is nullptr.
|
||||
* @return NimBLECharacteristic* The characteristic.
|
||||
* @return nullptr If the characteristic does not exist.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::locateReportCharacteristicById(uint8_t reportId, uint8_t& reportType) {
|
||||
NimBLECharacteristic* candidate = m_hidSvc->getCharacteristic(inputReportChrUuid, 0);
|
||||
for (uint16_t i = 1; (candidate != nullptr) && (i != 0); i++) {
|
||||
NimBLEDescriptor* dsc = candidate->getDescriptorByUUID(featureReportDscUuid);
|
||||
NimBLEAttValue desc1_val_att = dsc->getValue();
|
||||
const uint8_t* desc1_val = desc1_val_att.data();
|
||||
reportType = desc1_val[1];
|
||||
if (desc1_val[0] == reportId) return candidate;
|
||||
candidate = m_hidSvc->getCharacteristic(inputReportChrUuid, i);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the input report characteristic.
|
||||
* @param [in] reportId input report ID, the same as in report map for input object related to the characteristic.
|
||||
* @return A pointer to the input report characteristic.
|
||||
* @param [in] reportId Input report ID, the same as in report map for input object related to the characteristic.
|
||||
* @return NimBLECharacteristic* A pointer to the input report characteristic.
|
||||
* Store this value to avoid computational overhead.
|
||||
* @return nullptr If the report is already created as an output or feature report.
|
||||
* @details This will create the characteristic if not already created.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getInputReport(uint8_t reportId) {
|
||||
NimBLECharacteristic* inputReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid);
|
||||
uint8_t reportType;
|
||||
NimBLECharacteristic* inputReportChr = locateReportCharacteristicById(reportId, reportType);
|
||||
if ((inputReportChr != nullptr) && (reportType != 0x01))
|
||||
// ERROR: this reportId exists, but it is not an input report
|
||||
return nullptr;
|
||||
if (inputReportChr == nullptr) {
|
||||
inputReportChr =
|
||||
m_hidSvc->createCharacteristic(inputReportChrUuid,
|
||||
@@ -174,13 +201,17 @@ NimBLECharacteristic* NimBLEHIDDevice::getInputReport(uint8_t reportId) {
|
||||
/**
|
||||
* @brief Get the output report characteristic.
|
||||
* @param [in] reportId Output report ID, the same as in report map for output object related to the characteristic.
|
||||
* @return A pointer to the output report characteristic.
|
||||
* @return NimBLECharacteristic* A pointer to the output report characteristic.
|
||||
* Store this value to avoid computational overhead.
|
||||
* @return nullptr If the report is already created as an input or feature report.
|
||||
* @details This will create the characteristic if not already created.
|
||||
* @note The output report characteristic is optional and should only be created after the input report characteristic.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getOutputReport(uint8_t reportId) {
|
||||
// Same uuid as input so this needs to be the second instance
|
||||
NimBLECharacteristic* outputReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid, 1);
|
||||
uint8_t reportType;
|
||||
NimBLECharacteristic* outputReportChr = locateReportCharacteristicById(reportId, reportType);
|
||||
if ((outputReportChr != nullptr) && (reportType != 0x02))
|
||||
// ERROR: this reportId exists, but it is not an output report
|
||||
return nullptr;
|
||||
if (outputReportChr == nullptr) {
|
||||
outputReportChr =
|
||||
m_hidSvc->createCharacteristic(inputReportChrUuid,
|
||||
@@ -189,7 +220,6 @@ NimBLECharacteristic* NimBLEHIDDevice::getOutputReport(uint8_t reportId) {
|
||||
NimBLEDescriptor* outputReportDsc = outputReportChr->createDescriptor(
|
||||
featureReportDscUuid,
|
||||
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC);
|
||||
|
||||
uint8_t desc1_val[] = {reportId, 0x02};
|
||||
outputReportDsc->setValue(desc1_val, 2);
|
||||
}
|
||||
@@ -200,11 +230,17 @@ NimBLECharacteristic* NimBLEHIDDevice::getOutputReport(uint8_t reportId) {
|
||||
/**
|
||||
* @brief Get the feature report characteristic.
|
||||
* @param [in] reportId Feature report ID, the same as in report map for feature object related to the characteristic.
|
||||
* @return A pointer to feature report characteristic.
|
||||
* @return NimBLECharacteristic* A pointer to feature report characteristic.
|
||||
* Store this value to avoid computational overhead.
|
||||
* @return nullptr If the report is already created as an input or output report.
|
||||
* @details This will create the characteristic if not already created.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getFeatureReport(uint8_t reportId) {
|
||||
NimBLECharacteristic* featureReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid);
|
||||
uint8_t reportType;
|
||||
NimBLECharacteristic* featureReportChr = locateReportCharacteristicById(reportId, reportType);
|
||||
if ((featureReportChr != nullptr) && (reportType != 0x03))
|
||||
// ERROR: this reportId exists, but it is not a feature report
|
||||
return nullptr;
|
||||
if (featureReportChr == nullptr) {
|
||||
featureReportChr = m_hidSvc->createCharacteristic(
|
||||
inputReportChrUuid,
|
||||
|
||||
@@ -81,6 +81,8 @@ class NimBLEHIDDevice {
|
||||
NimBLECharacteristic* m_hidControlChr{nullptr}; // 0x2a4c
|
||||
NimBLECharacteristic* m_protocolModeChr{nullptr}; // 0x2a4e
|
||||
NimBLECharacteristic* m_batteryLevelChr{nullptr}; // 0x2a19
|
||||
|
||||
NimBLECharacteristic* locateReportCharacteristicById(uint8_t reportId, uint8_t& reportType);
|
||||
};
|
||||
|
||||
#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
@@ -91,6 +91,13 @@ void NimBLEService::dump() const {
|
||||
*/
|
||||
bool NimBLEService::start() {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> start(): Starting service: %s", toString().c_str());
|
||||
|
||||
// If started previously and no characteristics have been added or removed,
|
||||
// then we can skip the service registration process.
|
||||
if (m_pSvcDef->characteristics && !getServer()->m_svcChanged) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If started previously, clear everything and start over
|
||||
if (m_pSvcDef->characteristics) {
|
||||
if (m_pSvcDef->characteristics->descriptors) {
|
||||
|
||||
Reference in New Issue
Block a user