/// <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> /// Gets the list of connected controllers /// </summary> /// <returns>The list of controllers handled by this class.</returns> internal static Dictionary <Guid, Controller> GetControllers() { for (int i = 0; i < 10; i++) { Guid guid = Joystick.GetGuid(i); string id = GetControllerID(guid); string name = Joystick.GetName(i); bool comboDpad = name == "TAITO Densha de Go! Plug & Play"; if (!cachedControllers.ContainsKey(guid)) { // DGC-255/DGOC-44U/P&P if (id == "0ae4:0003") { ControllerButtons buttons = ControllerButtons.Select | ControllerButtons.Start | ControllerButtons.A | ControllerButtons.B | ControllerButtons.C | ControllerButtons.D; if (Joystick.GetCapabilities(i).HatCount > 0 || comboDpad) { // DGC-255 and P&P have a D-pad buttons = buttons | ControllerButtons.DPad; } int[] buttonIndices = { 4, 5, 1, 0, 2, 3, -1, -1 }; byte[] brakeBytes = { 0x78, 0x7A, 0x89, 0x8B, 0x93, 0x95, 0x99, 0x9B, 0xA1, 0xA3, 0xA7, 0xA9, 0xAE, 0xB0, 0xB1, 0xB3, 0xB4, 0xB6, 0xB8, 0xBA }; byte[] powerBytes = { 0x80, 0x82, 0x6C, 0x6E, 0x53, 0x55, 0x3E, 0x40, 0x20, 0x22, 0x0, 0x2 }; UnbalanceController newcontroller = new UnbalanceController(buttons, buttonIndices, comboDpad, brakeBytes, powerBytes) { Guid = guid, Id = id, joystickIndex = i, ControllerName = name, IsConnected = true }; cachedControllers.Add(guid, newcontroller); } // DRC-184/DYC-288 if (id == "0ae4:0008") { ControllerButtons buttons = ControllerButtons.Select | ControllerButtons.Start | ControllerButtons.A | ControllerButtons.B | ControllerButtons.C | ControllerButtons.D | ControllerButtons.LDoor | ControllerButtons.RDoor | ControllerButtons.DPad; int[] buttonIndices = { 5, 6, 2, 1, 0, -1, 4, 3 }; byte[] brakeBytes = { 0x23, 0x2C, 0x2D, 0x3E, 0x3F, 0x4E, 0x4F, 0x63, 0x64, 0x8A, 0x8B, 0xB0, 0xB1, 0xD4, 0xD5, 0xDF }; byte[] powerBytes = { 0x0, 0x2, 0x3B, 0x3D, 0x77, 0x79, 0xB3, 0xB5, 0xEF, 0xF1 }; UnbalanceController newcontroller = new UnbalanceController(buttons, buttonIndices, comboDpad, brakeBytes, powerBytes) { Guid = guid, Id = id, joystickIndex = i, ControllerName = name, IsConnected = true }; cachedControllers.Add(guid, newcontroller); } } else { // Cached controller, update it ((UnbalanceController)cachedControllers[guid]).joystickIndex = i; // HACK: IsConnected is broken, we check the capabilities instead to know if the controller is connected or not cachedControllers[guid].IsConnected = Joystick.GetCapabilities(i).ButtonCount > 0; } } return(cachedControllers); }