USBHostGamepad library usage example

Dependencies:   USBHostGamepad mbed

Files at this revision

API Documentation at this revision

Comitter:
abougouffa
Date:
Wed Dec 20 11:19:41 2017 +0000
Commit message:
USBHostGamepad example

Changed in this revision

USBHostGamepad.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHostGamepad.lib	Wed Dec 20 11:19:41 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/abougouffa/code/USBHostGamepad/#b12dbbe77a8a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 20 11:19:41 2017 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "USBHostGamepad.h"
+ 
+DigitalOut led(LED3);
+
+void onGamepadEvent(uint8_t x, uint8_t y, uint8_t z, uint8_t rz, uint16_t buttons) {
+    printf("x: %02X, y: %02X, z: %02X, rz: %02X, buttons: %04X\r\n",
+           x, y, z, rz, buttons);
+}
+ 
+void gamepad_task() {    
+    USBHostGamepad gamepad;
+    
+    while(1) {
+        // try to connect a USB Gamepad
+        while(!gamepad.connect())
+            Thread::wait(500);
+
+        // when connected, attach handler called on Gamepad event
+        gamepad.attachEvent(onGamepadEvent);
+        
+        // wait until the Gamepad is disconnected
+        while(gamepad.connected())
+            Thread::wait(500);
+    }
+}
+ 
+int main() {
+    Thread gamepadTask(osPriorityNormal, 1024 * 4);
+    gamepadTask.start(gamepad_task);
+
+    printf("MBED USB GAMEPAD\n\r");
+
+    while(1) {
+        led=!led;
+        Thread::wait(500);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Dec 20 11:19:41 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file