Skip to content

Commit

Permalink
Bug fix on PNP info
Browse files Browse the repository at this point in the history
Fixed issue #492
  • Loading branch information
afpineda authored and h2zero committed Jun 2, 2024
1 parent 0d9f039 commit 9cb1a67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/NimBLEHIDDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) {
*/
m_pnpCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a50, NIMBLE_PROPERTY::READ);

/*
* Non-mandatory characteristics for device info service
* Will be created on demand
*/
m_manufacturerCharacteristic = nullptr;

/*
* Mandatory characteristics for HID service
*/
Expand Down Expand Up @@ -86,7 +92,10 @@ void NimBLEHIDDevice::startServices() {
* @brief Create a manufacturer characteristic (this characteristic is optional).
*/
NimBLECharacteristic* NimBLEHIDDevice::manufacturer() {
m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a29, NIMBLE_PROPERTY::READ);
if (m_manufacturerCharacteristic == nullptr) {
m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t)0x2a29, NIMBLE_PROPERTY::READ);
}

return m_manufacturerCharacteristic;
}

Expand All @@ -95,7 +104,7 @@ NimBLECharacteristic* NimBLEHIDDevice::manufacturer() {
* @param [in] name The manufacturer name of this HID device.
*/
void NimBLEHIDDevice::manufacturer(std::string name) {
m_manufacturerCharacteristic->setValue(name);
manufacturer()->setValue(name);
}

/**
Expand All @@ -106,7 +115,15 @@ void NimBLEHIDDevice::manufacturer(std::string name) {
* @param [in] version The produce version number.
*/
void NimBLEHIDDevice::pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version) {
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 };
uint8_t pnp[] = {
sig,
((uint8_t *)&vid)[0],
((uint8_t *)&vid)[1],
((uint8_t *)&pid)[0],
((uint8_t *)&pid)[1],
((uint8_t *)&version)[0],
((uint8_t *)&version)[1]
};
m_pnpCharacteristic->setValue(pnp, sizeof(pnp));
}

Expand Down
1 change: 1 addition & 0 deletions src/NimBLEHIDDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define HID_DIGITAL_PEN 0x03C7
#define HID_BARCODE 0x03C8

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

/**
* @brief A model of a %BLE Human Interface Device.
Expand Down

0 comments on commit 9cb1a67

Please sign in to comment.