private void ReaderThread() { int count; // Maximum data is wMaxPacketSize XBoxJoystickData = new byte[XBoxInputPipe.PipeEndpoint.wMaxPacketSize]; // Read every bInterval while (true) { Thread.Sleep(XBoxInputPipe.PipeEndpoint.bInterval); count = 0; lock (XBoxJoystickData) { try { count = XBoxInputPipe.TransferData(XBoxJoystickData, 0, XBoxJoystickData.Length); } catch { USBH_ERROR e = USBHostController.GetLastError(); #if DEBUG Debug.Print("ERROR" + e); #endif Array.Clear(XBoxJoystickData, 0, XBoxJoystickData.Length); count = 0; } } //if (count > 3)//this is useful to print the data to help in reverse engineering if (false) { #if DEBUG // Debug.Print("(dx, dy) = (" + (sbyte)(XBOX_joustickData[1]) + ", " + (sbyte)(XBOX_joustickData[2]) + ")"); int i = 0; Debug.Print("=" + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) + " " + ByteToHex(XBoxJoystickData[i++]) ); /////////// RT LT analog ///////////////////// if (XBoxJoystickData[4] > 200) { Debug.Print("LT"); } if (XBoxJoystickData[5] > 200) { Debug.Print("RT"); } /////// left hat analog ////////////////// //if (XBOX_joustickData[6] > 200) // Debug.Print("LH x"); //if (XBOX_joustickData[8] > 200) // Debug.Print("LH y"); #endif } } }
/// <summary> /// Set the state of the LED on the Guide button. This is only supported on XBox 360 controllers, not classic XBox controllers. /// </summary> /// <param name="status">State for the button</param> public void SetLedState(Xbox360LedState status) { byte[] ledData = new byte[] { 0x01, 0x03, (byte)status }; try { XBoxOutputPipe.TransferData(ledData, 0, ledData.Length); } catch { USBH_ERROR e = USBHostController.GetLastError(); #if DEBUG Debug.Print("LED ERROR " + e); #endif } }
/// <summary> /// Set the rumble power. Note: You must have ~400mA of power for using rumble! /// </summary> /// <param name="left">Set the left (low frequency) power</param> /// <param name="right">Set the right (high frequency) power</param> public void SetRumblePower(byte left, byte right) { byte[] rumbleData = new byte[] { 0x00, 0x08, 0x00, left, right, 0x00, 0x00, 0x00 }; try { XBoxOutputPipe.TransferData(rumbleData, 0, rumbleData.Length); } catch { USBH_ERROR e = USBHostController.GetLastError(); #if DEBUG Debug.Print("RUMBLE ERROR " + e); #endif } }