Пример #1
0
        public Gamepad(GamepadConfiguration config, VGenWrapper vGenWrapper, HidDeviceLoader hidDeviceLoader)
        {
            _config = config;
            _vGenWrapper = vGenWrapper;
            _hidDeviceLoader = hidDeviceLoader;
            _virtualMappings = new Dictionary<XInputGamepadButtons, XInputGamepadButtons>();

            foreach (var virtualMapping in _config.Mapping.VirtualKeysItems.Where(item => item.DestinationItem != null))
            {
                var virtualPattern = virtualMapping.SourceKeys
                    .Where(sourceKey => sourceKey != null)
                    .Aggregate((XInputGamepadButtons)0, (current, sourceKey) => current | sourceKey.Value);

                // ReSharper disable once PossibleInvalidOperationException
                _virtualMappings[virtualPattern] = (XInputGamepadButtons) virtualMapping.DestinationItem;
            }
        }
Пример #2
0
        private IObservable<uint> StartSingle(GamepadConfiguration gamepadConfiguration)
        {
            return Observable.Create<uint>(observer =>
            {
                var gamepad = new Gamepad(gamepadConfiguration, _vGenWrapper, _hidManager.HidDeviceLoader);
                gamepad.ErrorOccuredEvent += Gamepad_ErrorOccuredEvent;
                if (gamepad.Start())
                {
                    observer.OnNext(gamepadConfiguration.GamepadId);
                }
                else
                {
                    gamepad.Dispose();
                    observer.OnError(GamepadStartException);
                }

                return Disposable.Create(() =>
                {
                    gamepad.Dispose();
                    gamepad.ErrorOccuredEvent -= Gamepad_ErrorOccuredEvent;
                });
            });
        }