From 1ff0e8e1016eca9ff4e805ed92e07e8debfacaf2 Mon Sep 17 00:00:00 2001 From: Trident Apollo Date: Tue, 7 Jan 2025 23:37:21 +0530 Subject: [PATCH 1/2] Fixes issues with Arduino IDE compilation In Arduino IDE the ESP32 core library has BleDevice.h library that is uses String but the code used std::string instead which raised an error during compilation, this commit fixes that issue --- BleKeyboard.cpp | 11 +++++------ BleKeyboard.h | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/BleKeyboard.cpp b/BleKeyboard.cpp index 48a8930..76c4ffa 100644 --- a/BleKeyboard.cpp +++ b/BleKeyboard.cpp @@ -95,10 +95,10 @@ static const uint8_t _hidReportDescriptor[] = { END_COLLECTION(0) // END_COLLECTION }; -BleKeyboard::BleKeyboard(std::string deviceName, std::string deviceManufacturer, uint8_t batteryLevel) +BleKeyboard::BleKeyboard(String deviceName, String deviceManufacturer, uint8_t batteryLevel) : hid(0) - , deviceName(std::string(deviceName).substr(0, 15)) - , deviceManufacturer(std::string(deviceManufacturer).substr(0,15)) + , deviceName(String(deviceName).substring(0, 15)) + , deviceManufacturer(String(deviceManufacturer).substring(0,15)) , batteryLevel(batteryLevel) {} void BleKeyboard::begin(void) @@ -161,7 +161,7 @@ void BleKeyboard::setBatteryLevel(uint8_t level) { } //must be called before begin in order to set the name -void BleKeyboard::setName(std::string deviceName) { +void BleKeyboard::setName(String deviceName) { this->deviceName = deviceName; } @@ -468,7 +468,6 @@ void BleKeyboard::releaseAll(void) _mediaKeyReport[0] = 0; _mediaKeyReport[1] = 0; sendReport(&_keyReport); - sendReport(&_mediaKeyReport); } size_t BleKeyboard::write(uint8_t c) @@ -544,4 +543,4 @@ void BleKeyboard::delay_ms(uint64_t ms) { } while(esp_timer_get_time() < e) {} } -} +} \ No newline at end of file diff --git a/BleKeyboard.h b/BleKeyboard.h index 0736a02..1d1ce07 100644 --- a/BleKeyboard.h +++ b/BleKeyboard.h @@ -138,8 +138,8 @@ class BleKeyboard : public Print, public BLEServerCallbacks, public BLECharacter BLEAdvertising* advertising; KeyReport _keyReport; MediaKeyReport _mediaKeyReport; - std::string deviceName; - std::string deviceManufacturer; + String deviceName; + String deviceManufacturer; uint8_t batteryLevel; bool connected = false; uint32_t _delay_ms = 7; @@ -150,7 +150,7 @@ class BleKeyboard : public Print, public BLEServerCallbacks, public BLECharacter uint16_t version = 0x0210; public: - BleKeyboard(std::string deviceName = "ESP32 Keyboard", std::string deviceManufacturer = "Espressif", uint8_t batteryLevel = 100); + BleKeyboard(String deviceName = "ESP32 Keyboard", String deviceManufacturer = "Espressif", uint8_t batteryLevel = 100); void begin(void); void end(void); void sendReport(KeyReport* keys); @@ -165,7 +165,7 @@ class BleKeyboard : public Print, public BLEServerCallbacks, public BLECharacter void releaseAll(void); bool isConnected(void); void setBatteryLevel(uint8_t level); - void setName(std::string deviceName); + void setName(String deviceName); void setDelay(uint32_t ms); void set_vendor_id(uint16_t vid); From 49cfc45ee44e52d077cda108e9119604913231f2 Mon Sep 17 00:00:00 2001 From: Trident Apollo Date: Wed, 2 Apr 2025 19:28:28 +0530 Subject: [PATCH 2/2] Update library.properties --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 263a10f..19cf838 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP32 BLE Keyboard -version=0.3.2 +version=0.3.4 author=T-vK maintainer=T-vK sentence=Bluetooth LE Keyboard library for the ESP32.