Ejemplo n.º 1
0
 /// <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;
         }
     }
 }
Ejemplo n.º 2
0
        /// <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);

                if (!cachedControllers.ContainsKey(guid))
                {
                    // ZKNS-001
                    if (id == "0f0d:00c1")
                    {
                        ControllerButtons buttons       = ControllerButtons.Select | ControllerButtons.Start | ControllerButtons.A | ControllerButtons.B | ControllerButtons.C | ControllerButtons.D | ControllerButtons.LDoor | ControllerButtons.RDoor | ControllerButtons.DPad;
                        int[]             buttonIndices = { 8, 9, 0, 1, 2, 3, 4, 5 };
                        byte[]            brakeBytes    = { 0x7F, 0x81, 0x64, 0x66, 0x56, 0x58, 0x48, 0x4A, 0x3B, 0x3D, 0x2D, 0x2F, 0x1F, 0x21, 0x12, 0x14, 0x04, 0x06, 0x0, 0x1 };
                        byte[]            powerBytes    = { 0x7F, 0x81, 0x9E, 0xA0, 0xB6, 0xB8, 0xCD, 0xCF, 0xE5, 0xE7, 0xFE, 0xFF };
                        ZuikiController   newcontroller = new ZuikiController(buttons, buttonIndices, brakeBytes, powerBytes)
                        {
                            Guid           = guid,
                            Id             = id,
                            joystickIndex  = i,
                            ControllerName = name,
                            IsConnected    = true
                        };
                        cachedControllers.Add(guid, newcontroller);
                    }
                }
                else
                {
                    // Cached controller, update it
                    ((ZuikiController)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);
        }