Xbox 360 Wireless Controller for Windows library

Dependencies:   USBHost USBHostXpad mbed

Fork of USBHostMSD_HelloWorld by Samuel Mokrani

Xbox 360 Wireless Controller for Windows

Microsoftの XBOX 360 ワイヤレスコントローラーを、パソコン用のUSB接続型レシーバーで mbed に接続して使えるライブラリです。
ワイヤードのXBOX360コントローラーや、初代XBOXコントローラーのコードも含んでいますが未確認です。

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

たまに usb_thread could not read dev descr を出力して処理が停止する不具合があります。

/media/uploads/samux/usb_host_schema.jpg

Import libraryUSBHostXpad

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

Committer:
okini3939
Date:
Sat Feb 01 08:14:26 2014 +0000
Revision:
12:f6d7bcc93e97
Parent:
11:f76e120a8520
fix led

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 9:16ce7a241108 1 #include "mbed.h"
okini3939 9:16ce7a241108 2 #include "USBHostXpad.h"
okini3939 9:16ce7a241108 3
okini3939 9:16ce7a241108 4 Serial pc(USBTX, USBRX);
okini3939 9:16ce7a241108 5 DigitalOut led(LED1);
okini3939 10:4b0c8727f0c3 6 volatile int poll = 0;
okini3939 9:16ce7a241108 7
okini3939 9:16ce7a241108 8 void onXpadEvent (int buttons, int stick_lx, int stick_ly, int stick_rx, int stick_ry, int trigger_l, int trigger_r) {
okini3939 9:16ce7a241108 9 std::printf("Xpad: %04x %-5d %-5d %-5d %-5d %02x %02x\r\n", buttons, stick_lx, stick_ly, stick_rx, stick_ry, trigger_l, trigger_r);
okini3939 10:4b0c8727f0c3 10 poll = 0;
okini3939 9:16ce7a241108 11 }
okini3939 9:16ce7a241108 12
okini3939 9:16ce7a241108 13 void xpad_task(void const *) {
okini3939 9:16ce7a241108 14 USBHostXpad xpad;
okini3939 9:16ce7a241108 15
okini3939 9:16ce7a241108 16 while(1) {
okini3939 9:16ce7a241108 17 // try to connect a Xbox 360 Wireless Controller
okini3939 9:16ce7a241108 18 while(!xpad.connect())
okini3939 9:16ce7a241108 19 Thread::wait(500);
okini3939 9:16ce7a241108 20
okini3939 9:16ce7a241108 21 // when connected, attach handler called on xpad event
okini3939 9:16ce7a241108 22 xpad.attachEvent(onXpadEvent);
okini3939 10:4b0c8727f0c3 23
okini3939 11:f76e120a8520 24 xpad.led(USBHostXpad::LED_ROTATE);
okini3939 10:4b0c8727f0c3 25 Thread::wait(500);
okini3939 10:4b0c8727f0c3 26 xpad.rumble(0xff, 0);
okini3939 10:4b0c8727f0c3 27 Thread::wait(500);
okini3939 10:4b0c8727f0c3 28 xpad.rumble(0, 0xff);
okini3939 10:4b0c8727f0c3 29 Thread::wait(500);
okini3939 10:4b0c8727f0c3 30 xpad.rumble(0, 0);
okini3939 10:4b0c8727f0c3 31 Thread::wait(500);
okini3939 11:f76e120a8520 32 xpad.led(USBHostXpad::LED1_ON);
okini3939 10:4b0c8727f0c3 33
okini3939 9:16ce7a241108 34 // wait until the mouse is disconnected
okini3939 10:4b0c8727f0c3 35 while(xpad.connected()) {
okini3939 9:16ce7a241108 36 Thread::wait(500);
okini3939 10:4b0c8727f0c3 37 poll ++;
okini3939 10:4b0c8727f0c3 38 if (poll > 10) {
okini3939 10:4b0c8727f0c3 39 xpad.restart();
okini3939 10:4b0c8727f0c3 40 poll = 0;
okini3939 10:4b0c8727f0c3 41 }
okini3939 10:4b0c8727f0c3 42 }
okini3939 9:16ce7a241108 43 }
okini3939 9:16ce7a241108 44 }
okini3939 9:16ce7a241108 45
okini3939 9:16ce7a241108 46
okini3939 9:16ce7a241108 47 int main() {
okini3939 9:16ce7a241108 48 pc.baud(115200);
okini3939 9:16ce7a241108 49 pc.printf("----------\r\n");
okini3939 9:16ce7a241108 50 Thread xpadTask(xpad_task, NULL, osPriorityNormal, 1024 * 4);
okini3939 9:16ce7a241108 51 while(1) {
okini3939 9:16ce7a241108 52 led=!led;
okini3939 9:16ce7a241108 53 Thread::wait(500);
okini3939 9:16ce7a241108 54 }
okini3939 9:16ce7a241108 55 }
okini3939 9:16ce7a241108 56