private void timerEvent_Tick(object sender, EventArgs e) { if (controller1 != null && controller1.IsConnected) { Vibration v = new Vibration(); v.LeftMotorSpeed = (short)(controller1.GetState().Gamepad.LeftTrigger * 255); v.RightMotorSpeed = (short)(controller1.GetState().Gamepad.RightTrigger * 255); lblLeftEngine.Text = "Left: " + v.LeftMotorSpeed; lblRightEngine.Text = "Right: " + v.RightMotorSpeed; controller1.SetVibration(v); } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (controller1 != null && controller1.IsConnected) { Vibration v = new Vibration(); v.LeftMotorSpeed = 0; v.RightMotorSpeed = 0; controller1.SetVibration(v); } }
/// <summary> /// Function to perform vibration on the gaming device, if supported. /// </summary> /// <param name="motorIndex">The index of the motor to start or stop.</param> /// <param name="value">The speed of the motor.</param> /// <remarks> /// <para> /// This will activate the vibration motor(s) in the gaming device. The <paramref name="motorIndex"/> should be within the <see cref="IGorgonGamingDeviceInfo.VibrationMotorRanges"/> count, or else /// an exception will be thrown. /// </para> /// <para> /// To determine if the device supports vibration, check the <see cref="IGorgonGamingDeviceInfo.Capabilities"/> property for the <see cref="GamingDeviceCapabilityFlags.SupportsVibration"/> flag. /// </para> /// <para> /// Implementors of a <see cref="GorgonGamingDeviceDriver"/> plug in should ensure that devices that support vibration implement this method. Otherwise, if the device does not support the functionality /// then this method can be left alone. /// </para> /// </remarks> protected override void OnVibrate(int motorIndex, int value) { _currentVibration = new XI.Vibration { LeftMotorSpeed = motorIndex == 0 ? (ushort)value : _currentVibration.LeftMotorSpeed, RightMotorSpeed = motorIndex == 1 ? (ushort)value : _currentVibration.RightMotorSpeed }; _controller.SetVibration(_currentVibration); }
/// <summary> /// Function to perform device vibration. /// </summary> /// <param name="motorIndex">Index of the motor to start.</param> /// <param name="value">Value to set.</param> /// <remarks>Implementors should implement this method if the device supports vibration.</remarks> protected override void VibrateDevice(int motorIndex, int value) { var vibeData = new XI.Vibration(); if (!_controller.IsConnected) { return; } if (motorIndex == 0) { vibeData.LeftMotorSpeed = (ushort)value; } if (motorIndex == 1) { vibeData.RightMotorSpeed = (ushort)value; } _controller.SetVibration(vibeData); }
public void UpdateForceFeedBack() { if (MainForm.Current.ControllerIndex == -1) return; // Convert 100% trackbar to MotorSpeed's 0 - 65,535 (100%). var leftMotor = (short)(LeftMotorTestTrackBar.Value / 100F * ushort.MaxValue); var rightMotor = (short)(RightMotorTestTrackBar.Value / 100F * ushort.MaxValue); LeftMotorTestTextBox.Text = string.Format("{0} % ", LeftMotorTestTrackBar.Value); RightMotorTestTextBox.Text = string.Format("{0} % ", RightMotorTestTrackBar.Value); lock (MainForm.XInputLock) { var gPad = MainForm.Current.GamePads[ControllerIndex]; if (XInput.IsLoaded && gPad.IsConnected) { var vibration = new Vibration(); vibration.LeftMotorSpeed = leftMotor; vibration.RightMotorSpeed = rightMotor; gPad.SetVibration(vibration); } } //UnsafeNativeMethods.Enable(false); //UnsafeNativeMethods.Enable(true); }
public Result SetVibration(Vibration vibration) { Result result = ErrorCodeHelper.ToResult(XInput.XInputSetState((int) this.userIndex, vibration)); result.CheckError(); return result; }
uint XInputSetState_Hooked(int dwUserIndex, ref Vibration pVibration) { var controller = new Controller((UserIndex)dwUserIndex); if (controller.IsConnected) { try { controller.SetVibration(pVibration); } catch { return ERROR_DEVICE_NOT_CONNECTED; } } return ERROR_SUCCESS; }
public static unsafe int XInputSetState(int dwUserIndex, Vibration vibrationRef) { return XInputSetState_(dwUserIndex, (void*)(&vibrationRef)); }
public int XInputSetState(int dwUserIndex, Vibration vibrationRef) { return Native.XInputSetState(dwUserIndex, vibrationRef); }
public override void SetVibration(float leftMotor, float rightMotor) { leftMotor = MathUtil.Clamp(leftMotor, 0.0f, 1.0f); rightMotor = MathUtil.Clamp(rightMotor, 0.0f, 1.0f); var vibration = new Vibration { LeftMotorSpeed = (ushort)(leftMotor*65535.0f), RightMotorSpeed = (ushort)(rightMotor*65535.0f) }; instance.SetVibration(vibration); }
public int XInputSetState(int dwUserIndex, Vibration vibrationRef) { return(XInput.XInputSetState(dwUserIndex, vibrationRef)); }