Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBHostKeyboard_HelloWorld by
main.cpp@1:2063e3713a99, 2013-03-12 (annotated)
- Committer:
- samux
- Date:
- Tue Mar 12 17:28:12 2013 +0000
- Revision:
- 1:2063e3713a99
- Parent:
- 0:88d52e197201
- Child:
- 7:4e0c80b26ba6
use latest USBHost
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| samux | 0:88d52e197201 | 1 | #include "mbed.h" |
| samux | 0:88d52e197201 | 2 | #include "USBHostKeyboard.h" |
| samux | 0:88d52e197201 | 3 | |
| samux | 0:88d52e197201 | 4 | DigitalOut led(LED1); |
| samux | 0:88d52e197201 | 5 | |
| samux | 0:88d52e197201 | 6 | void onKey(uint8_t key) { |
| samux | 1:2063e3713a99 | 7 | printf("Key: %c\r\n", key); |
| samux | 0:88d52e197201 | 8 | } |
| samux | 0:88d52e197201 | 9 | |
| samux | 0:88d52e197201 | 10 | void keyboard_task(void const *) { |
| samux | 0:88d52e197201 | 11 | |
| samux | 0:88d52e197201 | 12 | USBHostKeyboard keyboard; |
| samux | 0:88d52e197201 | 13 | |
| samux | 0:88d52e197201 | 14 | while(1) { |
| samux | 0:88d52e197201 | 15 | // try to connect a USB keyboard |
| samux | 0:88d52e197201 | 16 | while(!keyboard.connect()) |
| samux | 0:88d52e197201 | 17 | Thread::wait(500); |
| samux | 0:88d52e197201 | 18 | |
| samux | 0:88d52e197201 | 19 | // when connected, attach handler called on keyboard event |
| samux | 0:88d52e197201 | 20 | keyboard.attach(onKey); |
| samux | 0:88d52e197201 | 21 | |
| samux | 0:88d52e197201 | 22 | // wait until the keyboard is disconnected |
| samux | 0:88d52e197201 | 23 | while(keyboard.connected()) |
| samux | 0:88d52e197201 | 24 | Thread::wait(500); |
| samux | 0:88d52e197201 | 25 | } |
| samux | 0:88d52e197201 | 26 | } |
| samux | 0:88d52e197201 | 27 | |
| samux | 0:88d52e197201 | 28 | int main() { |
| samux | 0:88d52e197201 | 29 | Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4); |
| samux | 0:88d52e197201 | 30 | while(1) { |
| samux | 0:88d52e197201 | 31 | led=!led; |
| samux | 0:88d52e197201 | 32 | Thread::wait(500); |
| samux | 0:88d52e197201 | 33 | } |
| samux | 0:88d52e197201 | 34 | } |
