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 Suga koubou

Committer:
okini3939
Date:
Tue Dec 10 06:53:49 2013 +0000
Revision:
9:16ce7a241108
Parent:
4:f8a5c8aa895a
Child:
10:4b0c8727f0c3
1st build

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 9:16ce7a241108 6
okini3939 9:16ce7a241108 7 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 8 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 9:16ce7a241108 9 }
okini3939 9:16ce7a241108 10
okini3939 9:16ce7a241108 11 void xpad_task(void const *) {
okini3939 9:16ce7a241108 12
okini3939 9:16ce7a241108 13 USBHostXpad xpad;
okini3939 9:16ce7a241108 14
okini3939 9:16ce7a241108 15 while(1) {
okini3939 9:16ce7a241108 16 // try to connect a Xbox 360 Wireless Controller
okini3939 9:16ce7a241108 17 while(!xpad.connect())
okini3939 9:16ce7a241108 18 Thread::wait(500);
okini3939 9:16ce7a241108 19
okini3939 9:16ce7a241108 20 // when connected, attach handler called on xpad event
okini3939 9:16ce7a241108 21 xpad.attachEvent(onXpadEvent);
okini3939 9:16ce7a241108 22
okini3939 9:16ce7a241108 23 // wait until the mouse is disconnected
okini3939 9:16ce7a241108 24 while(xpad.connected())
okini3939 9:16ce7a241108 25 Thread::wait(500);
okini3939 9:16ce7a241108 26 }
okini3939 9:16ce7a241108 27 }
okini3939 9:16ce7a241108 28
okini3939 9:16ce7a241108 29
okini3939 9:16ce7a241108 30 int main() {
okini3939 9:16ce7a241108 31 pc.baud(115200);
okini3939 9:16ce7a241108 32 pc.printf("----------\r\n");
okini3939 9:16ce7a241108 33 Thread xpadTask(xpad_task, NULL, osPriorityNormal, 1024 * 4);
okini3939 9:16ce7a241108 34 while(1) {
okini3939 9:16ce7a241108 35 led=!led;
okini3939 9:16ce7a241108 36 Thread::wait(500);
okini3939 9:16ce7a241108 37 }
okini3939 9:16ce7a241108 38 }
okini3939 9:16ce7a241108 39