Justin S / USBHostXpad

Dependents:   N64_Output_XPAD

Fork of USBHostXpad by Suga koubou

Revision:
5:e0ed758abbdb
Parent:
4:4254192898a9
Child:
6:954ecd99709c
--- a/USBHostXpad.cpp	Sat Feb 01 08:12:44 2014 +0000
+++ b/USBHostXpad.cpp	Fri Nov 04 21:29:16 2016 +0000
@@ -62,13 +62,13 @@
                 
                 if (!int_in || !int_out) continue;
 
-                USB_INFO("New MSD device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, xpad_intf);
+                USB_INFO("New Xpad device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, xpad_intf);
                 dev->setName("XPAD", xpad_intf);
                 host->registerDriver(dev, xpad_intf, this, &USBHostXpad::init);
                 int_in->attach(this, &USBHostXpad::rxHandler);
                 host->interruptRead(dev, int_in, report, int_in->getSize(), false);
 
-                Thread::wait(100);
+                wait_ms(100);
                 led(LED_OFF);
                 dev_connected = true;
                 return true;
@@ -84,17 +84,18 @@
     int len_listen = int_in->getSize();
     int len = int_in->getLengthTransferred();
 
-/*
-    for (int i = 0; i < len_listen; i ++) {
+
+    /*for (int i = 0; i < len_listen; i ++) {
         std::printf(" %02x", report[i]);
     }
-    std::printf("\r\n");
-*/
+    std::printf("\r\n");*/
+
+
     if (dev_type == TYPE_XBOX) {
         parseMessage();
     } else
     if (report[0] == 0x08) {
-        if (report[1] == 0x80) {
+        if (report[1] == 0x80 || /*x360 headset status*/report[1] == 0x80) {
             // Connection Status Messages
             start();
         } else
@@ -103,6 +104,15 @@
             dev_started = false;
         }
     } else
+    if (report[0] == 0x01) { // X360 led
+        ; // no need to do anything?
+    } else
+    if (report[0] == 0x02) { // X360 unknown
+        ; // no need to do anything?
+    } else
+    if (report[0] == 0x03) { // X360 rumble
+        ; // no need to do anything?
+    } else
     if (report[0] == 0x00) {
         if ((report[1] == 0x14) ||
             (report[1] == 0x01 && report[2] == 0x00 && report[3] == 0xf0)) {
@@ -144,7 +154,7 @@
     if (vid == 0x045e && (pid == 0x0202 || pid == 0x0285 || pid == 0x0287 || pid == 0x0289)) {
         dev_type = TYPE_XBOX;
     } else
-    if (vid == 0x045e && pid == 0x028e) {
+    if ((vid == 0x045e && pid == 0x028e) || /*my afterglow addition!*/(vid == 0x0e6f && pid == 0x0213)) {
         dev_type = TYPE_XBOX360;
     } else
     if (vid == 0x045e && pid == 0x0719) {
@@ -164,6 +174,10 @@
         xpad_intf = intf_nb; // XBOX360W
         return true;
     }
+    if ((xpad_intf == -1) && (intf_class == 0xff) && (intf_subclass == 0x5d) && (intf_protocol == 0x01)) {
+        xpad_intf = intf_nb; // XBOX360 WIRED AFTERGLOW
+        return true;
+    }
     return false;
 }
 
@@ -217,7 +231,7 @@
     default:
         return;
     }
-
+    
     if (onUpdate) {
         (*onUpdate)(buttons, stick_lx, stick_ly, stick_rx, stick_ry, trigger_l, trigger_r);
     }