Xbox 360 Wireless Controller for Windows library
Dependencies: USBHost USBHostXpad mbed
Fork of USBHostMSD_HelloWorld by
Xbox 360 Wireless Controller for Windows
Microsoftの XBOX 360 ワイヤレスコントローラーを、パソコン用のUSB接続型レシーバーで mbed に接続して使えるライブラリです。
ワイヤードのXBOX360コントローラーや、初代XBOXコントローラーのコードも含んでいますが未確認です。
USB Host 機能を使いますので mbed LPC1768 専用です。
たまに usb_thread could not read dev descr を出力して処理が停止する不具合があります。
Import libraryUSBHostXpad
Xbox 360 Wireless Controller for Windows library. sample: http://mbed.org/users/okini3939/code/USBHostXpad_HelloWorld/
Revision 9:16ce7a241108, committed 2013-12-10
- Comitter:
- okini3939
- Date:
- Tue Dec 10 06:53:49 2013 +0000
- Parent:
- 8:758190c6c455
- Child:
- 10:4b0c8727f0c3
- Commit message:
- 1st build
Changed in this revision
--- a/USBHost.lib Thu Mar 14 14:23:42 2013 +0000 +++ b/USBHost.lib Tue Dec 10 06:53:49 2013 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/mbed_official/code/USBHost/#7671b6a8c363 +https://mbed.org/users/mbed_official/code/USBHost/#37c948cf0dbf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHostXpad.lib Tue Dec 10 06:53:49 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/okini3939/code/USBHostXpad/#bd0f6bf72a8b
--- a/main.cpp Thu Mar 14 14:23:42 2013 +0000 +++ b/main.cpp Tue Dec 10 06:53:49 2013 +0000 @@ -1,50 +1,39 @@ -#include "mbed.h" -#include "USBHostMSD.h" - -DigitalOut led(LED1); - -void msd_task(void const *) { - - USBHostMSD msd("usb"); - int i = 0; - - while(1) { - - // try to connect a MSD device - while(!msd.connect()) { - Thread::wait(500); - } - - // in a loop, append a file - // if the device is disconnected, we try to connect it again - while(1) { - - // append a file - FILE * fp = fopen("/usb/test1.txt", "a"); - - if (fp != NULL) { - fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++); - printf("Goodbye World!\r\n"); - fclose(fp); - } else { - printf("FILE == NULL\r\n"); - } - - Thread::wait(500); - - // if device disconnected, try to connect again - if (!msd.connected()) - break; - } - - } -} - - -int main() { - Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4); - while(1) { - led=!led; - Thread::wait(500); - } -} \ No newline at end of file +#include "mbed.h" +#include "USBHostXpad.h" + +Serial pc(USBTX, USBRX); +DigitalOut led(LED1); + +void onXpadEvent (int buttons, int stick_lx, int stick_ly, int stick_rx, int stick_ry, int trigger_l, int trigger_r) { + 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); +} + +void xpad_task(void const *) { + + USBHostXpad xpad; + + while(1) { + // try to connect a Xbox 360 Wireless Controller + while(!xpad.connect()) + Thread::wait(500); + + // when connected, attach handler called on xpad event + xpad.attachEvent(onXpadEvent); + + // wait until the mouse is disconnected + while(xpad.connected()) + Thread::wait(500); + } +} + + +int main() { + pc.baud(115200); + pc.printf("----------\r\n"); + Thread xpadTask(xpad_task, NULL, osPriorityNormal, 1024 * 4); + while(1) { + led=!led; + Thread::wait(500); + } +} +
--- a/mbed.bld Thu Mar 14 14:23:42 2013 +0000 +++ b/mbed.bld Tue Dec 10 06:53:49 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4096f863f923 \ No newline at end of file