ESP32-BLE-Keyboard icon indicating copy to clipboard operation
ESP32-BLE-Keyboard copied to clipboard

Update BleKeyboard.cpp

Open DustinWatts opened this issue 5 years ago • 6 comments

Edited BleKeyboard::begin and BleKeyboard::end to be able to delete the Task when stopping BleKeyboard. I had the need for this to so I could stop ESP32-BLE-Keyboard and start AsyncWebServer.

If you create a task like this:

TaskHandle_t xHandle = NULL;

void BleKeyboard::begin(void) { xTaskCreate(this->taskServer, "server", 20000, (void *)this, 5, &xHandle); }

You will be able to delete the task using BleKeyboard.end();

void BleKeyboard::end(void) { vTaskDelete(xHandle); }

DustinWatts avatar Nov 04 '20 23:11 DustinWatts

Thanks for your contribution. However, I would like to get #53 merged first and from what I recall it removes the xTaskCreate. I think with #53 merged the memory footprint will be greatly reduced and thus you should be able to run a webserver in parallel without having to end the BleKeyboard instance. The only reason I haven't merged #53 yet is that I would like startAdvertising to be called by the library internally rather than forcing the user deal with this. Maybe you can help with that? Because rousir hasn't replied.

T-vK avatar Nov 04 '20 23:11 T-vK

I can at least test it for you on Mac. I reduced the STACK_SIZE to about 2500 but is still wasn't good enough. That is why I create the vTaskDelete. In my case in doesn't matter because when the AsyncWebServer is started, I do not need BLE until I restart.

DustinWatts avatar Nov 04 '20 23:11 DustinWatts

I have changed the task size to 4096. 20000 was quite big. Haven't had issues since.

I also included BLE_KEYBOARD_VERSION "1.1" (Which off course can be any version number) for debugging purposes.

DustinWatts avatar Jan 01 '21 19:01 DustinWatts

Thanks for the efforts and I have tested without issues on PC, Android. However, can someone suggest how to convert this to classic BT instead of BLE environment please? I am a volunteer worker teaching remote region juniors to make fun projects, To cut the story short, the facility only equipped with outdated computers (BT2.0) , no BLE.

asianplanet avatar Jan 09 '21 16:01 asianplanet

No it can't be converted. Maybe if you work at espressif.

T-vK avatar Jan 09 '21 18:01 T-vK

To Dustin Watts, thanks for posting this - it solved a problem I have been working on for a few days now.

T-vk - I would like to second Dustin Watts' request to have this change accepted.

roblatour avatar Jul 03 '21 04:07 roblatour