Esempio n. 1
0
 public void Connect()
 {
     if (!_connected)
     {
         _directInput = new DirectInput();
         if (_joystickConfig.IsMapped())
         {
             var device = _directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly).FirstOrDefault(x => x.InstanceName.Equals(_joystickConfig.DeviceInstaceName));
             if (device == null)
             {
                 MessageBox.Show("The mapped joystick was not found. Please, delete joystickconfig.json in the application folder and restart application.");
                 _form.Close();
                 return;
             }
             _joystick  = new Joystick(_directInput, device.InstanceGuid);
             _connected = true;
         }
         else
         {
             var connectedsDevice = _directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
             foreach (var device in connectedsDevice)
             {
                 try
                 {
                     _joystick  = new Joystick(_directInput, device.InstanceGuid);
                     _connected = true;
                     break;
                 }
                 catch (DirectInputException ex)
                 {
                     Utils.ShowError($"It was impossible stablish connect with stick: {ex.Message}");
                 }
                 catch (Exception ex)
                 {
                     Utils.ShowError($"It was impossible stablish connect with stick: {ex.Message}");
                 }
             }
         }
         if (_connected)
         {
             _joystick.Acquire();
             _povSystem = _joystick.Capabilities.AxesCount > 4;
         }
     }
 }