HID-over-GATT implementation with the BLE API. This library allows to create devices such as mouse, keyboard or joystick, over Bluetooth Low Energy.
Dependents: BLENano_HID BLE_HID_MouseScrollDemo BLE_HID_KeyboardStreamDemo Shervs_TestKeyboard_TinyBLE ... more
KeyboardService Class Reference
HID-over-Gatt keyboard service. More...
#include <KeyboardService.h>
Inherits HIDServiceBase.
Public Member Functions | |
virtual ble_error_t | send (const report_t report) |
Send raw report. | |
ble_error_t | keyUpCode (void) |
Send an empty report, representing keyUp event. | |
ble_error_t | keyDownCode (uint8_t key, uint8_t modifier) |
Send a character, defined by a modifier (CTRL, SHIFT, ALT) and the key. | |
virtual int | _putc (int c) |
Push a key on the internal FIFO. | |
virtual void | sendCallback (void) |
Pop a key from the internal FIFO, and attempt to send it over BLE. | |
virtual void | onDataSent (unsigned count) |
Restart report ticker if it was disabled, after too many consecutive failures. | |
virtual ble_error_t | read (report_t report) |
Read Report. | |
Protected Member Functions | |
virtual void | startReportTicker (void) |
Start the ticker that sends input reports at regular interval. | |
virtual void | stopReportTicker (void) |
Stop the input report ticker. | |
GattAttribute ** | inputReportDescriptors () |
Create the Gatt descriptor for a report characteristic. | |
HID_information_t * | HIDInformation () |
Create the HID information structure. |
Detailed Description
HID-over-Gatt keyboard service.
Send keyboard reports over BLE. Users should rely on the high-level functions provided by the Stream API. Because we can't send batches of HID reports, we store pending keys in a circular buffer and rely on the report ticker to spread them over time.
BLE ble; KeyboardService kbd(ble); void once_connected_and_paired_callback(void) { // Sequentially send keys 'Shift'+'h', 'e', 'l', 'l', 'o', '!' and <enter> kbd.printf("Hello!\n"); }
Definition at line 183 of file KeyboardService.h.
Member Function Documentation
virtual int _putc | ( | int | c ) | [virtual] |
Push a key on the internal FIFO.
- Parameters:
-
c ASCII character to send
- Returns:
- 0 on success, or ENOMEM when the FIFO is full.
Definition at line 280 of file KeyboardService.h.
HID_information_t * HIDInformation | ( | ) | [protected, inherited] |
Create the HID information structure.
Definition at line 202 of file HIDServiceBase.cpp.
GattAttribute ** inputReportDescriptors | ( | ) | [protected, inherited] |
Create the Gatt descriptor for a report characteristic.
Definition at line 171 of file HIDServiceBase.cpp.
ble_error_t keyDownCode | ( | uint8_t | key, |
uint8_t | modifier | ||
) |
Send a character, defined by a modifier (CTRL, SHIFT, ALT) and the key.
- Parameters:
-
key Character to send (as defined in USB HID Usage Tables) modifier Optional modifiers (logical OR of enum MODIFIER_KEY)
- Returns:
- BLE_ERROR_NONE on success, or an error code otherwise.
Definition at line 265 of file KeyboardService.h.
ble_error_t keyUpCode | ( | void | ) |
Send an empty report, representing keyUp event.
Definition at line 252 of file KeyboardService.h.
virtual void onDataSent | ( | unsigned | count ) | [virtual] |
Restart report ticker if it was disabled, after too many consecutive failures.
This is called by the BLE stack.
- Parameters:
-
count Number of reports (notifications) sent
Definition at line 366 of file KeyboardService.h.
ble_error_t read | ( | report_t | report ) | [virtual, inherited] |
Read Report.
- Parameters:
-
report Report to fill. Must be of size outputReportLength
- Returns:
- The read status
Definition at line 214 of file HIDServiceBase.cpp.
virtual ble_error_t send | ( | const report_t | report ) | [virtual] |
Send raw report.
Should only be called by sendCallback.
Definition at line 218 of file KeyboardService.h.
virtual void sendCallback | ( | void | ) | [virtual] |
Pop a key from the internal FIFO, and attempt to send it over BLE.
keyUp reports should theoretically be sent after every keyDown, but we optimize the throughput by only sending one when strictly necessary:
- when we need to repeat the same key
- when there is no more key to report
In case of error, put the key event back in the buffer, and retry on next tick.
Definition at line 308 of file KeyboardService.h.
void startReportTicker | ( | void | ) | [protected, virtual, inherited] |
Start the ticker that sends input reports at regular interval.
- Note:
- reportTickerIsActive describes the state of the ticker and can be used by HIDS implementations.
Definition at line 155 of file HIDServiceBase.cpp.
void stopReportTicker | ( | void | ) | [protected, virtual, inherited] |
Stop the input report ticker.
Definition at line 162 of file HIDServiceBase.cpp.
Generated on Wed Jul 13 2022 08:13:42 by 1.7.2