Skip to content

Commit 9cb1a67

Browse files
afpinedah2zero
authored andcommitted
Bug fix on PNP info
Fixed issue #492
1 parent 0d9f039 commit 9cb1a67

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/NimBLEHIDDevice.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) {
3535
*/
3636
m_pnpCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a50, NIMBLE_PROPERTY::READ);
3737

38+
/*
39+
* Non-mandatory characteristics for device info service
40+
* Will be created on demand
41+
*/
42+
m_manufacturerCharacteristic = nullptr;
43+
3844
/*
3945
* Mandatory characteristics for HID service
4046
*/
@@ -86,7 +92,10 @@ void NimBLEHIDDevice::startServices() {
8692
* @brief Create a manufacturer characteristic (this characteristic is optional).
8793
*/
8894
NimBLECharacteristic* NimBLEHIDDevice::manufacturer() {
89-
m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a29, NIMBLE_PROPERTY::READ);
95+
if (m_manufacturerCharacteristic == nullptr) {
96+
m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t)0x2a29, NIMBLE_PROPERTY::READ);
97+
}
98+
9099
return m_manufacturerCharacteristic;
91100
}
92101

@@ -95,7 +104,7 @@ NimBLECharacteristic* NimBLEHIDDevice::manufacturer() {
95104
* @param [in] name The manufacturer name of this HID device.
96105
*/
97106
void NimBLEHIDDevice::manufacturer(std::string name) {
98-
m_manufacturerCharacteristic->setValue(name);
107+
manufacturer()->setValue(name);
99108
}
100109

101110
/**
@@ -106,7 +115,15 @@ void NimBLEHIDDevice::manufacturer(std::string name) {
106115
* @param [in] version The produce version number.
107116
*/
108117
void NimBLEHIDDevice::pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version) {
109-
uint8_t pnp[] = { sig, (uint8_t) (vid >> 8), (uint8_t) vid, (uint8_t) (pid >> 8), (uint8_t) pid, (uint8_t) (version >> 8), (uint8_t) version };
118+
uint8_t pnp[] = {
119+
sig,
120+
((uint8_t *)&vid)[0],
121+
((uint8_t *)&vid)[1],
122+
((uint8_t *)&pid)[0],
123+
((uint8_t *)&pid)[1],
124+
((uint8_t *)&version)[0],
125+
((uint8_t *)&version)[1]
126+
};
110127
m_pnpCharacteristic->setValue(pnp, sizeof(pnp));
111128
}
112129

src/NimBLEHIDDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define HID_DIGITAL_PEN 0x03C7
3434
#define HID_BARCODE 0x03C8
3535

36+
#define PNPVersionField(MajorVersion, MinorVersion, PatchVersion) ((MajorVersion << 16) & 0xFF00) | ((MinorVersion << 8) & 0x00F0) | (PatchVersion & 0x000F)
3637

3738
/**
3839
* @brief A model of a %BLE Human Interface Device.

0 commit comments

Comments
 (0)