Make string use compatible with newer ESP-Arduino core’s BLEDevice *while retaining backward compatibilty*#382
Conversation
In espressif/arduino-esp32 822f252b353c (2023-10-06), first released in arduino-esp32 3.0.0 (2024-05-27), some string types in BLEDevice changed from std::string (a C++ library string) to String (an Arduino string). See espressif/arduino-esp32#8724. This change makes BleKeyboard compatible with both the old and new versions of arduino-esp32, by detecting the version in use at compile time.
This updates the codebase for compatibility with https://github.com/pioarduino/platform-espressif32 55.03.35, which in turn uses https://github.com/espressif/arduino-esp32 3.3.5. An additional change along the lines of T-vK/ESP32-BLE-Keyboard#382 is needed to make lib/ESP32-BLE-Keyboard compatibile as well. This does not change the platform definition, which remains at https://github.com/platformio/platform-espressif32 6.8.1, using https://github.com/espressif/arduino-esp32 2.0.17. All changed code is compatible with both versions.
This updates the codebase for compatibility with https://github.com/pioarduino/platform-espressif32 55.03.35, which in turn uses https://github.com/espressif/arduino-esp32 3.3.5. An additional change along the lines of T-vK/ESP32-BLE-Keyboard#382 is needed to make lib/ESP32-BLE-Keyboard compatibile as well. This does not change the platform definition, which remains at https://github.com/platformio/platform-espressif32 6.8.1, using https://github.com/espressif/arduino-esp32 2.0.17. All changed code is correct regardless of Arduino-ESP version, and all changed code is compatible with both versions.
This updates the codebase for compatibility with https://github.com/pioarduino/platform-espressif32 55.03.35, which in turn uses https://github.com/espressif/arduino-esp32 3.3.5. An additional change along the lines of T-vK/ESP32-BLE-Keyboard#382 is needed to make lib/ESP32-BLE-Keyboard compatibile as well. This does not change the platform definition, which remains at https://github.com/platformio/platform-espressif32 6.8.1, using https://github.com/espressif/arduino-esp32 2.0.17. All changed code is correct regardless of Arduino-ESP version, and all changed code is compatible with both versions.
|
sorry it did realy working: |
Which version of arduino-esp32 are you using? |
|
3.3.4 |
Maybe Can you try adding #include "esp_arduino_version.h"to the top of BleKeyboard.cpp? |
|
i have do it: #if ESP_ARDUINO_VERSION_MAJOR < 3 hid = new BLEHIDDevice(pServer); outputKeyboard->setCallbacks(this); #if ESP_ARDUINO_VERSION_MAJOR < 3 N:\Doks\Arduino\libraries\ESP32C3_BLE_Keyboard\examples\SendKeyStrokes\BleKeyboard.cpp: In member function 'void BleKeyboard::begin()': |
In espressif/arduino-esp32@822f252, first released in https://github.com/espressif/arduino-esp32/releases/tag/3.0.0, some string types in BLEDevice changed from
std::string(a C++ library string) toString(an Arduino string). See espressif/arduino-esp32#8724.This change makes BleKeyboard compatible with both the old and new versions of arduino-esp32, by detecting the version in use at compile time.
I am aware that many other pull requests are open that intend to address this problem, but as far as I can see, they all migrate straight to the arduino-esp32 3.0.0 interface, without any affordance for compatibility with older versions of arduino-esp32. This pull request makes BleKeyboard compatible with both the old and new interfaces. This pull request also uses the known size of a
std::stringwhen constructing aString.