mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-25 12:10:47 +01:00
parent
226c67f729
commit
6fa3783206
2 changed files with 21 additions and 3 deletions
|
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue