Skip to content

Unable to set HapticDirection.dir #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
theGeekPirate opened this issue Feb 21, 2018 · 15 comments
Closed

Unable to set HapticDirection.dir #315

theGeekPirate opened this issue Feb 21, 2018 · 15 comments
Labels
solved? This issue might have been solved but not tested

Comments

@theGeekPirate
Copy link

dir is unexported (https://github.com/veandco/go-sdl2/blob/master/sdl/haptic.go#L46) and has no methods to set it with, so we're currently unable to use it.

https://wiki.libsdl.org/SDL_HapticDirection

@malashin
Copy link
Collaborator

malashin commented Feb 21, 2018

Hey @theGeekPirate, Dir is exported now. Thank you for your feedback.

I am wondering if anyone has actually used the bindings for haptics. Either I am missing something or there is no way to actually create/update the HapticEffect. I had to update the C pointer for this to work:

err := sdl.Init(sdl.INIT_EVERYTHING)
if err != nil {
	panic(err)
}

joy := sdl.JoystickOpen(0)
defer joy.Close()

h, err := sdl.HapticOpenFromJoystick(joy)
defer h.Close()

e := sdl.HapticConstant{
	Type:      sdl.HAPTIC_CONSTANT,
	Direction: sdl.HapticDirection{Type: sdl.HAPTIC_CARTESIAN, Dir: [3]int32{-1, 0}},
	Length:    1000,
	Level:     32767,
}

he := sdl.HapticEffect{}
*((*sdl.HapticConstant)(unsafe.Pointer(&he[0]))) = e

id, err := h.NewEffect(&he)
if err != nil {
	panic(err)
}
defer h.DestroyEffect(id)

h.RunEffect(id, 1)

time.Sleep(2 * time.Second)

We should probably make functions to update HapticEffect with actual effects or think of some other way of creating them in the first place.

This one might be redundant in that case, not sure what it is used for:

func (he HapticEffect) SetType(typ uint16) {}

@theGeekPirate
Copy link
Author

theGeekPirate commented Feb 21, 2018

From both my PS3 and XB One controllers using your code:

panic: Haptic: Effect not supported by haptic device.

Tried changing the Type just in case, but to no avail.

My original goal was to have the left/right sides rumble independently.

Have you been able to get it working with an sdl.GameController?

@theGeekPirate
Copy link
Author

theGeekPirate commented Feb 21, 2018

I should probably mention that a regular sdl.Haptic.RumblePlay() does work on both controllers (I'm on Linux).

@malashin
Copy link
Collaborator

malashin commented Feb 22, 2018

@theGeekPirate ye, the first thing I tested on was Xbox One Gamepad.

Most of the gamepads don't support complex effects, the only thing they can run is
https://wiki.libsdl.org/SDL_HapticLeftRight

In my case it's just low and high frequency motors, nothing directional.

err := sdl.Init(sdl.INIT_EVERYTHING)
if err != nil {
	panic(err)
}

joy := sdl.JoystickOpen(0)
defer joy.Close()

h, err := sdl.HapticOpenFromJoystick(joy)
defer h.Close()


// Test low frequency motor.
e := sdl.HapticLeftRight{Type: sdl.HAPTIC_LEFTRIGHT,
	Length:         3000,
	LargeMagnitude: 32767,
	SmallMagnitude: 0,
}

he := sdl.HapticEffect{}
*((*sdl.HapticLeftRight)(unsafe.Pointer(&he[0]))) = e

id, err := h.NewEffect(&he)
if err != nil {
	panic(err)
}
h.RunEffect(id, 1)

time.Sleep(3 * time.Second)
h.DestroyEffect(id)


// Test high frequency motor.
e = sdl.HapticLeftRight{Type: sdl.HAPTIC_LEFTRIGHT,
	Length:         3000,
	LargeMagnitude: 0,
	SmallMagnitude: 32767,
}
*((*sdl.HapticLeftRight)(unsafe.Pointer(&he[0]))) = e

id, err = h.NewEffect(&he)
if err != nil {
	panic(err)
}
defer h.DestroyEffect(id)
h.RunEffect(id, 1)

time.Sleep(3 * time.Second)

This is what rumble does in SDL sources:

/* Most things can use SINE, but XInput only has LEFTRIGHT. */

if (haptic->supported & SDL_HAPTIC_SINE) {
    efx->type = SDL_HAPTIC_SINE;
    efx->periodic.period = 1000;
    efx->periodic.magnitude = 0x4000;
    efx->periodic.length = 5000;
    efx->periodic.attack_length = 0;
    efx->periodic.fade_length = 0;
} else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) {  /* XInput? */
    efx->type = SDL_HAPTIC_LEFTRIGHT;
    efx->leftright.length = 5000;
    efx->leftright.large_magnitude = 0x4000;
    efx->leftright.small_magnitude = 0x4000;
} else {
    return SDL_SetError("Device doesn't support rumble");
}

Directional effects work on Logitech G27 Racing Wheel.

@malashin malashin added the bug This issue describes a bug in the project label Feb 22, 2018
@theGeekPirate
Copy link
Author

theGeekPirate commented Feb 22, 2018

Interesting, I wonder if your first example doesn't work because SDL2 is detecting it as an XInput device instead of an XB One controller.

Thanks for pasting working examples, made testing much easier!

Out of curiosity, which OS are you running?

@theGeekPirate
Copy link
Author

theGeekPirate commented Feb 22, 2018

Also, is there any reason you use sdl.Joystick instead of an sdl.GameController?

Best practice, or preference?

@malashin
Copy link
Collaborator

@theGeekPirate

Interesting, I wonder if your first example doesn't work because SDL2 is detecting it as an XInput device instead of an XB One controller.

As far as I remember is that if you open it as gamepad instead of joystick it will recognize it as Xbox One Contoller. But the example doesn't work because the gamepad doesn't support those effects. XInput is Microsofts API for Xbox Controller, and many other gamepads use it now, instead of legacy DirectInput.

@theGeekPirate
Copy link
Author

theGeekPirate commented Feb 22, 2018

Oh neat, thanks for the information! FWIW, using sdl.GameController still returns the Name as XInput Controller.

@malashin
Copy link
Collaborator

malashin commented Feb 22, 2018

@theGeekPirate

Also, is there any reason you use the sdl.Joystick instead of an sdl.GameController?

The first example was used to test directional effects and since they don't work with gamepads I had to use joystick.

Joysticks are all the peripheral devices like wheels, joysticks, pedals, gamepads. GameController is still a joystick but have different functions and you might not find needed one in GameController methods. You are better off opening it as a GameController and returning sdl.Joystick with this function if needed:

// Joystick returns the Joystick ID from a Game Controller. The game controller builds on the Joystick API, but to be able to use the Joystick's functions with a gamepad, you need to use this first to get the joystick object.
// (https://wiki.libsdl.org/SDL_GameControllerGetJoystick)
func (ctrl *GameController) Joystick() *Joystick {}

HapticOpenFromJoystick() was used in the examples, but there is no equivalent of it for GameControllers. Also I did not need any GameController methods, so it was not opened as one.

// HapticOpenFromJoystick opens a haptic device for use from a joystick device.
// (https://wiki.libsdl.org/SDL_HapticOpenFromJoystick)
func HapticOpenFromJoystick(joy *Joystick) (*Haptic, error) {}

malashin added a commit to malashin/go-sdl2 that referenced this issue Feb 22, 2018
@malashin
Copy link
Collaborator

malashin commented Feb 22, 2018

@theGeekPirate
There is no need for sdl.HapticEffect{} now, pass pointer to sdl.HapticLeftRight{} instead of it.

Check #316 for details.

@malashin malashin added solved? This issue might have been solved but not tested and removed bug This issue describes a bug in the project labels Feb 22, 2018
@theGeekPirate
Copy link
Author

Your commit logs and issue comments are unparalleled.

Thanks for the great work!

@xpander69
Copy link

Same issue here. FFB doesn't work
log reveals that:

107214.718:002f:006d:err:dinput:effect_Download SDL_HapticNewEffect failed (Effect type 128): Haptic: Effect not supported by haptic device.
107214.734:002f:006d:err:dinput:effect_Download SDL_HapticNewEffect failed (Effect type 128): Haptic: Effect not supported by haptic device.

i tried to search what this effect type 128 is, but didnt find anything. I guess i have to downgrade to older version also. The Game works superbly other than that. Just need my FFB

@veeableful
Copy link
Contributor

Hi @xpander69, could you provide a minimal code example and details about your setup? I'll see if I can try to reproduce the problem. Sorry for the late response..

@malashin
Copy link
Collaborator

The issue is most likely in the SDL itself and not in the bindings.

Haptics are fairly weird and each device works differently on different operating systems. I got Xbox One Controller and the list of supported effects is different on Windows and Linux.

I did an example quite a while ago that let's you test which effects are supported:
https://github.com/veandco/go-sdl2-examples/blob/4298a5894b3ec15532eb78de70c71a528095865e/examples/haptic/haptic.go

@xpander69
Copy link

xpander69 commented Dec 10, 2018

@veeableful what you have in mind with the code example? btw i reported in another issue ValveSoftware/Proton#908 (comment)

The effect that failed does not cause the FFB not to work in the newer version of the game, older version of the game has the same error messages in proton log, but FFB still works.

I have logitech Driving Force GT (my G920 should arrive this week)

edit: ahh i now just see that i wrote this message in a totally wrong place :) some links in the proton comments probaby confused me. sorry about that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved? This issue might have been solved but not tested
Projects
None yet
Development

No branches or pull requests

4 participants