Sign in to follow this  

XInput rumble not stopping...

Recommended Posts

Hi all,

I've started to play around with a XBone controller using the XInput API.
​So far I've managed to retrieve all buttons and sticks input without a problem.

The only thing I don't understand, is how the rumble function works.
​I know how to enable it with XINPUT_VIBRATION and the motor speeds (0 to 65xxx).
​But if I try to disable rumbling by setting the motor speeds to 0, the rumbling doesn't stop.

Do you have any idea what I'm doing wrong?
​Below is the code of the simple test application.

Any input is appreciated.

	while(!done)
	{
		XINPUT_STATE state;
		ZeroMemory(&state, sizeof(XINPUT_STATE));
		dwResult = XInputGetState(controllerId, &state);

		if(dwResult != ERROR_SUCCESS)		// controller NOT connected?
		{
			MessageBox(NULL, L"XBox controller error - state not retrieved", L"Whoops...", MB_ICONERROR);
		}

		// DIGITAL BUTTONS
		if(((state.Gamepad.wButtons & XINPUT_GAMEPAD_A) != 0))				MessageBox(NULL, L"A", L"XBone", MB_OK);			// A button
		if(((state.Gamepad.wButtons & XINPUT_GAMEPAD_B) != 0))				MessageBox(NULL, L"B", L"XBone", MB_OK);			// B button
		if(((state.Gamepad.wButtons & XINPUT_GAMEPAD_X) != 0))																	// X button + RUMBLE
		{
			XINPUT_VIBRATION rumbler;
			rumbler.wLeftMotorSpeed = 25000;
			rumbler.wRightMotorSpeed = 25000;
			XInputSetState(controllerId, &rumbler);
			//MessageBox(NULL, L"X - rumble ON", L"XBone", MB_OK);			
		}
		
		if(((state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) != 0))																	// Y button + RUMBLE OFF
		{
			XINPUT_VIBRATION rumblerOff;
			rumblerOff.wLeftMotorSpeed = 0;
			rumblerOff.wRightMotorSpeed = 0;
			XInputSetState(controllerId, &rumblerOff);
			//MessageBox(NULL, L"Y - rumble OFF", L"XBone", MB_OK);
		}

		// Escape
		if(GetAsyncKeyState(VkKeyScan(VK_ESCAPE)) & 0x8000) done = true;
	}

Another question, do I need to use XInputEnable(true/false) when my application goes in/ out of scope?
​It doesn't seem to work with all XInput versions.

I'm currently including <xinput.h> and linking Xinput9_1_0.lib

Share this post


Link to post
Share on other sites

I looked at XInputSetState() ( https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputenable(v=vs.85).aspx ), and it says:

 

...

In a controller that supports vibration effects:

Passing FALSE will stop any vibration effects currently playing.

 

Could that be of any use?

Share this post


Link to post
Share on other sites

Thanks, I gave it a shot right away:

XInputSetState(controllerId, FALSE);

Unfortunately the same result.
I'll try to check the result that XInputSetState returns, maybe it's something else that's going wrong. I assume 'false' should give the same result as 0 and 0 for the left and right motor speeds.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this