Esempio n. 1
0
 internal unsafe override void OnShutdown()
 {
     if (directInput != null)
     {
         IDirectInput.Release(directInput);
         directInput = null;
     }
 }
Esempio n. 2
0
 public HOTASCollection(DirectInputFactory directInputFactory, JoystickFactory joystickFactory, HOTASQueueFactory hotasQueueFactory, HOTASDeviceFactory hotasDeviceFactory)
 {
     _directInputFactory = directInputFactory ?? throw new ArgumentNullException(nameof(directInputFactory));
     _joystickFactory    = joystickFactory ?? throw new ArgumentNullException(nameof(joystickFactory));
     _hotasQueueFactory  = hotasQueueFactory ?? throw new ArgumentNullException(nameof(hotasQueueFactory));
     _hotasDeviceFactory = hotasDeviceFactory ?? throw new ArgumentNullException(nameof(hotasDeviceFactory));
     _directInput        = _directInputFactory?.CreateDirectInput();
     Initialize();
 }
Esempio n. 3
0
        private static HOTASCollection CreateHotasCollection(out IDirectInput directInput, out JoystickFactory joystickFactory, out IHOTASQueue hotasQueue)
        {
            directInput = Substitute.For <IDirectInput>();
            hotasQueue  = Substitute.For <IHOTASQueue>();
            var          productId = Guid.NewGuid();
            var          deviceId  = Guid.NewGuid();
            const string name      = "test device name";

            var subJoystick = Substitute.For <IJoystick>();

            subJoystick.Capabilities.Returns(new Capabilities()
            {
                PovCount = 1, AxeCount = 4, ButtonCount = 20
            });
            subJoystick.IsAxisPresent(Arg.Any <string>()).Returns(true);

            joystickFactory = Substitute.For <JoystickFactory>();
            joystickFactory.CreateJoystick(default, default).ReturnsForAnyArgs(subJoystick);
Esempio n. 4
0
        public HOTASDevice(IDirectInput directInput, Guid productGuid, Guid deviceId, string name, IHOTASQueue hotasQueue)
        {
            _directInput = directInput ?? throw new ArgumentNullException(nameof(directInput));
            _hotasQueue  = hotasQueue ?? throw new ArgumentNullException(nameof(hotasQueue));

            if (deviceId == Guid.Empty)
            {
                return;                         //can occur when loading an unsupported json format and the device id isn't deserialized correctly or a non-connected device that was previously saved
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            DeviceId  = deviceId;
            ProductId = productGuid;
            Name      = name;
            InitializeModeProfile();
        }
Esempio n. 5
0
        unsafe bool CreateDevices()
        {
            // check for XInput presense
            haveXInput = XInput.IsXInputPresent();

            if (haveXInput)
            {
                XINPUT_STATE state = new XINPUT_STATE();

                for (int n = 0; n < XInput.MaxControllers; n++)
                {
                    int result = XInput.GetState(n, ref state);
                    if (!XInputNativeWrapper.Wrapper.FAILED(result))
                    {
                        string name = string.Format("XBox Controller {0}", n);

                        WindowsXBoxGamepad device = new WindowsXBoxGamepad(name, n);
                        if (!device.Init())
                        {
                            device.CallOnShutdown();
                            continue;
                        }

                        RegisterDevice(device);
                    }
                }
            }

            // check for DirectInput devices

            int hr = IDirectInput.EnumDevices(directInput, DInput.DI8DEVCLASS_GAMECTRL,
                                              EnumDevicesHandler, null, DInput.DIEDFL_ATTACHEDONLY);

            if (global::DirectInput.Wrapper.FAILED(hr))
            {
                Log.Warning("WindowsInputDeviceManager: IDirectInput.EnumDevices failed ({0}).",
                            DInput.GetOutString(DInput.DXGetErrorStringW(hr)));
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        public HOTASDevice(IDirectInput directInput, JoystickFactory joystickFactory, Guid productGuid, Guid deviceId, string name, IHOTASQueue hotasQueue) :
            this(directInput, productGuid, deviceId, name, hotasQueue)
        {
            _directInput     = directInput ?? throw new ArgumentNullException(nameof(directInput));
            _joystickFactory = joystickFactory ?? throw new ArgumentNullException(nameof(joystickFactory));
            _hotasQueue      = hotasQueue ?? throw new ArgumentNullException(nameof(hotasQueue));
            if (deviceId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(deviceId));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (App.IsDebug)
            {
                return;
            }
            AcquireJoystick();
            LoadCapabilitiesMapping();
        }
Esempio n. 7
0
 public virtual IJoystick CreateJoystick(IDirectInput directInput, Guid deviceId)
 {
     return(new JoystickWrapper(new Joystick(directInput.GetDirectInput(), deviceId)));
 }
 public virtual IHOTASDevice CreateHOTASDevice(IDirectInput directInput, Guid productGuid, Guid deviceId, string name, IHOTASQueue hotasQueue)
 {
     return(new HOTASDevice(directInput, productGuid, deviceId, name, hotasQueue));
 }