-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Comments
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) {} |
From both my PS3 and XB One controllers using your code:
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? |
I should probably mention that a regular |
@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 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. |
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? |
Also, is there any reason you use sdl.Joystick instead of an sdl.GameController? Best practice, or preference? |
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. |
Oh neat, thanks for the information! FWIW, using sdl.GameController still returns the Name as |
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) {} |
@theGeekPirate Check #316 for details. |
Your commit logs and issue comments are unparalleled. Thanks for the great work! |
Same issue here. FFB doesn't work
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 |
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.. |
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: |
@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 |
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
The text was updated successfully, but these errors were encountered: