usb keyboard

Dependencies:   mbed USBHost

Files at this revision

API Documentation at this revision

Comitter:
duchonic
Date:
Thu Jul 25 06:52:50 2019 +0000
Commit message:
first

Changed in this revision

USBHost.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1c8a9f40d32c USBHost.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHost.lib	Thu Jul 25 06:52:50 2019 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/USBHost/#7c3b59bb364e
diff -r 000000000000 -r 1c8a9f40d32c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 25 06:52:50 2019 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "USBHostKeyboard.h"
+
+DigitalOut led(LED1);
+
+void onKey(uint8_t key) {
+    printf("Key: %c\r\n", key);
+}
+
+void keyboard_task(void const *) {
+    
+    USBHostKeyboard keyboard;
+    
+    while(1) {
+        // try to connect a USB keyboard
+        while(!keyboard.connect())
+            Thread::wait(500);
+    
+        // when connected, attach handler called on keyboard event
+        keyboard.attach(onKey);
+        
+        // wait until the keyboard is disconnected
+        while(keyboard.connected())
+            Thread::wait(500);
+    }
+}
+
+int main() {
+    Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);
+    while(1) {
+        led=!led;
+        Thread::wait(500);
+    }
+}
diff -r 000000000000 -r 1c8a9f40d32c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jul 25 06:52:50 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file