/// <summary> /// Refreshes the connected controllers. /// </summary> public static void RefreshControllers() { // PlayStation 2 controllers foreach (KeyValuePair <Guid, Controller> controller in Ps2Controller.GetControllers()) { if (!Controllers.ContainsKey(controller.Key)) { Controllers.Add(controller.Key, controller.Value); } else { Controllers[controller.Key] = controller.Value; } } // Unbalance controllers foreach (KeyValuePair <Guid, Controller> controller in UnbalanceController.GetControllers()) { if (!Controllers.ContainsKey(controller.Key)) { Controllers.Add(controller.Key, controller.Value); } else { Controllers[controller.Key] = controller.Value; } } // Zuiki controllers foreach (KeyValuePair <Guid, Controller> controller in ZuikiController.GetControllers()) { if (!Controllers.ContainsKey(controller.Key)) { Controllers.Add(controller.Key, controller.Value); } else { Controllers[controller.Key] = controller.Value; } } // Classic controllers, they need to be added last because we do not use VID/PID foreach (KeyValuePair <Guid, Controller> controller in ClassicController.GetControllers()) { if (!Controllers.ContainsKey(controller.Key)) { Controllers.Add(controller.Key, controller.Value); } else if (controller.GetType() == typeof(ClassicController)) { // Replace controller only if it is a classic controller Controllers[controller.Key] = controller.Value; } } }
/// <summary> /// Configures controller-specific settings on load. /// </summary> internal static void Load() { Ps2Controller.ConfigureControllers(); }
/// <summary> /// Gets the list of connected controllers /// </summary> /// <returns>The list of controllers handled by this class.</returns> internal static Dictionary <Guid, Controller> GetControllers() { foreach (KeyValuePair <Guid, LibUsb.UsbController> usbController in LibUsb.GetSupportedControllers()) { Guid guid = usbController.Key; string id = GetControllerID(guid); string name = usbController.Value.ControllerName; if (!cachedControllers.ContainsKey(guid)) { // TCPP-20009 (Type II) if (id == "0ae4:0004") { ControllerButtons buttons = ControllerButtons.Select | ControllerButtons.Start | ControllerButtons.A | ControllerButtons.B | ControllerButtons.C | ControllerButtons.D | ControllerButtons.Pedal | ControllerButtons.DPad; byte[] buttonBytes = { 0x10, 0x20, 0x2, 0x1, 0x4, 0x8, 0x0, 0x0 }; byte[] brakeBytes = { 0x79, 0x79, 0x8A, 0x8A, 0x94, 0x94, 0x9A, 0x9A, 0xA2, 0xA2, 0xA8, 0xA8, 0xAF, 0xAF, 0xB2, 0xB2, 0xB5, 0xB5, 0xB9, 0xB9 }; byte[] powerBytes = { 0x81, 0x81, 0x6D, 0x6D, 0x54, 0x54, 0x3F, 0x3F, 0x21, 0x21, 0x00, 0x00 }; Ps2Controller newcontroller = new Ps2Controller(buttons, buttonBytes, brakeBytes, powerBytes) { // 6 bytes for input, 2 for output Guid = guid, Id = id, ControllerName = name, inputBuffer = new byte[] { 0x1, 0x0, 0x0, 0xFF, 0x8, 0x0 }, outputBuffer = new byte[] { 0x0, 0x3 } }; cachedControllers.Add(guid, newcontroller); } // TCPP-20011 (Shinkansen) if (id == "0ae4:0005") { ControllerButtons buttons = ControllerButtons.Select | ControllerButtons.Start | ControllerButtons.A | ControllerButtons.B | ControllerButtons.C | ControllerButtons.D | ControllerButtons.Pedal | ControllerButtons.DPad; byte[] buttonBytes = { 0x10, 0x20, 0x8, 0x4, 0x2, 0x1, 0x0, 0x0 }; byte[] brakeBytes = { 0x1C, 0x1C, 0x38, 0x38, 0x54, 0x54, 0x70, 0x70, 0x8B, 0x8B, 0xA7, 0xA7, 0xC3, 0xC3, 0xDF, 0xDF, 0xFB, 0xFB }; byte[] powerBytes = { 0x12, 0x12, 0x24, 0x24, 0x36, 0x36, 0x48, 0x48, 0x5A, 0x5A, 0x6C, 0x6C, 0x7E, 0x7E, 0x90, 0x90, 0xA2, 0xA2, 0xB4, 0xB4, 0xC6, 0xC6, 0xD7, 0xD7, 0xE9, 0xE9, 0xFB, 0xFB }; Ps2Controller newcontroller = new Ps2Controller(buttons, buttonBytes, brakeBytes, powerBytes) { // 6 bytes for input, 8 for output Guid = guid, Id = id, ControllerName = name, inputBuffer = new byte[] { 0x0, 0x0, 0xFF, 0x8, 0x0, 0x0 }, outputBuffer = new byte[] { 0x0, 0x0, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF } }; cachedControllers.Add(guid, newcontroller); } // TCPP-20014 (Ryojouhen) if (id == "0ae4:0007") { ControllerButtons buttons = ControllerButtons.Select | ControllerButtons.Start | ControllerButtons.A | ControllerButtons.B | ControllerButtons.C | ControllerButtons.Pedal | ControllerButtons.LDoor | ControllerButtons.RDoor | ControllerButtons.DPad; byte[] buttonBytes = { 0x20, 0x40, 0x4, 0x2, 0x1, 0x0, 0x10, 0x8 }; byte[] brakeBytes = { 0x23, 0x2C, 0x2D, 0x3E, 0x3F, 0x4E, 0x4F, 0x63, 0x64, 0x8A, 0x8B, 0xB0, 0xB1, 0xD4, 0xD5, 0xDF }; byte[] powerBytes = { 0x0, 0x0, 0x3C, 0x3C, 0x78, 0x78, 0xB4, 0xB4, 0xF0, 0xF0 }; Ps2Controller newcontroller = new Ps2Controller(buttons, buttonBytes, brakeBytes, powerBytes) { // 8 bytes for input, no output Guid = guid, Id = id, ControllerName = name, inputBuffer = new byte[] { 0x0, 0x0, 0xFF, 0x8, 0x0, 0x0, 0x0, 0x0 }, outputBuffer = new byte[0] }; cachedControllers.Add(guid, newcontroller); } } // Update connection status and name cachedControllers[guid].IsConnected = usbController.Value.IsConnected; cachedControllers[guid].ControllerName = name; } return(cachedControllers); }