Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions BleKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ void BleKeyboard::begin(void)
pServer->setCallbacks(this);

hid = new BLEHIDDevice(pServer);
inputKeyboard = hid->inputReport(KEYBOARD_ID); // <-- input REPORTID from report map
outputKeyboard = hid->outputReport(KEYBOARD_ID);
inputMediaKeys = hid->inputReport(MEDIA_KEYS_ID);
inputKeyboard = hid->getInputReport(KEYBOARD_ID); // <-- input REPORTID from report map
outputKeyboard = hid->getOutputReport(KEYBOARD_ID);
inputMediaKeys = hid->getInputReport(MEDIA_KEYS_ID);

outputKeyboard->setCallbacks(this);

hid->manufacturer()->setValue(deviceManufacturer);
hid->setManufacturer(deviceManufacturer);

hid->pnp(0x02, vid, pid, version);
hid->hidInfo(0x00, 0x01);
hid->setPnp(0x02, vid, pid, version);
hid->setHidInfo(0x00, 0x01);


#if defined(USE_NIMBLE)
Expand All @@ -131,15 +131,16 @@ void BleKeyboard::begin(void)

#endif // USE_NIMBLE

hid->reportMap((uint8_t*)_hidReportDescriptor, sizeof(_hidReportDescriptor));
hid->setReportMap((uint8_t*)_hidReportDescriptor, sizeof(_hidReportDescriptor));
hid->startServices();

onStarted(pServer);

advertising = pServer->getAdvertising();
advertising->setAppearance(HID_KEYBOARD);
advertising->addServiceUUID(hid->hidService()->getUUID());
advertising->setScanResponse(false);
advertising->addServiceUUID(hid->getHidService()->getUUID());
advertising->setName(deviceName);

advertising->start();
hid->setBatteryLevel(batteryLevel);

Expand Down Expand Up @@ -500,7 +501,7 @@ size_t BleKeyboard::write(const uint8_t *buffer, size_t size) {
return n;
}

void BleKeyboard::onConnect(BLEServer* pServer) {
void BleKeyboard::onConnect(BLEServer* pServer, NimBLEConnInfo & connInfo) {
this->connected = true;

#if !defined(USE_NIMBLE)
Expand All @@ -514,7 +515,7 @@ void BleKeyboard::onConnect(BLEServer* pServer) {

}

void BleKeyboard::onDisconnect(BLEServer* pServer) {
void BleKeyboard::onDisconnect(BLEServer* pServer, NimBLEConnInfo & connInfo, int reason) {
this->connected = false;

#if !defined(USE_NIMBLE)
Expand All @@ -529,7 +530,7 @@ void BleKeyboard::onDisconnect(BLEServer* pServer) {
#endif // !USE_NIMBLE
}

void BleKeyboard::onWrite(BLECharacteristic* me) {
void BleKeyboard::onWrite(BLECharacteristic* me, NimBLEConnInfo & connInfo) {
uint8_t* value = (uint8_t*)(me->getValue().c_str());
(void)value;
ESP_LOGI(LOG_TAG, "special keys: %d", *value);
Expand Down
14 changes: 8 additions & 6 deletions BleKeyboard.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// uncomment the following line to use NimBLE library
//#define USE_NIMBLE
#define USE_NIMBLE

#ifndef ESP32_BLE_KEYBOARD_H
#define ESP32_BLE_KEYBOARD_H
Expand All @@ -10,6 +10,8 @@

#include "NimBLECharacteristic.h"
#include "NimBLEHIDDevice.h"
#include "NimBLEAdvertising.h"
#include "NimBLEServer.h"

#define BLEDevice NimBLEDevice
#define BLEServerCallbacks NimBLEServerCallbacks
Expand All @@ -28,10 +30,10 @@

#include "Print.h"

#define BLE_KEYBOARD_VERSION "0.0.4"
#define BLE_KEYBOARD_VERSION "0.0.6"
#define BLE_KEYBOARD_VERSION_MAJOR 0
#define BLE_KEYBOARD_VERSION_MINOR 0
#define BLE_KEYBOARD_VERSION_REVISION 4
#define BLE_KEYBOARD_VERSION_REVISION 6

const uint8_t KEY_LEFT_CTRL = 0x80;
const uint8_t KEY_LEFT_SHIFT = 0x81;
Expand Down Expand Up @@ -173,9 +175,9 @@ class BleKeyboard : public Print, public BLEServerCallbacks, public BLECharacter
void set_version(uint16_t version);
protected:
virtual void onStarted(BLEServer *pServer) { };
virtual void onConnect(BLEServer* pServer) override;
virtual void onDisconnect(BLEServer* pServer) override;
virtual void onWrite(BLECharacteristic* me) override;
virtual void onConnect(BLEServer* pServer, NimBLEConnInfo & connInfo) override;
virtual void onDisconnect(BLEServer* pServer, NimBLEConnInfo & connInfo, int reason) override;
virtual void onWrite(BLECharacteristic* me, NimBLEConnInfo & connInfo) override;

};

Expand Down