Example #1
0
        public bool AddAndStart(string device)
        {
            if (Contains(device))
            {
                return(false);
            }

            var gamepad = new MiGamepad(device, _ViGEmClient);

            _Gamepads.Add(device, gamepad);

            gamepad.Started += Gamepad_Started;
            gamepad.Ended   += Gamepad_Ended;

            gamepad.Start();

            return(true);
        }
Example #2
0
        public bool AddAndStart(string device)
        {
            if (Contains(device))
            {
                _Logger.Warning("Requested addition of already existing device {Device}", device);
                return(false);
            }

            _Logger.Information("Adding device {Device}", device);
            var gamepad = new MiGamepad(device, _ViGEmClient);

            _Gamepads.Add(device, gamepad);

            gamepad.Started += Gamepad_Started;
            gamepad.Ended   += Gamepad_Ended;

            _Logger.Information("Starting {Device}", device);
            gamepad.Start();

            return(true);
        }
Example #3
0
        private void SearchForDevice(object state)
        {
            var devices        = HidDevices.Enumerate(XiaomiGamepadVid, XiaomiGamepadPid);
            var connectedPaths = new List <string>();

            foreach (var device in devices)
            {
                connectedPaths.Add(device.DevicePath);

                // If the device is already running, go on
                if (_Gamepads.ContainsKey(device.DevicePath))
                {
                    continue;
                }

                // This is a new gamepad
                ShowNotification("Gamepad connected", "A new gamepad is up and running.");

                var gamepad = new MiGamepad(device, _ViGEmClient);
                _Gamepads.Add(device.DevicePath, gamepad);
                gamepad.Start();
            }

            // Stop and remove any disconnected gamepad
            var runningPaths = _Gamepads.Keys.ToArray();

            foreach (var path in runningPaths)
            {
                if (!connectedPaths.Contains(path))
                {
                    var gamepad = _Gamepads[path];

                    ShowNotification("Gamepad disconnected", "A gamepad disconnected and is not available any more.");
                    gamepad.Stop();
                    gamepad.Dispose();
                    _Gamepads.Remove(path);
                }
            }
        }