Page 1 of 1

Trouble getting the joypad buttons

Posted: Tue Jan 04, 2011 4:50 pm
by markand

Hi,

 

I told a few days ago on IRC that I have a problem with a Saitek joypad. This joypad sends useless information on each press so it fills the input dialog with the same thing even if I press different buttons.

 

As you can see here (from SDL/test source directory) a joystick tester that prints every button information from a joystick, that what happening when I press two buttons :

 

Code: Select all

markand@Melon ~ $ sdl-joytest -
There are 1 joysticks attached
Joystick 0: 0x0004 (0)
      axes: 4
     balls: 0
      hats: 1
   buttons: 12
Watching joystick 0: (Joystick (0))
Joystick has 4 axes, 1 hats, 0 balls, and 12 buttons
Joystick 0 hat 0 value: centered
Joystick 0 button 3 down
Joystick 0 hat 0 value: centered
Joystick 0 button 3 up
Joystick 0 hat 0 value: centered
Joystick 0 button 2 down
Joystick 0 hat 0 value: centered
Joystick 0 button 2 up

 

We can see the hat 0 value that may cause de problem, so when I try to fill the dialog input it does the following :

 

I put the focus on the first entry (Up) and I press one button, as you can see it fill two inputs directly with the same value.

 

Screenshot of input dialog: http://files.malikania.fr/dialog.png

 

The button pressed was one of the four at right: http://i2.cdiscount.com/pdt/P/2/1/1/f/PP21.jpg

 

If you have any clue to fix that.. My knowledge in SDL are not enough to fix it right now.

 

Note: this bug does not appears with zsnes, snes9x-gtk and other SDL joystick capable application.


Trouble getting the joypad buttons

Posted: Sun Jan 09, 2011 12:48 pm
by markand

Hi, finally kode54 made a successfully working patch. If you agree on you can commit them to the main branch :

 

Code: Select all

--- src/gtk/joypadconfig.cpp.orig	2008-09-26 20:25:23.000000000 +0200
+++ src/gtk/joypadconfig.cpp	2011-01-06 17:53:43.000000000 +0100
@@ -144,9 +144,17 @@
      else if (what < 0x30)
      {
        // joystick hat
+        int dir = (what & 3);
        what = (what & 15);
        what >>= 2;
-        os << " Hat " << what;
+        os << " Hat " << what << " ";
+	switch (dir)
+	{
+	  case 0: os << "Up"; break;
+	  case 1: os << "Down"; break;
+	  case 2: os << "Right"; break;
+	  case 3: os << "Left"; break;
+	}
      }

      csName = os.str().c_str();
@@ -209,6 +217,7 @@
  }

  int code = inputGetEventCode(event);
+  if (!code) return;
  inputSetKeymap(m_ePad, m_astKeys[m_iCurrentEntry].m_eKeyFlag, code);
  vUpdateEntries();

@@ -241,11 +250,17 @@
      }
      vEmptyEventQueue();
      break;
-    case SDL_JOYHATMOTION:
    case SDL_JOYBUTTONUP:
      vOnInputEvent(event);
      vEmptyEventQueue();
      break;
+    case SDL_JOYHATMOTION:
+      if (event.jhat.value)
+      {
+	vOnInputEvent(event);
+	vEmptyEventQueue();
+      }
+      break;
    }
  }

 

And

 

Code: Select all

--- src/sdl/inputSDL.cpp.orig	2008-11-29 12:19:27.000000000 +0100
+++ src/sdl/inputSDL.cpp	2011-01-06 17:53:43.000000000 +0100
@@ -84,8 +84,11 @@

static uint32_t sdlGetHatCode(const SDL_Event &event)
{
+    if (!event.jhat.value) return 0;
+    
return ( ((event.jhat.which + 1) << 16) | + 32 | (event.jhat.hat << 2) | ( event.jhat.value & SDL_HAT_UP ? 0 : @@ -106,6 +109,8 @@ static uint32_t sdlGetAxisCode(const SDL_Event &event) { + if (event.jaxis.value >= -16384 && event.jaxis.value <= 16384) return 0; + return ( ((event.jaxis.which + 1) << 16) | (event.jaxis.axis << 1) |

 

Thanks!


Trouble getting the joypad buttons

Posted: Thu Jan 13, 2011 2:28 am
by spacy51

Are you by any chance the guy that was on the 27C3 and hacked the PS3?