private void FullControllerUpdate()
        {
            AddOrUpdateValue($"HID/Gamepad", gamepads.Count, true);

            for (int i = 0; i < gamepads.Count; i++)
            {
                RawGameController gamepad = gamepads[i];
                AddOrUpdateValue($"HID/Gamepad/{i}", gamepad.DisplayName, true);
                AddOrUpdateValue($"HID/Gamepad/{i}/Axis", gamepad.AxisCount, true);
                AddOrUpdateValue($"HID/Gamepad/{i}/Button", gamepad.ButtonCount, true);
                AddOrUpdateValue($"HID/Gamepad/{i}/Switch", gamepad.SwitchCount, true);

                for (int j = 0; j < gamepad.ButtonCount; j++)
                {
                    AddOrUpdateValue($"HID/Gamepad/{i}/Button/{j}/Name", gamepad.GetButtonLabel(j).ToString(), true);
                }

                for (int j = 0; j < gamepad.SwitchCount; j++)
                {
                    AddOrUpdateValue($"HID/Gamepad/{i}/Switch/{j}/Kind", (int)gamepad.GetSwitchKind(j), true);
                }
            }

            ControllerReadingUpdate();
        }
        private void ControllerReadingUpdate()
        {
            for (int i = 0; i < gamepads.Count; i++)
            {
                RawGameController gamepad     = gamepads[i];
                bool[]            buttonArray = new bool[gamepad.ButtonCount];
                GameControllerSwitchPosition[] switchArray = new GameControllerSwitchPosition[gamepad.SwitchCount];
                double[] axisArray = new double[gamepad.AxisCount];
                ulong    timestamp = gamepad.GetCurrentReading(buttonArray, switchArray, axisArray);

                for (int j = 0; j < gamepad.AxisCount; j++)
                {
                    AddOrUpdateValue($"HID/Gamepad/{i}/Axis/{j}", axisArray[j], true);
                }

                for (int j = 0; j < gamepad.ButtonCount; j++)
                {
                    AddOrUpdateValue($"HID/Gamepad/{i}/Button/{j}", buttonArray[j], true);
                }

                for (int j = 0; j < gamepad.SwitchCount; j++)
                {
                    AddOrUpdateValue($"HID/Gamepad/{i}/Switch/{j}", (int)switchArray[j], true);
                }

                //AddOrUpdateValue($"HID/Gamepad/{i}/Battery", (int)gamepad.TryGetBatteryReport().Status, true);
            }
        }
 public RawGameControllerModel(RawGameController controller)
 {
     Axes       = new double[controller.AxisCount];
     Switches   = new GameControllerSwitchPosition[controller.SwitchCount];
     Buttons    = new bool[controller.ButtonCount];
     Controller = controller;
 }
        private void ControllerAdded(object sender, RawGameController e)
        {
            if (!gamepads.Contains(e))
            {
                gamepads.Add(e);
            }

            FullControllerUpdate();
        }
 public XboxHeadsetDetector()
 {
     usersConnectedGamePad = RawGameController.RawGameControllers.FirstOrDefault(x => x.User == Crystal3.CrystalApplication.GetCurrentAsCrystalApplication().CurrentUser);
     if (usersConnectedGamePad != null)
     {
         usersConnectedGamePad.HeadsetConnected    += UsersConnectedGamePad_HeadsetConnected;
         usersConnectedGamePad.HeadsetDisconnected += UsersConnectedGamePad_HeadsetDisconnected;
         SetHeadsetStatus(usersConnectedGamePad.Headset != null);
     }
 }
        public GenericController()
        {
            this.Controller = null;

            RawGameController.RawGameControllerRemoved += (s, e) =>
            {
                OnDisconnected(e);
            };

            RawGameController.RawGameControllerAdded += (s, e) =>
            {
                OnConnected(e);
            };
        }
Exemple #7
0
        private void RawGameController_RawGameControllerAdded(object sender, RawGameController e)
        {
            switch (e.HardwareVendorId)
            {
            case 0x44f:
                switch (e.HardwareProductId)
                {
                case 0xB10A: _tmFlightStick = e; break;

                case 0xB687: _throttle = e; break;
                }
                break;
            }
        }
