From 361806ab352c4910073504883e799d7ac9adf9d2 Mon Sep 17 00:00:00 2001 From: Paperino <42046613+aovestdipaperino@users.noreply.github.com> Date: Wed, 21 Apr 2021 14:19:45 -0700 Subject: [PATCH] Fix reconnection issue #84 (#86) --- BleConnectionStatus.cpp | 2 +- BleConnectionStatus.h | 1 + BleKeyboard.cpp | 12 ++++++------ library.properties | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/BleConnectionStatus.cpp b/BleConnectionStatus.cpp index baf51ed..1b8bcad 100644 --- a/BleConnectionStatus.cpp +++ b/BleConnectionStatus.cpp @@ -21,5 +21,5 @@ void BleConnectionStatus::onDisconnect(BLEServer* pServer) desc = (BLE2902*)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); desc->setNotifications(false); - + pAdvertising->start(); } diff --git a/BleConnectionStatus.h b/BleConnectionStatus.h index 7fd2667..67cd42a 100644 --- a/BleConnectionStatus.h +++ b/BleConnectionStatus.h @@ -17,6 +17,7 @@ class BleConnectionStatus : public BLEServerCallbacks BLECharacteristic* inputKeyboard; BLECharacteristic* outputKeyboard; BLECharacteristic* inputMediaKeys; + BLEAdvertising *pAdvertising; }; #endif // CONFIG_BT_ENABLED diff --git a/BleKeyboard.cpp b/BleKeyboard.cpp index e98af09..4329fc9 100644 --- a/BleKeyboard.cpp +++ b/BleKeyboard.cpp @@ -128,7 +128,7 @@ void BleKeyboard::taskServer(void* pvParameter) { bleKeyboardInstance->inputMediaKeys = bleKeyboardInstance->hid->inputReport(MEDIA_KEYS_ID); bleKeyboardInstance->connectionStatus->inputKeyboard = bleKeyboardInstance->inputKeyboard; bleKeyboardInstance->connectionStatus->outputKeyboard = bleKeyboardInstance->outputKeyboard; - bleKeyboardInstance->connectionStatus->inputMediaKeys = bleKeyboardInstance->inputMediaKeys; + bleKeyboardInstance->connectionStatus->inputMediaKeys = bleKeyboardInstance->inputMediaKeys; bleKeyboardInstance->outputKeyboard->setCallbacks(new KeyboardOutputCallbacks()); @@ -146,11 +146,11 @@ void BleKeyboard::taskServer(void* pvParameter) { bleKeyboardInstance->onStarted(pServer); - BLEAdvertising *pAdvertising = pServer->getAdvertising(); - pAdvertising->setAppearance(HID_KEYBOARD); - pAdvertising->addServiceUUID(bleKeyboardInstance->hid->hidService()->getUUID()); - pAdvertising->setScanResponse(false); - pAdvertising->start(); + bleKeyboardInstance->connectionStatus->pAdvertising = pServer->getAdvertising(); + bleKeyboardInstance->connectionStatus->pAdvertising->setAppearance(HID_KEYBOARD); + bleKeyboardInstance->connectionStatus->pAdvertising->addServiceUUID(bleKeyboardInstance->hid->hidService()->getUUID()); + bleKeyboardInstance->connectionStatus->pAdvertising->setScanResponse(false); + bleKeyboardInstance->connectionStatus->pAdvertising->start(); bleKeyboardInstance->hid->setBatteryLevel(bleKeyboardInstance->batteryLevel); ESP_LOGD(LOG_TAG, "Advertising started!"); diff --git a/library.properties b/library.properties index 50b216b..3382ef6 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP32 BLE Keyboard -version=0.2.2 +version=0.2.3 author=T-vK maintainer=T-vK sentence=Bluetooth LE Keyboard library for the ESP32.