|
| 1 | +# Summary |
| 2 | + |
| 3 | + Members | Descriptions |
| 4 | +--------------------------------|--------------------------------------------- |
| 5 | +`class ` [`USBHIDDevice`](#class_u_s_b_h_i_d_device) | Base class for USB HID devices. |
| 6 | +`class ` [`USBHIDKeyboard`](#class_u_s_b_h_i_d_keyboard) | [USBHIDKeyboard](#class_u_s_b_h_i_d_keyboard) class. |
| 7 | +`class ` [`USBHIDMouse`](#class_u_s_b_h_i_d_mouse) | [USBHIDMouse](#class_u_s_b_h_i_d_mouse) class. |
| 8 | +`struct ` [`HIDMouseEvent`](#struct_h_i_d_mouse_event) | Structure representing a mouse event. |
| 9 | + |
| 10 | +# class `USBHIDDevice` <a id="class_u_s_b_h_i_d_device" class="anchor"></a> |
| 11 | + |
| 12 | +Base class for USB HID devices. |
| 13 | + |
| 14 | +Provides common connection callback functionality for all HID devices. |
| 15 | + |
| 16 | +## Summary |
| 17 | + |
| 18 | + Members | Descriptions |
| 19 | +--------------------------------|--------------------------------------------- |
| 20 | +| [`USBHIDDevice`](#class_u_s_b_h_i_d_device_1a99831d39786cc0186e8c780c202f46da) | Construct a new [USBHIDDevice](#class_u_s_b_h_i_d_device) object. | |
| 21 | +| [`~USBHIDDevice`](#class_u_s_b_h_i_d_device_1a87b5400ec3747933d6c33204b7c9c7a2) | Destroy the [USBHIDDevice](#class_u_s_b_h_i_d_device) object. | |
| 22 | +| [`attachConnectionCallback`](#class_u_s_b_h_i_d_device_1a1a2c5b59829d743132ddc9435b70856d) | Attach a connection callback. | |
| 23 | +| [`handleConnection`](#class_u_s_b_h_i_d_device_1aea3e06465b67c0f523413d3a14ab5800) | Internal handler for connection events. | |
| 24 | +| [`isConnected`](#class_u_s_b_h_i_d_device_1a8e8cfdadc4556bdf301eea065d8c3262) | Check whether the device is connected. | |
| 25 | + |
| 26 | +## Members |
| 27 | + |
| 28 | +### `USBHIDDevice` <a id="class_u_s_b_h_i_d_device_1a99831d39786cc0186e8c780c202f46da" class="anchor"></a> |
| 29 | + |
| 30 | +```cpp |
| 31 | +USBHIDDevice() |
| 32 | +``` |
| 33 | + |
| 34 | +Construct a new [USBHIDDevice](#class_u_s_b_h_i_d_device) object. |
| 35 | + |
| 36 | +<hr /> |
| 37 | + |
| 38 | +### `~USBHIDDevice` <a id="class_u_s_b_h_i_d_device_1a87b5400ec3747933d6c33204b7c9c7a2" class="anchor"></a> |
| 39 | + |
| 40 | +```cpp |
| 41 | +virtual ~USBHIDDevice() |
| 42 | +``` |
| 43 | + |
| 44 | +Destroy the [USBHIDDevice](#class_u_s_b_h_i_d_device) object. |
| 45 | + |
| 46 | +<hr /> |
| 47 | + |
| 48 | +### `attachConnectionCallback` <a id="class_u_s_b_h_i_d_device_1a1a2c5b59829d743132ddc9435b70856d" class="anchor"></a> |
| 49 | + |
| 50 | +```cpp |
| 51 | +void attachConnectionCallback(HIDConnectionCallback connectionCallback) |
| 52 | +``` |
| 53 | +
|
| 54 | +Attach a connection callback. |
| 55 | +
|
| 56 | +#### Parameters |
| 57 | +* `connectionCallback` A callback function to be invoked when the device connects. |
| 58 | +<hr /> |
| 59 | +
|
| 60 | +### `handleConnection` <a id="class_u_s_b_h_i_d_device_1aea3e06465b67c0f523413d3a14ab5800" class="anchor"></a> |
| 61 | +
|
| 62 | +```cpp |
| 63 | +void handleConnection(HIDDeviceType deviceType) |
| 64 | +``` |
| 65 | + |
| 66 | +Internal handler for connection events. |
| 67 | + |
| 68 | +Called by the USB host callbacks to indicate a device connection. If the connected device type is not supported, an error is printed and execution halts. |
| 69 | + |
| 70 | +#### Parameters |
| 71 | +* `deviceType` The detected HID device type. |
| 72 | +<hr /> |
| 73 | + |
| 74 | +### `isConnected` <a id="class_u_s_b_h_i_d_device_1a8e8cfdadc4556bdf301eea065d8c3262" class="anchor"></a> |
| 75 | + |
| 76 | +```cpp |
| 77 | +inline bool isConnected() const |
| 78 | +``` |
| 79 | + |
| 80 | +Check whether the device is connected. |
| 81 | + |
| 82 | +#### Returns |
| 83 | +true if connected, false otherwise. |
| 84 | +<hr /> |
| 85 | + |
| 86 | +# class `USBHIDKeyboard` <a id="class_u_s_b_h_i_d_keyboard" class="anchor"></a> |
| 87 | + |
| 88 | +```cpp |
| 89 | +class USBHIDKeyboard |
| 90 | + : public USBHIDDevice |
| 91 | + : public Stream |
| 92 | +``` |
| 93 | +
|
| 94 | +[USBHIDKeyboard](#class_u_s_b_h_i_d_keyboard) class. |
| 95 | +
|
| 96 | +Inherits from [USBHIDDevice](#class_u_s_b_h_i_d_device) and Arduino's Stream interface. It buffers incoming keystrokes so that they can be read via the stream API and also raises an event callback for each key press. |
| 97 | +
|
| 98 | +## Summary |
| 99 | +
|
| 100 | + Members | Descriptions |
| 101 | +--------------------------------|--------------------------------------------- |
| 102 | +| [`USBHIDKeyboard`](#class_u_s_b_h_i_d_keyboard_1a71b6c823bd4b3943efd3561ddf50a1cc) | Construct a new [USBHIDKeyboard](#class_u_s_b_h_i_d_keyboard) object. | |
| 103 | +| [`begin`](#class_u_s_b_h_i_d_keyboard_1a6e8c1d8bb99e32b158f3ccca4f4876ae) | Initialize the keyboard subsystem. | |
| 104 | +| [`poll`](#class_u_s_b_h_i_d_keyboard_1a7e5675d35163eaf611e3d4f560c935f5) | Poll for USB events. | |
| 105 | +| [`attachKeyboardEventCallback`](#class_u_s_b_h_i_d_keyboard_1ae5f780d5b42191dc6fbb2804bfc4d8ed) | Attach a keyboard event callback. | |
| 106 | +| [`handleKey`](#class_u_s_b_h_i_d_keyboard_1a302c35210ccb0d0c853f26ef3713360e) | Internal handler for a new key event from USB. | |
| 107 | +| [`available`](#class_u_s_b_h_i_d_keyboard_1a2dd03cc0280dde2973b2d1a9132460f7) | Return the number of characters available in the buffer. | |
| 108 | +| [`read`](#class_u_s_b_h_i_d_keyboard_1a8f037af0b1d434b3d95d72d03106a4e8) | Read the next character from the buffer. | |
| 109 | +| [`peek`](#class_u_s_b_h_i_d_keyboard_1a112c43dc0d4762b166d5f0c91b7dfca0) | Peek at the next character without removing it from the buffer. | |
| 110 | +| [`flush`](#class_u_s_b_h_i_d_keyboard_1ace1e9fdf6459cf7f05595c3579c65792) | Flush the internal buffer. | |
| 111 | +| [`write`](#class_u_s_b_h_i_d_keyboard_1a9ecf8198b596c0f5fc1ef4ca28272e79) | Write is not supported. | |
| 112 | +
|
| 113 | +## Members |
| 114 | +
|
| 115 | +### `USBHIDKeyboard` <a id="class_u_s_b_h_i_d_keyboard_1a71b6c823bd4b3943efd3561ddf50a1cc" class="anchor"></a> |
| 116 | +
|
| 117 | +```cpp |
| 118 | +USBHIDKeyboard() |
| 119 | +``` |
| 120 | + |
| 121 | +Construct a new [USBHIDKeyboard](#class_u_s_b_h_i_d_keyboard) object. |
| 122 | + |
| 123 | +<hr /> |
| 124 | + |
| 125 | +### `begin` <a id="class_u_s_b_h_i_d_keyboard_1a6e8c1d8bb99e32b158f3ccca4f4876ae" class="anchor"></a> |
| 126 | + |
| 127 | +```cpp |
| 128 | +void begin() |
| 129 | +``` |
| 130 | + |
| 131 | +Initialize the keyboard subsystem. |
| 132 | + |
| 133 | +Should be called in setup(). |
| 134 | +<hr /> |
| 135 | + |
| 136 | +### `poll` <a id="class_u_s_b_h_i_d_keyboard_1a7e5675d35163eaf611e3d4f560c935f5" class="anchor"></a> |
| 137 | + |
| 138 | +```cpp |
| 139 | +void poll() |
| 140 | +``` |
| 141 | + |
| 142 | +Poll for USB events. |
| 143 | + |
| 144 | +Should be called repeatedly in loop(). |
| 145 | +<hr /> |
| 146 | + |
| 147 | +### `attachKeyboardEventCallback` <a id="class_u_s_b_h_i_d_keyboard_1ae5f780d5b42191dc6fbb2804bfc4d8ed" class="anchor"></a> |
| 148 | + |
| 149 | +```cpp |
| 150 | +void attachKeyboardEventCallback(KeyboardEventCallback keyboardEventCallback) |
| 151 | +``` |
| 152 | +
|
| 153 | +Attach a keyboard event callback. |
| 154 | +
|
| 155 | +#### Parameters |
| 156 | +* `keyboardEventCallback` The callback function to be invoked for every key event. |
| 157 | +<hr /> |
| 158 | +
|
| 159 | +### `handleKey` <a id="class_u_s_b_h_i_d_keyboard_1a302c35210ccb0d0c853f26ef3713360e" class="anchor"></a> |
| 160 | +
|
| 161 | +```cpp |
| 162 | +void handleKey(uint8_t key) |
| 163 | +``` |
| 164 | + |
| 165 | +Internal handler for a new key event from USB. |
| 166 | + |
| 167 | +Called by the USB host callback when a new key is received. |
| 168 | + |
| 169 | +#### Parameters |
| 170 | +* `key` The ASCII value of the key. |
| 171 | +<hr /> |
| 172 | + |
| 173 | +### `available` <a id="class_u_s_b_h_i_d_keyboard_1a2dd03cc0280dde2973b2d1a9132460f7" class="anchor"></a> |
| 174 | + |
| 175 | +```cpp |
| 176 | +virtual int available() |
| 177 | +``` |
| 178 | + |
| 179 | +Return the number of characters available in the buffer. |
| 180 | + |
| 181 | +#### Returns |
| 182 | +int Number of available characters. |
| 183 | +<hr /> |
| 184 | + |
| 185 | +### `read` <a id="class_u_s_b_h_i_d_keyboard_1a8f037af0b1d434b3d95d72d03106a4e8" class="anchor"></a> |
| 186 | + |
| 187 | +```cpp |
| 188 | +virtual int read() |
| 189 | +``` |
| 190 | + |
| 191 | +Read the next character from the buffer. |
| 192 | + |
| 193 | +#### Returns |
| 194 | +int The next character, or -1 if none available. |
| 195 | +<hr /> |
| 196 | + |
| 197 | +### `peek` <a id="class_u_s_b_h_i_d_keyboard_1a112c43dc0d4762b166d5f0c91b7dfca0" class="anchor"></a> |
| 198 | + |
| 199 | +```cpp |
| 200 | +virtual int peek() |
| 201 | +``` |
| 202 | + |
| 203 | +Peek at the next character without removing it from the buffer. |
| 204 | + |
| 205 | +#### Returns |
| 206 | +int The next character, or -1 if none available. |
| 207 | +<hr /> |
| 208 | + |
| 209 | +### `flush` <a id="class_u_s_b_h_i_d_keyboard_1ace1e9fdf6459cf7f05595c3579c65792" class="anchor"></a> |
| 210 | + |
| 211 | +```cpp |
| 212 | +virtual void flush() |
| 213 | +``` |
| 214 | + |
| 215 | +Flush the internal buffer. |
| 216 | + |
| 217 | +<hr /> |
| 218 | + |
| 219 | +### `write` <a id="class_u_s_b_h_i_d_keyboard_1a9ecf8198b596c0f5fc1ef4ca28272e79" class="anchor"></a> |
| 220 | + |
| 221 | +```cpp |
| 222 | +virtual size_t write(uint8_t c) |
| 223 | +``` |
| 224 | +
|
| 225 | +Write is not supported. |
| 226 | +
|
| 227 | +#### Parameters |
| 228 | +* `c` Character to write. |
| 229 | +
|
| 230 | +#### Returns |
| 231 | +size_t Always returns 0. |
| 232 | +<hr /> |
| 233 | +
|
| 234 | +# class `USBHIDMouse` <a id="class_u_s_b_h_i_d_mouse" class="anchor"></a> |
| 235 | +
|
| 236 | +```cpp |
| 237 | +class USBHIDMouse |
| 238 | + : public USBHIDDevice |
| 239 | +``` |
| 240 | + |
| 241 | +[USBHIDMouse](#class_u_s_b_h_i_d_mouse) class. |
| 242 | + |
| 243 | +Inherits from [USBHIDDevice](#class_u_s_b_h_i_d_device). Converts incoming mouse reports into [HIDMouseEvent](#struct_h_i_d_mouse_event) structures and dispatches them via a user-defined callback. |
| 244 | + |
| 245 | +## Summary |
| 246 | + |
| 247 | + Members | Descriptions |
| 248 | +--------------------------------|--------------------------------------------- |
| 249 | +| [`USBHIDMouse`](#class_u_s_b_h_i_d_mouse_1a24f491506148b7c334e7ff7acc8df1ce) | Construct a new [USBHIDMouse](#class_u_s_b_h_i_d_mouse) object. | |
| 250 | +| [`begin`](#class_u_s_b_h_i_d_mouse_1af4f5212531f4334450a8afa30499f773) | Initialize the mouse subsystem. | |
| 251 | +| [`poll`](#class_u_s_b_h_i_d_mouse_1a6896edf4fc8de719180218dbd71e1e55) | Poll for USB events. | |
| 252 | +| [`attachMouseEventCallback`](#class_u_s_b_h_i_d_mouse_1acb41fb77e1ff5bafce0a90742b99b93e) | Attach a mouse event callback. | |
| 253 | +| [`handleMouseEvent`](#class_u_s_b_h_i_d_mouse_1a11cbb10b2a32bf5c6f1fad73297e364d) | Internal handler for a new mouse event. | |
| 254 | + |
| 255 | +## Members |
| 256 | + |
| 257 | +### `USBHIDMouse` <a id="class_u_s_b_h_i_d_mouse_1a24f491506148b7c334e7ff7acc8df1ce" class="anchor"></a> |
| 258 | + |
| 259 | +```cpp |
| 260 | +USBHIDMouse() |
| 261 | +``` |
| 262 | + |
| 263 | +Construct a new [USBHIDMouse](#class_u_s_b_h_i_d_mouse) object. |
| 264 | + |
| 265 | +<hr /> |
| 266 | + |
| 267 | +### `begin` <a id="class_u_s_b_h_i_d_mouse_1af4f5212531f4334450a8afa30499f773" class="anchor"></a> |
| 268 | + |
| 269 | +```cpp |
| 270 | +void begin() |
| 271 | +``` |
| 272 | + |
| 273 | +Initialize the mouse subsystem. |
| 274 | + |
| 275 | +Should be called in setup(). |
| 276 | +<hr /> |
| 277 | + |
| 278 | +### `poll` <a id="class_u_s_b_h_i_d_mouse_1a6896edf4fc8de719180218dbd71e1e55" class="anchor"></a> |
| 279 | + |
| 280 | +```cpp |
| 281 | +void poll() |
| 282 | +``` |
| 283 | + |
| 284 | +Poll for USB events. |
| 285 | + |
| 286 | +Should be called repeatedly in loop(). |
| 287 | +<hr /> |
| 288 | + |
| 289 | +### `attachMouseEventCallback` <a id="class_u_s_b_h_i_d_mouse_1acb41fb77e1ff5bafce0a90742b99b93e" class="anchor"></a> |
| 290 | + |
| 291 | +```cpp |
| 292 | +void attachMouseEventCallback(MouseEventCallback mouseEventCallback) |
| 293 | +``` |
| 294 | +
|
| 295 | +Attach a mouse event callback. |
| 296 | +
|
| 297 | +#### Parameters |
| 298 | +* `mouseEventCallback` The callback function to be invoked for each mouse event. |
| 299 | +<hr /> |
| 300 | +
|
| 301 | +### `handleMouseEvent` <a id="class_u_s_b_h_i_d_mouse_1a11cbb10b2a32bf5c6f1fad73297e364d" class="anchor"></a> |
| 302 | +
|
| 303 | +```cpp |
| 304 | +void handleMouseEvent(const HIDMouseEvent & mouseEvent) |
| 305 | +``` |
| 306 | + |
| 307 | +Internal handler for a new mouse event. |
| 308 | + |
| 309 | +Called by the USB host callback when a new mouse report is received. |
| 310 | + |
| 311 | +#### Parameters |
| 312 | +* `mouseEvent` The mouse event data. |
| 313 | +<hr /> |
| 314 | + |
| 315 | +# struct `HIDMouseEvent` <a id="struct_h_i_d_mouse_event" class="anchor"></a> |
| 316 | + |
| 317 | +Structure representing a mouse event. |
| 318 | + |
| 319 | +## Summary |
| 320 | + |
| 321 | + Members | Descriptions |
| 322 | +--------------------------------|--------------------------------------------- |
| 323 | +| [`buttons`](#struct_h_i_d_mouse_event_1af3129f12ed81c6efa68005235545db60) | Bitmask for mouse buttons (e.g., left, right, middle) | |
| 324 | +| [`xMovement`](#struct_h_i_d_mouse_event_1aa7143890ec68eefd60a5bd55e848f816) | Relative x movement. | |
| 325 | +| [`yMovement`](#struct_h_i_d_mouse_event_1a12bb38dcdd4bfdd0306cef7cf599ddd2) | Relative y movement. | |
| 326 | +| [`wheelMovement`](#struct_h_i_d_mouse_event_1af0734a85ac9f0089780ace5b9cc5d86e) | Wheel movement. | |
| 327 | + |
| 328 | +## Members |
| 329 | + |
| 330 | +### `buttons` <a id="struct_h_i_d_mouse_event_1af3129f12ed81c6efa68005235545db60" class="anchor"></a> |
| 331 | + |
| 332 | +```cpp |
| 333 | +uint8_t buttons |
| 334 | +``` |
| 335 | + |
| 336 | +Bitmask for mouse buttons (e.g., left, right, middle) |
| 337 | + |
| 338 | +<hr /> |
| 339 | + |
| 340 | +### `xMovement` <a id="struct_h_i_d_mouse_event_1aa7143890ec68eefd60a5bd55e848f816" class="anchor"></a> |
| 341 | + |
| 342 | +```cpp |
| 343 | +int16_t xMovement |
| 344 | +``` |
| 345 | + |
| 346 | +Relative x movement. |
| 347 | + |
| 348 | +<hr /> |
| 349 | + |
| 350 | +### `yMovement` <a id="struct_h_i_d_mouse_event_1a12bb38dcdd4bfdd0306cef7cf599ddd2" class="anchor"></a> |
| 351 | + |
| 352 | +```cpp |
| 353 | +int16_t yMovement |
| 354 | +``` |
| 355 | + |
| 356 | +Relative y movement. |
| 357 | + |
| 358 | +<hr /> |
| 359 | + |
| 360 | +### `wheelMovement` <a id="struct_h_i_d_mouse_event_1af0734a85ac9f0089780ace5b9cc5d86e" class="anchor"></a> |
| 361 | + |
| 362 | +```cpp |
| 363 | +int16_t wheelMovement |
| 364 | +``` |
| 365 | + |
| 366 | +Wheel movement. |
| 367 | + |
| 368 | +<hr /> |
| 369 | + |
0 commit comments