Re: [hatari-devel] joystick subsystem patch for configurable axis mapping

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Am Montag, den 12.12.2011, 23:34 +0200 schrieb Eero Tamminen: 
> Hi,
> 
> On maanantai 12 joulukuu 2011, Matthias Arndt wrote:
> > Am Sonntag, den 11.12.2011, 22:38 +0100 schrieb Nicolas Pomarède:
> > > Hello
> > > 
> > > could you provide these changes as some diff files instead please ?
> > > It's easier to see what is modified.
> > 
> > If you tell me howto create those patches.
> 
> "hg diff"
> 
> > I'd prefer to commit directly anyway.
> 
> 
> 	- Eero
> 

Thanks, it took me some time to figure out that I had to mention a
specific revision.

Hope the patches work.

Regards,
Matthias
-- 
Matthias Arndt <marndt@xxxxxxxxxxxxxx>
PGP-Key: http://www.final-memory.org/files/marndt.asc
Jabber: simonsunnyboy@xxxxxxxxxxxxxxxx
diff -r 9e2869935d52 src/joy.c
--- a/src/joy.c	Sat Nov 13 21:55:55 2010 +0100
+++ b/src/joy.c	Tue Dec 13 17:45:45 2011 +0100
@@ -29,10 +29,16 @@
 	NULL, NULL, NULL, NULL, NULL, NULL
 };
 
+/* Further explanation see JoyInit() */
+static JOYAXISMAPPING *sdlJoystickMapping[6] = /* references which axis are actually in use by the selected SDL joystick */
+{
+    NULL, NULL, NULL, NULL, NULL, NULL
+};
+
 static bool bJoystickWorking[6] =       /* Is joystick plugged in and working? */
 {
-	false, false, false, false, false, false
-}; 
+    NULL, NULL, NULL, NULL, NULL, NULL
+};
 
 int JoystickSpaceBar = false;           /* State of space-bar on joystick button 2 */
 static Uint8 nJoyKeyEmu[6];
@@ -45,8 +51,29 @@
  */
 void Joy_Init(void)
 {
+    /* Joystick axis mapping table                        */
+    /* Matthias Arndt <marndt@xxxxxxxxxxxxxx>             */
+    /* Somehow, not all SDL joysticks are created equal.  */
+    /* Not all pads or sticks use axis 0 for x and axis 1 */
+    /* for y information.                                 */
+    /* This table allows to remap the axis to used.       */
+    /* A joystick is identified by its SDL name and       */
+    /* followed by the X axis to use and the Y axis.      */
+    /* Find out the axis number with the tool jstest.     */
+
+    /* FIXME: Read those settings from a configuration file and make them tunable from the GUI. */
+    static JOYAXISMAPPING AxisMappingTable [] =
+    {
+        /* USB game pad with ID ID 0079:0011, sold by Speedlink*/
+        {"USB Gamepad" , 3, 4},
+        /* default entry, is used if no other SDL joystick name does match */
+        {"*DEFAULT*" , 0, 1},
+    };
+
 	int i, nPadsConnected;
 
+	JOYAXISMAPPING *thismapping;
+
 	/* Initialise SDL's joystick subsystem: */
 	if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
 	{
@@ -66,6 +93,21 @@
 			/* Set as working */
 			bJoystickWorking[i] = true;
 			Log_Printf(LOG_DEBUG, "Joystick %i: %s\n", i, SDL_JoystickName(i));
+			/* determine joystick axis mapping for given SDL joystick name: */
+			thismapping = AxisMappingTable;
+			while(strcmp(thismapping->SDLJoystickName, "*DEFAULT*") != 0)
+			{
+                /* check if ID string matches teh wone reported by SDL: */
+                if(strncmp(thismapping->SDLJoystickName, SDL_JoystickName(i),strlen(thismapping->SDLJoystickName)) == 0)
+                {
+                    break;
+                }
+			    /* iterate mapping table: */
+                thismapping++;
+			}
+
+            sdlJoystickMapping[i] = thismapping;
+            Log_Printf(LOG_DEBUG, "Joystick %i maps axis %d and %d\n", i, sdlJoystickMapping[i]->XAxisID, sdlJoystickMapping[i]->YAxisID);
 		}
 	}
 
@@ -143,9 +185,9 @@
 	         && bJoystickWorking[nSdlJoyId])
 	{
 		/* get joystick axis from configuration settings and make them plausible */
-		JoyReading.XAxisID = 0;
-		JoyReading.YAxisID = 1;
-		
+		JoyReading.XAxisID = sdlJoystickMapping[nSdlJoyId]->XAxisID;
+		JoyReading.YAxisID = sdlJoystickMapping[nSdlJoyId]->YAxisID;
+
 		/* make selected axis IDs plausible */
 		if(  (JoyReading.XAxisID == JoyReading.YAxisID) /* same joystick axis for two directions? */
 		   ||(JoyReading.XAxisID > nAxes)               /* ID for x axis beyond nr of existing axes? */
@@ -156,7 +198,7 @@
 			JoyReading.XAxisID = 0;
 			JoyReading.YAxisID = 1;
 		}
-		
+
 		/* Read real joystick and map to emulated ST joystick for emulation */
 		if (!Joy_ReadJoystick(nSdlJoyId, &JoyReading))
 		{
diff -r 9e2869935d52 src/includes/joy.h
--- a/src/includes/joy.h	Sat Nov 13 21:55:55 2010 +0100
+++ b/src/includes/joy.h	Tue Dec 13 17:45:54 2011 +0100
@@ -11,10 +11,16 @@
 typedef struct
 {
 	int XPos,YPos;                /* the actually read axis values in range of -32768...0...32767 */
-	int XAxisID,YAxisID;          /* the IDs of the physical PC jyostick's axis to be used to gain ST joystick axis input */
+	int XAxisID,YAxisID;          /* the IDs of the physical PC joystick's axis to be used to gain ST joystick axis input */
 	int Buttons;                  /* JOY_BUTTON1 */
 } JOYREADING;
 
+typedef struct
+{
+    char SDLJoystickName[50];
+    int XAxisID,YAxisID;           /* the IDs associated with a certain SDL joystick */
+} JOYAXISMAPPING;
+
 enum
 {
 	JOYSTICK_SPACE_NULL,          /* Not up/down */


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/