/// <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); }
static void Main(string[] args) { Controller xbox = new Controller(UserIndex.One); Console.WriteLine("Controller connected: " + xbox.IsConnected); BatteryInformation battery = xbox.GetBatteryInformation(BatteryDeviceType.Gamepad); Console.WriteLine("Battery level: " + battery.BatteryLevel); bool isRunning = true; while (isRunning) { Console.Clear(); State state = xbox.GetState(); switch (state.Gamepad.Buttons) { case GamepadButtonFlags.Start: isRunning = false; break; default: break; } Console.Write("Key pressed: " + state.Gamepad.Buttons + "\n"); Console.Write("RightThumbX stick: " + state.Gamepad.RightThumbX + "\n"); Console.Write("RightThumbY stick: " + state.Gamepad.RightThumbY + "\n"); Console.Write("LeftThumbX stick: " + state.Gamepad.LeftThumbX + "\n"); Console.Write("LeftThumbY stick: " + state.Gamepad.LeftThumbY + "\n"); Console.Write("LeftTrigger: " + state.Gamepad.LeftTrigger + "\n"); Console.Write("RightTrigger: " + state.Gamepad.RightTrigger + "\n"); int vibrationLeftMotorSpeed = 0; if (state.Gamepad.LeftThumbX > -1) vibrationLeftMotorSpeed = state.Gamepad.LeftThumbX; vibration.LeftMotorSpeed = (ushort)vibrationLeftMotorSpeed; xbox.SetVibration(vibration); System.Threading.Thread.Sleep(100); } }
/// <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); }
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; }