You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- printf replaced with std::cout
- Added comments
- Removed unused code
- Removed unused files
- private members renamed with underscore suffix
- Some new handlers for the application
Remains to do:
- resolve ble device reconnection not working fine
- synchronize the code with the esp-idf example
- issues with the new handlers not called on connected_ changes
Copy file name to clipboardexpand all lines: README.md
+33-17
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,27 @@
1
-
# ESP32 ESP-IDF Bluetooth keyboard input demo
1
+
# ESP32 ESP-IDF Bluetooth Keyboard Input Demo For Receiving And Processing Keyboard Inputs
2
2
3
-
(Updated 2022/02/02)
3
+
(Updated 2025-02-09)
4
4
5
-
(Work in progress... updated for ESP-IDF V4.4)
5
+
- Now using `ESP-IDF V5.4` for development.
6
+
- Partial support of CMake Presets (compiling using VSCode CMake extensions instead of idf.py)
7
+
- The `BTKeyboard` class is now located in the components folder
8
+
-`keys` renamed to `keys_data` and is now 20 bytes in size. It may need to be larger depending on the keyboard in use.
9
+
- All printf use is gone. Now using ostream.
10
+
- BLE keyboard `Logitech MX Keys Mini` to do pairing. Still doesn't reconnect through the bonding process (connection recovery doesn't work, still investigating).
11
+
- BT keyboard `Logitech K380` works well in both pairing and bonding (recovering after signal lost or ESP32 reboot).
12
+
- Apple Wireless keyboard not working
13
+
14
+
----
6
15
7
16
This is a demonstration of an external Bluetooth keyboard sending characters to an ESP32. The code is mainly based on the ESP-IDF's bluetooth/esp_hid_host example, packaged into a class with added support for easier integration with a user application.
8
17
9
-
Please look at the `main/main.cpp` file on how to use the class. Note that only one instance of the class can be used.
18
+
Please look at the `main/main.cpp` file on how to use the class. Only one instance of the class should be used to avoid conflicts and resource limitations within the Bluetooth stack.
19
+
20
+
The class named BTKeyboard waits for a keyboard to be available for pairing through the `BTKeyboard::devices_scan()` method (must be called by the application). It will then accumulate scan codes in a queue to be processed. The class methods available allow for:
21
+
- Retrieval of the low-level key scan codes transmitted by the keyboard (`bool wait_for_low_event(BTKeyboard::KeyInfo & inf)` method)
22
+
- Retrieval of the ASCII characters augmented with function keys values (`char wait_for_ascii_char()` or `char get_ascii_char()` methods)
10
23
11
-
The class named BTKeyboard waits for a keyboard to be available for pairing through the `BTKeyboard::devices_scan()` method (must be called by the application). It will then cumulate scan codes in a queue to be processed. The class methods available allow for the retrieval of the low-level key scan codes transmitted by the keyboard (`bool wait_for_low_event(BTKeyboard::KeyInfo & inf)` method) or the ASCII characters augmented with function keys values (`char wait_for_ascii_char()` or `char get_ascii_char()` methods). The following list the character values returned (support of other keyboard keys may be added in a future release):
24
+
The following list the character values returned (support of other keyboard keys may be added in a future release):
12
25
13
26
| Values | Description |
14
27
|:-----------:|------------------|
@@ -35,38 +48,41 @@ The class named BTKeyboard waits for a keyboard to be available for pairing thro
35
48
| 0x97 | DownArrow key |
36
49
| 0x98 | UpArrow key |
37
50
38
-
The returned scan codes in the BTKeyboard::KeyInfo structure are defined in chapter 10 of https://usb.org/sites/default/files/hut1_22.pdf and are usually supplied directly by the keyboard. The BTKeyboard class supports up to three keys pressed at the same time. The corresponging scan codes are located in the `keys[3]` field. The `modifier` field contains the CTRL/SHIFT/ALT/META left and right key modifier info.
51
+
The returned scan codes in the BTKeyboard::KeyInfo structure are defined in chapter 10 of the [USB HID Usage Tables document](https://usb.org/sites/default/files/hut1_22.pdf) and are typically provided directly by the keyboard. The BTKeyboard class supports up to three keys pressed at the same time. The corresponding scan codes are located in the `keys_data` field. The `modifier` field contains the CTRL/SHIFT/ALT/META left and right key modifier info.
52
+
53
+
The main program is a simple demonstration of the usage of the class. The author is using a Logitech K380 (standard Bluetooth keyboard, not a BLE) and the recent Logitech MX Keys Mini (BLE) keyboards for this demo. Other Bluetooth keyboards may work but may require some modification (mainly adding other key scan codes).
39
54
40
-
The main program is a simple demonstration of the usage of the class. The author is using a Logitech K380 keyboard (standard Bluetooth keyboard, not a BLE) for this demo. Other Bluetooth keyboards may work but may require some modification (mainly adding other key scan codes).
55
+
The first-generation Apple wireless keyboard is known to not function correctly.
41
56
42
-
The `sdkconfig.defaults` file identifies the ESP-IDF sdkconfig parameters that are required to have this demo working.
57
+
The `sdkconfig.defaults` file specifies the ESP-IDF sdkconfig parameters required for this demo to work.
43
58
44
-
A bug with ESP-IDF 4.3.x may cause an internal stack overflow. Seems to be corrected in 4.4.
59
+
A bug in `ESP-IDF 4.3.x` may cause an internal stack overflow due to improper Bluetooth stack resource handling. This issue has been fixed in `ESP-IDF 4.4`.
45
60
46
-
This is not ready yet as testing with ESP-IDF 4.4 is ongoing. Seems to work fine at this point in time.
61
+
Testing with `ESP-IDF V5.4` appears to be stable.
47
62
48
-
Please be sure that you have installed the ESP-IDF v4.4 (examples are for Linux/MacOS):
63
+
Ensure that you have installed ESP-IDF V4.4 or later (example provided is for Linux/MacOS and V5.4):
0 commit comments