/// <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); } catch (Exception) { // Do nothing, gamepad could be uninitialized } finally { Monitor.Exit(this.timerLock); } }
/// <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); } }