Пример #1
0
 private void buttonCalibrate_Click(object sender, EventArgs e)
 {
     if (controllerList.Count == 0)
     {
         return;
     }
     Timer1.Stop();
     ClassicController.Calibrate();
     Timer1.Start();
 }
Пример #2
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;
         }
     }
 }
Пример #3
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))
                {
                    // A valid controller needs at least 12 buttons or 10 buttons plus a hat. If there are more than 20 buttons, the joystick is unlikely a valid controller.
                    JoystickCapabilities capabilities = Joystick.GetCapabilities(i);
                    if ((capabilities.ButtonCount >= 12 || (capabilities.ButtonCount >= 10 && capabilities.HatCount > 0)) && capabilities.ButtonCount <= 20)
                    {
                        ClassicController newcontroller = new ClassicController()
                        {
                            Guid           = guid,
                            Id             = id,
                            joystickIndex  = i,
                            ControllerName = name,
                            IsConnected    = true
                        };
                        cachedControllers.Add(guid, newcontroller);
                    }
                }
                else
                {
                    // Cached controller, update index
                    ((ClassicController)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);
        }