/// <summary> /// <p>Sends data to a connected controller. This function is used to activate the vibration function of a controller.</p> /// </summary> /// <param name="dwUserIndex"><dd> <p>Index of the user's controller. Can be a value from 0 to 3. For information about how this value is determined and how the value maps to indicators on the controller, see Multiple Controllers.</p> </dd></param> /// <param name="vibrationRef"><dd> <p>Pointer to an <strong><see cref="SharpDX.XInput.Vibration"/></strong> structure containing the vibration information to send to the controller.</p> </dd></param> /// <returns><p>If the function succeeds, the return value is <strong><see cref="SharpDX.Win32.ErrorCode.Success"/></strong>.</p><p>If the controller is not connected, the return value is <strong><see cref="SharpDX.Win32.ErrorCode.DeviceNotConnected"/></strong>.</p><p>If the function fails, the return value is an error code defined in WinError.h. The function does not use <em>SetLastError</em> to set the calling thread's last-error code.</p></returns> /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='XInputSetState']/*"/> /// <msdn-id>microsoft.directx_sdk.reference.xinputsetstate</msdn-id> /// <unmanaged>unsigned int XInputSetState([In] unsigned int dwUserIndex,[In] XINPUT_VIBRATION* pVibration)</unmanaged> /// <unmanaged-short>XInputSetState</unmanaged-short> public static int XInputSetState(int dwUserIndex, SharpDX.XInput.Vibration vibrationRef) { unsafe { int __result__; __result__ = XInputSetState_(dwUserIndex, &vibrationRef); return(__result__); } }
/// <summary> /// <p>Sends data to a connected controller. This function is used to activate the vibration function of a controller.</p> /// </summary> /// <param name = "dwUserIndex"><dd> <p>Index of the user's controller. Can be a value from 0 to 3. For information about how this value is determined and how the value maps to indicators on the controller, see Multiple Controllers.</p> </dd></param> /// <param name = "vibrationRef"><dd> <p>Pointer to an <strong><see cref = "SharpDX.XInput.Vibration"/></strong> structure containing the vibration information to send to the controller.</p> </dd></param> /// <returns><p>If the function succeeds, the return value is <strong>ERROR_SUCCESS</strong>.</p><p>If the controller is not connected, the return value is <strong>ERROR_DEVICE_NOT_CONNECTED</strong>.</p><p>If the function fails, the return value is an error code defined in WinError.h. The function does not use <em>SetLastError</em> to set the calling thread's last-error code.</p></returns> /// <doc-id>microsoft.directx_sdk.reference.xinputsetstate</doc-id> /// <unmanaged>DWORD XInputSetState([In] DWORD dwUserIndex,[In] XINPUT_VIBRATION* pVibration)</unmanaged> /// <unmanaged-short>XInputSetState</unmanaged-short> public static unsafe System.Int32 XInputSetState(System.Int32 dwUserIndex, ref SharpDX.XInput.Vibration vibrationRef) { SharpDX.XInput.Vibration.__Native vibrationRef_ = default(SharpDX.XInput.Vibration.__Native); System.Int32 __result__; vibrationRef.__MarshalTo(ref vibrationRef_); __result__ = XInputSetState_(dwUserIndex, &vibrationRef_); vibrationRef.__MarshalFree(ref vibrationRef_); return(__result__); }
private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger) { if (!_connected[index]) { if (!HasDisconnectedTimeoutElapsed(index)) { return(false); } if (!_controllers[index].IsConnected) { SetDisconnectedTimeout(index); return(false); } _connected[index] = true; } SharpDX.Result result; try { var vibration = new SharpDX.XInput.Vibration { LeftMotorSpeed = (ushort)(leftMotor * ushort.MaxValue), RightMotorSpeed = (ushort)(rightMotor * ushort.MaxValue), }; result = _controllers[index].SetVibration(vibration); } catch (SharpDX.SharpDXException ex) { const int deviceNotConnectedHResult = unchecked ((int)0x8007048f); if (ex.HResult == deviceNotConnectedHResult) { _connected[index] = false; SetDisconnectedTimeout(index); return(false); } throw; } return(result == SharpDX.Result.Ok); }
public static void vibrate(int gp_index, float left_vib, float right_vib) { #if GAMEPAD_VIBRATION left_vib = Math.Min(Math.Max(0.0f, left_vib), 1.0f); right_vib = Math.Min(Math.Max(0.0f, right_vib), 1.0f); var left_motor = (ushort)(left_vib * 65535.0f); var right_motor = (ushort)(right_vib * 65535.0f); var vib = new SharpDX.XInput.Vibration { LeftMotorSpeed = left_motor, RightMotorSpeed = right_motor }; var gamepad = new SharpDX.XInput.Controller((SharpDX.XInput.UserIndex)gp_index); if (GamePad.GetState((PlayerIndex)gp_index).IsConnected) { gamepad.SetVibration(vib); } #endif }