Skip to content

Commit 76e31d4

Browse files
committed
Updated BleKeyboard Class
1 parent b078372 commit 76e31d4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

NimBleKeyboard.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ void BleKeyboard::begin(void)
9494
NimBLEDevice::init(deviceName);
9595
NimBLEServer* pServer = NimBLEDevice::createServer();
9696
pServer->setCallbacks(this);
97+
// Set server auto-restart advertise on
98+
pServer->advertiseOnDisconnect(true);
9799

98100
hid = new NimBLEHIDDevice(pServer);
99101
inputKeyboard = hid->getInputReport(KEYBOARD_ID); // <-- input REPORTID from report map
@@ -103,10 +105,17 @@ void BleKeyboard::begin(void)
103105
outputKeyboard->setCallbacks(this);
104106

105107
hid->setManufacturer(deviceManufacturer);
106-
107108
hid->setPnp(0x02, vid, pid, version);
108109
hid->setHidInfo(0x00, 0x01);
109110

111+
// Set the Generic Access Appearance value from default: [0] a.k.a. "Unknown" to HID_KEYBOARD
112+
int RespErr = ble_svc_gap_device_appearance_set(HID_KEYBOARD);
113+
if(RespErr == 0) {
114+
ESP_LOGI(LOG_TAG, "Generic Access Appearance set to: [%d]", HID_KEYBOARD);
115+
} else {
116+
ESP_LOGD(LOG_TAG, "Unable to set Generic Access Appearance value!");
117+
}
118+
110119
NimBLEDevice::setSecurityAuth(true, true, true);
111120

112121
hid->setReportMap((uint8_t*)_hidReportDescriptor, sizeof(_hidReportDescriptor));
@@ -116,6 +125,7 @@ void BleKeyboard::begin(void)
116125

117126
advertising = pServer->getAdvertising();
118127
advertising->setAppearance(HID_KEYBOARD);
128+
advertising->setName(deviceName);
119129
advertising->addServiceUUID(hid->getHidService()->getUUID());
120130
advertising->enableScanResponse(false);
121131
advertising->start();

NimBleKeyboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#if defined(CONFIG_BT_ENABLED)
55

66
#include <NimBLEDevice.h>
7+
#include <nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h>
78
#include <NimBLEHIDDevice.h>
89
#include "Print.h"
910

0 commit comments

Comments
 (0)