The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_Haptic : really weird issue with the DirectInput path
sl1nk3


Joined: 14 Nov 2009
Posts: 1
Location: France
Hey, so i'm having a strange issue with SDL_Haptic (latest rev), i'm using it on Windows 7 x64 and the controller is a Sony DualShock (PS2) gamepad.
For some reasons Force Feedback didn't work at all in the app i'm doing, neither did it work on the small test haptic sample included in the doc. So i was a bit clueless, since using plain DirectInput code as the one provided in the DX SDK works quite well.

So i compiled the testhaptic and found out it was "Unable to create effect", actually the IDirectInputDevice2_CreateEffect() func returns "E_INVALIDARG" which is quite odd.

After a bit more testing, i found out my gamepad has 3 FF axis, X axis, Y axis and RZ axis, and SDL uses them all, contrary to the DX SDK sample which only uses X and Y, but it turned out 3 axis can only be used in conjunction with SDL_HAPTIC_CARTESIAN or SDL_HAPTIC_SPHERICAL (while the testhaptic uses SDL_HAPTIC_POLAR everywhere).

Using SDL_HAPTIC_CARTESIAN effectively fixed the issues with creating the effect, but obviously, it still won't rumble, at this point, it seems to be a driver issue though Evil or Very Mad

So just like it's done in DirectInput, it might be a good idea to let the user specify the number of axis to use through a SDL function something like the following : ( "works-for-me" )

What do you guys think ? Am i doing it wrong?

Code:

Index: include/SDL_haptic.h
===================================================================
--- include/SDL_haptic.h   (revision 5241)
+++ include/SDL_haptic.h   (working copy)
@@ -921,10 +921,22 @@
  *  \brief Gets the number of haptic axes the device has.
  * 
  *  \sa SDL_HapticDirection
+ *  \sa SDL_HapticSetAxes
  */
 extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
 
+
+
 /**
+ *  \brief Sets the number of haptic axes to use.
+ * 
+ *  \sa SDL_HapticDirection
+ *  \sa SDL_HapticNumAxes
+ */
+extern DECLSPEC int SDLCALL SDL_HapticSetAxes(SDL_Haptic * haptic, int axes);
+
+
+/**
  *  \brief Checks to see if effect is supported by haptic.
  * 
  *  \param haptic Haptic device to check on.
Index: src/haptic/SDL_haptic.c
===================================================================
--- src/haptic/SDL_haptic.c   (revision 5241)
+++ src/haptic/SDL_haptic.c   (working copy)
@@ -416,6 +416,29 @@
 }
 
 /*
+ * Manually set the number of axis on the device.
+ */
+int
+SDL_HapticSetAxes(SDL_Haptic * haptic, int axes)
+{
+    static int origNaxes = 0;
+
+    if (!ValidHaptic(haptic)) {
+        return -1;
+    }
+
+    if (axes > 0) {
+        if (!origNaxes)
+            origNaxes = haptic->naxes;
+        if (axes <= origNaxes)
+            haptic->naxes = axes;
+      else
+         return -1;
+   }
+    return 0;
+}
+
+/*
  * Checks to see if the device can support the effect.
  */
 int
Index: test/testhaptic.c
===================================================================
--- test/testhaptic.c   (revision 5241)
+++ test/testhaptic.c   (working copy)
@@ -97,6 +97,10 @@
                    SDL_GetError());
             return 1;
         }
+
+        // Use a maximum of 2 axis
+        SDL_HapticSetAxes(haptic, 2);
+
         printf("Device: %s\n", SDL_HapticName(i));
         HapticPrintSupported(haptic);
     } else {
SDL_Haptic : really weird issue with the DirectInput path
Edgar Simo
Guest

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,


The problem with force feedback especially on windows is that the
drivers tend to be loads of steaming crap. Windows on top of it all has
a very "loose" force feedback driver model which makes it so you have to
continuously check a billion of small minor things to see if they're
supported to support all the possible cases. Not to mention the fact
that not all devices actually support what they broadcast among other
things. Mac OS X does it much cleaner (although it's HID code is
horrible). Linux probably takes the cake for cleanest, although it is
missing some bells and whistles the mac os x and windows implementations
have.

The solution of manually overriding the number of axes in C code seems
like a horrible solution. It basically goes against the law of making
things simple. The device should tell you how many axes it has, you
shouldn't have to know how many in advance. Having the SDL developer
have to handle it would just make haptic code for people using SDL more
complicated and ugly.

The way I see it there are 3 solutions of solving it:

1) The real best solution would be to tell the vendor to fix the bugs in
their drivers. Realistically this is probably not going to happen.

2) Create a table of known buggy drivers and try to work around them.
This is a lot of work and pretty hassling since it constantly has to be
maintained and tweaked.

3) Allow the user using ENV_VARS to override different functionality.
The issue is how would you specify which joystick is which? Would only
really be sane in singe-joystick setups.

Personally I would first file bug reports to the drivers. That's the
best solution, SDL shouldn't be responsible for working around buggy
drivers. The second best solution if the manufacturer doesn't fix their
drivers (most likely), would be number 3). However I'm not entirely sure
how to handle this exactly and how much control to give to the user. Not
to mention it still doesn't solve the issue fully since some tables
would have to be maintained with most likely problems and how to fix
them (like changing number of axes).


