Пример #1
0
        private async Task XboxJoystickInit(DeviceInformationCollection deviceInformationCollection)
        {
            //string deviceSelector = HidDevice.GetDeviceSelector(0x01, 0x05);
            //DeviceInformationCollection deviceInformationCollection = await DeviceInformation.FindAllAsync(deviceSelector);

            DeviceId = null;
            int deviceCount = deviceInformationCollection.Count;

            if (deviceCount == 0)
            {
                Debug.WriteLine("Error: No Xbox360 controller found!");
                JoystickIsWorking = false;
            }
            else
            {
                foreach (DeviceInformation d in deviceInformationCollection)
                {
                    Debug.WriteLine("OK: Found: Xbox 360 Joystick Device ID: " + d.Id);

                    HidDevice hidDevice = await HidDevice.FromIdAsync(d.Id, Windows.Storage.FileAccessMode.Read);

                    if (hidDevice == null)
                    {
                        JoystickIsWorking = false;
                        try
                        {
                            var deviceAccessStatus = DeviceAccessInformation.CreateFromId(d.Id).CurrentStatus;

                            if (!deviceAccessStatus.Equals(DeviceAccessStatus.Allowed))
                            {
                                Debug.WriteLine("IP: DeviceAccess: " + deviceAccessStatus.ToString());
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("Error: Xbox init - " + e.Message);
                        }

                        Debug.WriteLine("Error: Failed to connect to Xbox 360 Joystick controller!");
                    }
                    else
                    {
                        controller = new XboxHidController(hidDevice);
                        controller.JoystickDataChanged += Controller_JoystickDataChanged;
                        JoystickIsWorking = true;
                        DeviceId          = d.Id;
                    }
                }
            }
            lastControllerCount = deviceCount;
        }
Пример #2
0
        private async Task XboxJoystickInit(DeviceInformationCollection deviceInformationCollection)
        {
            //string deviceSelector = HidDevice.GetDeviceSelector(0x01, 0x05);
            //DeviceInformationCollection deviceInformationCollection = await DeviceInformation.FindAllAsync(deviceSelector);

            DeviceId = null;
            int deviceCount = deviceInformationCollection.Count;

            if (deviceCount == 0)
            {
                Debug.WriteLine("Error: No Xbox360 controller found!");
                JoystickIsWorking = false;
            }
            else
            {
                foreach (DeviceInformation d in deviceInformationCollection)
                {
                    Debug.WriteLine("OK: Found: Xbox 360 Joystick Device ID: " + d.Id);

                    HidDevice hidDevice = await HidDevice.FromIdAsync(d.Id, Windows.Storage.FileAccessMode.Read);

                    if (hidDevice == null)
                    {
                        JoystickIsWorking = false;
                        try
                        {
                            var deviceAccessStatus = DeviceAccessInformation.CreateFromId(d.Id).CurrentStatus;

                            if (!deviceAccessStatus.Equals(DeviceAccessStatus.Allowed))
                            {
                                Debug.WriteLine("IP: DeviceAccess: " + deviceAccessStatus.ToString());
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("Error: Xbox init - " + e.Message);
                        }

                        Debug.WriteLine("Error: Failed to connect to Xbox 360 Joystick controller!");
                    }
                    else
                    {
                        controller = new XboxHidController(hidDevice);
                        controller.JoystickDataChanged += Controller_JoystickDataChanged;
                        JoystickIsWorking = true;
                        DeviceId = d.Id;
                    }
                }
            }
            lastControllerCount = deviceCount;
        }
Пример #3
0
        private void Controller_JoystickDataChanged(object sender, XboxHidController.JoystickEventArgs e)
        {
            // receiving IJoystickRawState
            JoystickIsWorking = true;
            //Debug.WriteLine("JoystickRawState: X=" + e.jss.X + "  Y=" + e.jss.Y);

            lock(jssLock)
            {
                // keep a copy for those who poll the joystick:
                jssCurrent = new JoystickSubState(e.jss);
            }

            // if we have subscribers, notify them:
            //Debug.WriteLine("--------- 360: Controller_JoystickDataChanged");
            joystickEvent?.Invoke(this, (IJoystickSubState)jssCurrent.Clone());

            //Debug.WriteLine("JoystickSubState: Speed=" + jssCurrent.Speed + "  Turn=" + jssCurrent.Turn);
        }