USBHostGamepad library usage example

Dependencies:   USBHostGamepad mbed

Revision:
0:e0b65c2c3cc8
--- /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);
+    }
+}