Exemple #8
0
        private async Task GameControllersSetup()
        {
            // setup delegates for adding/removing to the gamepad list
            RawGameController.RawGameControllerAdded += async(object sender, RawGameController e) =>
            {
                //Check if the just - added gamepad is already in myGamepads; if it isn't, add
                // it.

                bool gamepadInList = myGamepads.Contains(e);

                if (!gamepadInList)
                {
                    buttonArray = new bool[e.ButtonCount];
                    switchArray = new GameControllerSwitchPosition[e.SwitchCount];
                    axisArray   = new double[e.AxisCount];

                    myGamepads.Add(e);
                }

                // add a placeholder for the number of buttons
                for (int i = 0; i < e.ButtonCount; i++)
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        ButtonPanelHolder.Children.Add(CreateButtonDisplay(i));
                    });
                }
            };

            RawGameController.RawGameControllerRemoved += (object sender, RawGameController e) =>
            {
                lock (myLock)
                {
                    int indexRemoved = myGamepads.IndexOf(e);

                    if (indexRemoved > -1)
                    {
                        if (mainGamepad == myGamepads[indexRemoved])
                        {
                            mainGamepad = null;
                        }

                        myGamepads.RemoveAt(indexRemoved);
                    }
                }
            };
        }
        private async void ControllerRemoved(object sender, RawGameController e)
        {
            int indexRemoved = gamepads.IndexOf(e);

            if (indexRemoved > -1)
            {
                gamepads.RemoveAt(indexRemoved);
                int count = 1;
                while (count > 0)
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        dataTable.Remove(dataTable.FirstOrDefault((Value a) => { return(a.Key.StartsWith("HID/Gamepad/" + gamepads.Count)); }));
                    });

                    count = dataTable.Count((Value a) => { return(a.Key.StartsWith("HID/Gamepad/" + gamepads.Count)); });
                }
            }

            FullControllerUpdate();
        }
Exemple #10
0
        static void UpdateControllerLists()
        {
            _controllers = new Dictionary <RawGameController, IGameController>();
            foreach (var raw in _rawControllers)
            {
                _controllers[raw.Key] = null;
            }
            foreach (var gamepad in _gamepads)
            {
                var raw = RawGameController.FromGameController(gamepad);
                _controllers[raw] = gamepad;
            }

            if (_controllers.Values.Any(x => x == null))
            {
                StartRawPolling();
            }
            else
            {
                StopRawPolling();
            }
        }
 protected virtual void OnDisconnected(RawGameController e)
 {
     this.Controller = null;
     Disconnected.Invoke(this, EventArgs.Empty);
 }
Exemple #12
0
 private static async void RawGameController_RawGameControllerAdded(object sender, RawGameController e)
 {
     if (e.AxisCount > 0 || e.ButtonCount > 0 || e.SwitchCount > 0)
     {
         if (!_rawControllers.ContainsKey(e))
         {
             _rawControllers.Add(e, new RawGameControllerModel(e));
             UpdateControllerLists();
             if (HasInitialized || VendorId == null)
             {
                 try
                 {
                     await HandleRawInput(e);
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.Message);
                 }
             }
         }
     }
 }
Exemple #13
0
 private static void RawGameController_RawGameControllerRemoved(object sender, RawGameController e)
 {
     if (_rawControllers.ContainsKey(e))
     {
         _rawControllers.Remove(e);
         UpdateControllerLists();
     }
 }
        /// <summary>
        /// Product represents the Hardware Product ID for a IGamingController object.
        /// </summary>
        /// <returns>
        /// Product returns the Hardware Product ID value for a IGamingController object.
        /// </returns>
        public ushort Product()
        {
            RawGameController raw = RawGameController.FromGameController(Controller);

            return(raw.HardwareProductId);
        }
        /// <summary>
        /// Vendor represents the Hardware Vendor ID for a IGamingController object.
        /// </summary>
        /// <returns>
        /// Vendor returns the Hardware Vendor ID value for a IGamingController object.
        /// </returns>
        public ushort Vendor()
        {
            RawGameController raw = RawGameController.FromGameController(Controller);

            return(raw.HardwareVendorId);
        }
Exemple #16
0
 /////////////////////////////////////////////////////////////////////////////Backend
 //public event EventHandler<RawGameController> RawGameControllerAdded;
 static void RawGameControllerAdded(object sender, RawGameController args)
 {
     RawGameControllers.Add(args);
 }