Ejemplo n.º 1
0
        /// <summary>
        /// Prints the gamepad readings to the UI
        /// </summary>
        /// <param name="reading">The reading.</param>
        private void WriteGamepadReadings(GamepadReading reading)
        {
            var propertyStringBuilder = new StringBuilder();
            var valueStringBuilder    = new StringBuilder();

            valueStringBuilder.AppendLine(this.gamepad.CurrentSlotId.ToString());
            propertyStringBuilder.AppendLine(string.Format("Slot:"));

            valueStringBuilder.AppendLine(reading.Buttons.ToString());
            propertyStringBuilder.AppendLine("Buttons:");

            valueStringBuilder.AppendLine(reading.LeftTrigger.ToString());
            propertyStringBuilder.AppendLine("LeftTrigger:");

            valueStringBuilder.AppendLine(reading.RightTrigger.ToString());
            propertyStringBuilder.AppendLine("RightTrigger:");

            valueStringBuilder.AppendLine(reading.LeftThumbstickX.ToString());
            propertyStringBuilder.AppendLine("LeftThumbstickX:");

            valueStringBuilder.AppendLine(reading.LeftThumbstickY.ToString());
            propertyStringBuilder.AppendLine("LeftThumbstickY:");

            valueStringBuilder.AppendLine(reading.RightThumbstickX.ToString());
            propertyStringBuilder.AppendLine("RightThumbstickX:");

            valueStringBuilder.AppendLine(reading.RightThumbstickY.ToString());
            propertyStringBuilder.AppendLine("RightThumbstickY:");

            // Config values
            EliteGamepadConfiguration config = this.gamepad.gamepad.GetConfiguration(this.gamepad.CurrentSlotId);

            valueStringBuilder.AppendLine(config.LeftTrigger.Min.ToString());
            propertyStringBuilder.AppendLine("LeftTriggerMin:");

            valueStringBuilder.AppendLine(config.LeftTrigger.Max.ToString());
            propertyStringBuilder.AppendLine("LeftTriggerMax:");

            valueStringBuilder.AppendLine(config.RightTrigger.Min.ToString());
            propertyStringBuilder.AppendLine("RightTriggerMin:");

            valueStringBuilder.AppendLine(config.RightTrigger.Max.ToString());
            propertyStringBuilder.AppendLine("RightTriggerMax:");

            double value = normalizeTriggerValue(reading.LeftTrigger, config.LeftTrigger.Min / 10, config.LeftTrigger.Max / 10);

            valueStringBuilder.AppendLine(value.ToString());
            propertyStringBuilder.AppendLine("VibrationValueLeft");

            value = normalizeTriggerValue(reading.RightTrigger, config.RightTrigger.Min / 10, config.RightTrigger.Max / 10);
            valueStringBuilder.AppendLine(value.ToString());
            propertyStringBuilder.AppendLine("VibrationValueRight");

            var task  = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { measurementId.Text = propertyStringBuilder.ToString(); }).AsTask();
            var task2 = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { measurementValue.Text = valueStringBuilder.ToString(); }).AsTask();

            Task.WaitAll(task, task2);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EliteGamepadAdapter"/> class.
        /// </summary>
        /// <param name="gamepad">The gamepad.</param>
        private EliteGamepadAdapter(EliteGamepad gamepad)
        {
            this.gamepad       = gamepad;
            this.gamepadId     = gamepad.FriendlyName;
            this.IsReady       = true;
            this.configuration = gamepad.GetConfiguration(this.CurrentSlotId);

            // Should make this disposable so they get removed, but it should never be a problem unless somebody is being naughty or ambitious :)
            EliteGamepad.EliteGamepadAdded += (sender, data) =>
            {
                this.EnsureGamepadInitialized(data);
            };

            EliteGamepad.EliteGamepadRemoved += (sender, data) =>
            {
                this.RemoveGamepad(data);
            };
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The function to do processing for the timer
        /// </summary>
        /// <param name="state">The object holding the state to be used by the timer..</param>
        private void TimerCallback(object state)
        {
            if (!Monitor.TryEnter(this.timerLock))
            {
                return;
            }

            try
            {
                if ((this.gamepad == null && !EliteGamepadAdapter.TryCreate(out this.gamepad)) || !this.gamepad.IsReady)
                {
                    return;
                }

                var reading = this.gamepad.GetCurrentUnmappedReading();
                if (this.ShouldSkipGamepadProcessing(reading))
                {
                    return;
                }

                this.WriteGamepadReadings(reading);
                this.ProcessGamepadReadings(reading);


                {
                    // Vibrations
                    Windows.Gaming.Input.Gamepad          gamepad = Windows.Gaming.Input.Gamepad.Gamepads.First();
                    Windows.Gaming.Input.GamepadVibration vibration;

                    EliteGamepadConfiguration config = this.gamepad.gamepad.GetConfiguration(this.gamepad.CurrentSlotId);

                    vibration.LeftMotor    = 0.0;
                    vibration.LeftTrigger  = 0.0;
                    vibration.RightMotor   = 0.0;
                    vibration.RightTrigger = 0.0;

                    // Set the vibration
                    // Left Trigger
                    if (reading.LeftTrigger != 0.0)
                    {
                        if (isVibrationEnabled == true)
                        {
                            // Normalize our data base on the set interval
                            double value = normalizeTriggerValue(reading.LeftTrigger, config.LeftTrigger.Min / 10, config.LeftTrigger.Max / 10);

                            // Set the vibration Based on the normalized value AND trigger scale factor!
                            vibration.LeftTrigger = value * config.ScaleFactorLeftTriggerMotor / 100.0f;
                            gamepad.Vibration     = vibration;
                        }
                    }
                    else
                    {
                        vibration.LeftTrigger = 0.0;
                        gamepad.Vibration     = vibration;
                    }

                    // Right Trigger
                    if (reading.RightTrigger != 0.0)
                    {
                        if (isVibrationEnabled == true)
                        {
                            // Normalize our data base on the set interval
                            double value = normalizeTriggerValue(reading.RightTrigger, config.RightTrigger.Min / 10, config.RightTrigger.Max / 10);

                            // Set the vibration Based on the normalized value AND trigger scale factor!
                            vibration.RightTrigger = value * config.ScaleFactorRightTriggerMotor / 100.0f;
                            gamepad.Vibration      = vibration;
                        }
                    }
                    else
                    {
                        vibration.RightTrigger = 0.0;
                        gamepad.Vibration      = vibration;
                    }
                }
            }
            catch (Exception)
            {
                // Do nothing, gamepad could be uninitialized
            }
            finally
            {
                Monitor.Exit(this.timerLock);
            }
        }