turgu1 / bt-keyboard

Other
71 stars 8 forks source link

Adding compatibility with Arduino IDE and bonding/reconnect features #5

Closed Hamberthm closed 4 months ago

Hamberthm commented 1 year ago

Hi! Sorry if I'm doing this wrong or if it's just a mess. I'm a noob on Git and in coding in general. I just want to bring awareness on the many improves I made to the code:

-added isConnected flag, hidh_callback() will update it in case of connections/disconnections. -now devices_scan() returns true if a device of interest has been found and connection open requested for it (doesn't guarantee connection, refer to isConnected for that) -added BLE security params and enabled bonding/permanent key exchange. -now handle_ble_device_result() and devices_scan() will retrieve the bonded devices list from flash and connect to the latest bonded device if in range, avoiding the need to enter pairing mode, otherwise discovery and pairing goes on as normal. -added quick_reconnect() function that can be recursively called if isConnected flag goes false. This will try to reconnect to the latest device without losing time on scanning. This is critical for battery keyboards that go to sleep or reset.

1raghavmahajan commented 6 months ago

I'm not sure how to read up on this but how do I setup your fork with Arduino? I thought this required ESP-IDF to build. I'm sorry I don't understand how they work together.

Hamberthm commented 6 months ago

I'm not sure how to read up on this but how do I setup your fork with Arduino? I thought this required ESP-IDF to build. I'm sorry I don't understand how they work together.

You should be able to copy the code and use it under Arduino IDE and compile/upload for the ESP-32 board. If you don't know how to compile for ESP under Arduino, look for a guide, there's plenty of info.

Basically esp_bt_controller_init(&bt_cfg) was not working with the Arduino core for ESP32, so I chnget it for btStart(). You can look at the commit and the code comments.