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:
0:bd0f6bf72a8b
Child:
1:5bb153989f33
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHostXpad.h	Tue Dec 10 06:50:37 2013 +0000
@@ -0,0 +1,106 @@
+/*
+ * Xbox 360 Wireless Controller for Windows library
+ * for mbed USBHost library
+ * Copyright (c) 2013 Hiroshi Suga
+ *
+ * VID=0x045e PID=0x0719
+ */
+
+#ifndef USBHostXpad_H
+#define USBHostXpad_H
+
+#include "USBHostConf.h"
+
+#if 1 or USBHOST_XPAD
+
+#include "USBHost.h"
+
+#define XPAD_HAT_TOP    0x0001
+#define XPAD_HAT_BOTTOM 0x0002
+#define XPAD_HAT_LEFT   0x0004
+#define XPAD_HAT_RIGHT  0x0008
+#define XPAD_START      0x0010
+#define XPAD_BACK       0x0020
+#define XPAD_ANALOG_L   0x0040
+#define XPAD_ANALOG_R   0x0080
+#define XPAD_PAD_LB     0x0100
+#define XPAD_PAD_RB     0x0200
+#define XPAD_XLOGO      0x0400
+#define XPAD_PAD_A      0x1000
+#define XPAD_PAD_B      0x2000
+#define XPAD_PAD_X      0x4000
+#define XPAD_PAD_Y      0x8000
+
+/** 
+ * A class to communicate a USB flash disk
+ */
+class USBHostXpad : public IUSBEnumerator {
+public:
+    /**
+    * Constructor
+    *
+    * @param rootdir mount name
+    */
+    USBHostXpad();
+
+    /**
+    * Check if a MSD device is connected
+    *
+    * @return true if a MSD device is connected
+    */
+    bool connected();
+
+    /**
+     * Try to connect to a MSD device
+     *
+     * @return true if connection was successful
+     */
+    bool connect();
+
+    /**
+     * Attach a callback called when a mouse event is received
+     *
+     * @param ptr function pointer
+     */
+    inline void attachEvent(void (*ptr)(int buttons, int stick_lx, int stick_ly, int stick_rx, int stick_ry, int trigger_l, int trigger_r)) {
+        if (ptr != NULL) {
+            onUpdate = ptr;
+        }
+    }
+
+    bool effect(uint8_t strong, uint8_t weak);
+
+    void poll ();
+
+protected:
+    //From IUSBEnumerator
+    virtual void setVidPid(uint16_t vid, uint16_t pid);
+    virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
+    virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
+
+private:
+    USBHost * host;
+    USBDeviceConnected * dev;
+    bool dev_connected;
+
+    USBEndpoint * int_in;
+    USBEndpoint * int_out;
+    uint8_t nb_ep;
+    int xpad_intf;
+    bool xpad_device_found;
+    uint8_t report[32];
+
+    uint32_t buttons;
+    int16_t stick_lx, stick_ly, stick_rx, stick_ry;
+    uint8_t trigger_l, trigger_r;
+
+    void rxHandler();
+    void (*onUpdate)(int buttons, int stick_lx, int stick_ly, int stick_rx, int stick_ry, int trigger_l, int trigger_r);
+    void init();
+    bool probe(int val1, int val2, int val3, int val4);
+
+};
+
+#endif
+
+#endif