Bug fix on PNP info

Fixed issue #492
This commit is contained in:
afpineda 2023-03-25 12:49:37 +01:00 committed by h2zero
parent 226c67f729
commit 6fa3783206
2 changed files with 21 additions and 3 deletions

View file

@ -35,6 +35,12 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) {
*/ */
m_pnpCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a50, NIMBLE_PROPERTY::READ); 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 * Mandatory characteristics for HID service
*/ */
@ -86,7 +92,10 @@ void NimBLEHIDDevice::startServices() {
* @brief Create a manufacturer characteristic (this characteristic is optional). * @brief Create a manufacturer characteristic (this characteristic is optional).
*/ */
NimBLECharacteristic* NimBLEHIDDevice::manufacturer() { NimBLECharacteristic* NimBLEHIDDevice::manufacturer() {
if (m_manufacturerCharacteristic == nullptr) {
m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t)0x2a29, NIMBLE_PROPERTY::READ); m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t)0x2a29, NIMBLE_PROPERTY::READ);
}
return m_manufacturerCharacteristic; return m_manufacturerCharacteristic;
} }
@ -95,7 +104,7 @@ NimBLECharacteristic* NimBLEHIDDevice::manufacturer() {
* @param [in] name The manufacturer name of this HID device. * @param [in] name The manufacturer name of this HID device.
*/ */
void NimBLEHIDDevice::manufacturer(std::string name) { void NimBLEHIDDevice::manufacturer(std::string name) {
m_manufacturerCharacteristic->setValue(name); manufacturer()->setValue(name);
} }
/** /**
@ -106,7 +115,15 @@ void NimBLEHIDDevice::manufacturer(std::string name) {
* @param [in] version The produce version number. * @param [in] version The produce version number.
*/ */
void NimBLEHIDDevice::pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version) { 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)); m_pnpCharacteristic->setValue(pnp, sizeof(pnp));
} }

View file

@ -33,6 +33,7 @@
#define HID_DIGITAL_PEN 0x03C7 #define HID_DIGITAL_PEN 0x03C7
#define HID_BARCODE 0x03C8 #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. * @brief A model of a %BLE Human Interface Device.