Edgar

sl1nk3 wrote:
| Hey, so i'm having a strange issue with SDL_Haptic (latest rev), i'm
using it on Windows 7 x64 and the controller is a Sony DualShock (PS2)
gamepad.
| For some reasons Force Feedback didn't work at all in the app i'm
doing, neither did it work on the small test haptic sample included in
the doc. So i was a bit clueless, since using plain DirectInput code as
the one provided in the DX SDK works quite well.
|
| So i compiled the testhaptic and found out it was "Unable to create
effect", actually the IDirectInputDevice2_CreateEffect() func returns
"E_INVALIDARG" which is quite odd.
|
| After a bit more testing, i found out my gamepad has 3 FF axis, X
axis, Y axis and RZ axis, and SDL uses them all, contrary to the DX SDK
sample which only uses X and Y, but it turned out 3 axis can only be
used in conjunction with SDL_HAPTIC_CARTESIAN or SDL_HAPTIC_SPHERICAL
(while the testhaptic uses SDL_HAPTIC_POLAR everywhere).
|
| Using SDL_HAPTIC_CARTESIAN effectively fixed the issues with creating
the effect, but obviously, it still won't rumble, at this point, it
seems to be a driver issue though [Evil or Very Mad]
|
| So just like it's done in DirectInput, it might be a good idea to let
the user specify the number of axis to use through a SDL function
something like the following : ( "works-for-me" )
|
| What do you guys think ? Am i doing it wrong?
|
|
| Code:
|
| Index: include/SDL_haptic.h
| ===================================================================
| --- include/SDL_haptic.h (revision 5241)
| +++ include/SDL_haptic.h (working copy)
| @@ -921,10 +921,22 @@
| * \brief Gets the number of haptic axes the device has.
| *
| * \sa SDL_HapticDirection
| + * \sa SDL_HapticSetAxes
| */
| extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
|
| +
| +
| /**
| + * \brief Sets the number of haptic axes to use.
| + *
| + * \sa SDL_HapticDirection
| + * \sa SDL_HapticNumAxes
| + */
| +extern DECLSPEC int SDLCALL SDL_HapticSetAxes(SDL_Haptic * haptic,
int axes);
| +
| +
| +/**
| * \brief Checks to see if effect is supported by haptic.
| *
| * \param haptic Haptic device to check on.
| Index: src/haptic/SDL_haptic.c
| ===================================================================
| --- src/haptic/SDL_haptic.c (revision 5241)
| +++ src/haptic/SDL_haptic.c (working copy)
| @@ -416,6 +416,29 @@
| }
|
| /*
| + * Manually set the number of axis on the device.
| + */
| +int
| +SDL_HapticSetAxes(SDL_Haptic * haptic, int axes)
| +{
| + static int origNaxes = 0;
| +
| + if (!ValidHaptic(haptic)) {
| + return -1;
| + }
| +
| + if (axes > 0) {
| + if (!origNaxes)
| + origNaxes = haptic->naxes;
| + if (axes <= origNaxes)
| + haptic->naxes = axes;
| + else
| + return -1;
| + }
| + return 0;
| +}
| +
| +/*
| * Checks to see if the device can support the effect.
| */
| int
| Index: test/testhaptic.c
| ===================================================================
| --- test/testhaptic.c (revision 5241)
| +++ test/testhaptic.c (working copy)
| @@ -97,6 +97,10 @@
| SDL_GetError());
| return 1;
| }
| +
| + // Use a maximum of 2 axis
| + SDL_HapticSetAxes(haptic, 2);
| +
| printf("Device: %s\n", SDL_HapticName(i));
| HapticPrintSupported(haptic);
| } else {
|
|
|
|
|
|
|
|
|
|
| ------------------------------------------------------------------------
|
| _______________________________________________
| SDL mailing list
|
| http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkr/EmcACgkQolm4VNX3QTyCAACeP7DSca8Wqq5rZDTXMxTJWSLF
ovkAoKX5D5yvQZxmDMdnxxxL8rx88lxt
=jf9t
-----END PGP SIGNATURE-----
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
similar problem
elboato


Joined: 07 Nov 2009
Posts: 5
Hei there!

Did you solve the problem yet? I think i might have a similar one. I made this Joystick driver for Java (http://boat.lachsfeld.at/ffjoystick4java/) and with the Logitech Force 3D Pro Joystick (2 FF axes) everything worked fine. The Saitek Evo Force stick on the other hand (it has 3 FF axes, or at least it says so) does not work at all.

On Linux it seems to be just not supported at all. On Windows it works in the control panel and SDL sees it as a force feedback device. If i query for supported effects, all types of effects are said to be supported. But whatever direction I use, and whatever type of direction I use, when I want to upload an effect I get "Unable to create effect"....

And btw: this was on Windows XP. On Windows 7 64bit already the control panel caused the system driver dll to crash, whenever I tried to play an effect....

All the best,

elboato