winterhell's picture

GamePad forcefeedback not working?

I have an Xbox 360 controller (no other controllers hooked to the system at the moment). I poll it with GameWindows.Joysticks[0];
Tried to set vibration with
OpenTK.Input.GamePad.SetVibration(0, 0.4f, 0.9f);//tried with index 1 as well
Nothing happens. Do I need to initiate the gamepad somewhere, or update it?
In XNA it rumbles as usual.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Force feedback is on the todo list (the return value of SetVibration() is false.) Fortunately, getting the Xbox360 controller to work on Windows is trivial, all it needs is a call to SetState() here.

I'm working on different parts of the code now, so a PR for this would be welcome. Otherwise, I'll revisit this topic over the following months.

winterhell's picture

Is there a thing I can read to get more familiarized on HID/drivers/relevant stuff, or maybe a C++ source code that could be ported, so I can help this to get done?

the Fiddler's picture
winterhell wrote:

Is there a thing I can read to get more familiarized on HID/drivers/relevant stuff, or maybe a C++ source code that could be ported, so I can help this to get done?

For the case of Xbox360-compatible controllers on Windows, you need to call XInputSetState. This function is already bound in OpenTK/Platform/Windows/XInputJoystick.cs, so all you need to do is add a call to xinput.SetState() in line 95 of that file.

The SDL2 backend is also very simple to implement, according to this example code. The tricky part is that we need a proper haptics API for that. Let's continue that discussion to the relevant issue on github.

the Fiddler's picture

Vibration for Xbox-compatible controllers implemented here: https://github.com/opentk/opentk/pull/161

Please test!

winterhell's picture

Under the GameWindow States, GamePad state both 360 triggers are repported correctly and all of the buttons and ministicks. Under Joystick the buttons are maybe in different order, and no triggers.
SetVibration still does not produce a vibration.

A Mega Drive 6 button gamepad reports only 4/8 butons, namely X Y Z Mode and not A B C and Start. Both Joystick and Legacy Joystick recognize it the same.

the Fiddler's picture

Thanks. The missing buttons are probably reported as a HID collection element, which I haven't implemented yet. This is relatively simple to fix.

Not sure about SetVibration, I'll have to test that on my xbox controller.

the Fiddler's picture

All issues except for vibration have been resolved. Can you please test once more?

winterhell's picture

I'm not good with GitHub. How do I find the newest fork?(the pull/161 link says the newest changes are 2 days old)

the Fiddler's picture

Just checked and the new code should be there (just git pull). I've also implemented GamePad.SetVibration and will commit that in a couple of hours.

Everything seems stable on my system, including hotplugging.

winterhell's picture

Just checked the newest version in the branches.
The Mega drive pad shows improvement, still only 4 button states, but A B C Start double the state of X Y Z Mode, so its an improvement and is good enough for most oldschool games.
For what is worth the original controller did some kind of multiplexing to achieve all 8 buttons and maybe the USB driver preserves this in a way. Emulators detect all buttons correctly however.