示例#1
0
 private void AddJoystick(WaitableJoystick joystick)
 {
     if (joystick.IsWaitable)
     {
         joysticksWaitable.Add(joystick);
         // Signal waiting thread that there are new Joysticks to wait on
         eventNewJoystick.Set();
     }
     else
     {
         joysticksPolled.Add(joystick);
     }
 }
示例#2
0
        /// <summary>
        /// Enumerates devices and adds them to Joysticks if not already present.
        /// </summary>
        private void UpdateConnectedDeviceList()
        {
            List <DeviceInstance> devices = GetDevices();

            if (devices.Count > GetConnectedCount())
            {
                foreach (DeviceInstance device in devices)
                {
                    if (!IsDeviceConnected(device))
                    {
                        bool connected = false;
#pragma warning disable IDE0068 // Use recommended dispose pattern: Can't be disposed until enclosing DirectInputManager is disposed.
                        WaitableJoystick joystick = CreateJoystick(device);
#pragma warning restore IDE0068 // Use recommended dispose pattern

                        try
                        {
                            if (null != joystick)
                            {
                                joystick.Connect();
                                connected = true;

                                AddJoystick(joystick);
                                PublishControllerListChanged();

                                Logger.Info("Connected " + joystick.Information.Type + ": " + joystick.Information.InstanceName);
                            }
                        }
                        catch (SharpDXException dxException)
                        {
                            Logger.Error("SharpDXException during construction / connection of Device " + device.InstanceName + ": ", dxException);
                        }
                        finally
                        {
                            // Something went wrong during creation process,
                            // so dispose of partially created object
                            if (!connected && joystick != null)
                            {
                                joystick.Dispose();
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        private WaitableJoystick CreateJoystick(DeviceInstance device)
        {
            WaitableJoystick joystick = null;

            try
            {
                joystick = new WaitableJoystick(directInput, device.InstanceGuid);
                joystick.Properties.BufferSize = DEVICE_BUFFER_SIZE;
            }
            catch (SharpDXException dxException)
            {
                if (dxException.ResultCode == 0x80040154)
                {
                    Logger.Warning("SharpDXException often occurs when disconnecting Joystick instance: " + dxException.Message);
                }
                else
                {
                    Logger.Error("SharpDXException during creation of Joystick instance: ", dxException);
                }
            }

            return(joystick);
        }
 public ConnectedDeviceInfo(WaitableJoystick joystick)
 {
     Information  = joystick.Information;
     Capabilities = joystick.Capabilities;
     Properties   = joystick.Properties;
 }