A program to show the use of a wireless xbox 360 controller. Has details on what data is given out from the controller as well as normalized values for the triggers and sticks
Dependencies: USBHost USBHostXpad mbed
Fork of USBHostXpad_HelloWorld by
Diff: main.cpp
- Revision:
- 10:4b0c8727f0c3
- Parent:
- 9:16ce7a241108
- Child:
- 11:f76e120a8520
--- a/main.cpp Tue Dec 10 06:53:49 2013 +0000 +++ b/main.cpp Wed Dec 11 04:11:46 2013 +0000 @@ -3,13 +3,14 @@ Serial pc(USBTX, USBRX); DigitalOut led(LED1); +volatile int poll = 0; 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); + poll = 0; } void xpad_task(void const *) { - USBHostXpad xpad; while(1) { @@ -19,10 +20,26 @@ // when connected, attach handler called on xpad event xpad.attachEvent(onXpadEvent); - + + xpad.led(XPAD_LED_ROTATE); + Thread::wait(500); + xpad.rumble(0xff, 0); + Thread::wait(500); + xpad.rumble(0, 0xff); + Thread::wait(500); + xpad.rumble(0, 0); + Thread::wait(500); + xpad.led(XPAD_LED1_ON); + // wait until the mouse is disconnected - while(xpad.connected()) + while(xpad.connected()) { Thread::wait(500); + poll ++; + if (poll > 10) { + xpad.restart(); + poll = 0; + } + } } }