Xbox 360 Wireless Controller for Windows library. sample: http://mbed.org/users/okini3939/code/USBHostXpad_HelloWorld/

Dependents:   USBHostXpad_HelloWorld USBHostXpad_HelloWorld

Xbox 360 Wireless Controller for Windows

Microsoftの XBOX 360 ワイヤレスコントローラーを、パソコン用のUSB接続型レシーバーで mbed に接続して使えるライブラリです。

USB Host 機能を使いますので mbed LPC1768 専用です。

たまに処理が停止する不具合があります。

/media/uploads/samux/usb_host_schema.jpg

Revision:
2:2749f4e649db
Parent:
1:5bb153989f33
Child:
3:53ce7778a155
--- a/USBHostXpad.cpp	Wed Dec 11 04:11:04 2013 +0000
+++ b/USBHostXpad.cpp	Wed Dec 11 05:03:05 2013 +0000
@@ -69,7 +69,7 @@
                 host->interruptRead(dev, int_in, report, int_in->getSize(), false);
 
                 Thread::wait(100);
-                led(XPAD_LED_OFF);
+                led(LED_OFF);
                 dev_connected = true;
                 return true;
             }
@@ -97,7 +97,7 @@
     } else
     if (report[0] == 0x00 && report[1] == 0x0f) {
         // On connection
-        led(XPAD_LED1_ON);
+        led(LED1_ON);
         send(0x00, 0x00, 0x00, 0x40);
         goto exit;
     } else
@@ -167,7 +167,10 @@
 
 void USBHostXpad::restart ()
 {
-    send(0x08, 0x00, 0x0f, 0xc0);
+    if (send(0x08, 0x00, 0x0f, 0xc0) == false) {
+        init();
+        return;
+    }
     send(0x08, 0x00, 0x0f, 0xc0);
     send(0x08, 0x00, 0x0f, 0xc0);
     send(0x08, 0x00, 0x0f, 0xc0);
@@ -190,7 +193,26 @@
     return true;
 }
 
-bool USBHostXpad::led(int cmd)
+int USBHostXpad::read (TYPE type) {
+    switch (type) {
+    case XPAD_STICK_LX:
+        return stick_lx;
+    case XPAD_STICK_LY:
+        return stick_ly;
+    case XPAD_STICK_RX:
+        return stick_rx;
+    case XPAD_STICK_RY:
+        return stick_ry;
+    case XPAD_TRIGGER_L:
+        return trigger_l;
+    case XPAD_TRIGGER_R:
+        return trigger_r;
+    default:
+        return (buttons & type) ? 1 : 0;
+    }
+}
+
+bool USBHostXpad::led(LED cmd)
 {
     unsigned char odata[32];
     memset(odata, 0, sizeof(odata));