From b9a2d3a8f4d9b55f66391b3368da146085a77158 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 14:28:20 +0000 Subject: [PATCH] Fixed joystick axes mapping (to be tested) git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1332 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Linux/Joystick.cpp | 19 ++++++------------- src/SFML/Window/Linux/Joystick.hpp | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index e8267d482..4f3ca725f 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -28,13 +28,6 @@ #include #include -#if defined(SFML_SYSTEM_LINUX) - #include - #include -#elif defined(SFML_SYSTEM_FREEBSD) - // #include ? -#endif - namespace sf { @@ -69,7 +62,7 @@ void Joystick::Initialize(unsigned int Index) { // Use non-blocking mode fcntl(myDescriptor, F_SETFL, O_NONBLOCK); - + // Get number of buttons char NbButtons; ioctl(myDescriptor, JSIOCGBUTTONS, &NbButtons); @@ -78,12 +71,12 @@ void Joystick::Initialize(unsigned int Index) myNbButtons = Joy::ButtonCount; // Get the supported axes - char NbAxes, Axes[ABS_MAX + 1]; - ioctl(myDescriptor, JSIOCGAXES, &NbAxes); - ioctl(myDescriptor, JSIOCGAXMAP, Axes); + char NbAxes; + ioctl(myDescriptor, JSIOCGAXES, &NbAxes); + ioctl(myDescriptor, JSIOCGAXMAP, myAxesMapping); for (int i = 0; i < NbAxes; ++i) { - switch (Axes[i]) + switch (myAxesMapping[i]) { case ABS_X : myAxes[Joy::AxisX] = true; break; case ABS_Y : myAxes[Joy::AxisY] = true; break; @@ -114,7 +107,7 @@ JoystickState Joystick::UpdateState() // An axis has been moved case JS_EVENT_AXIS : { - switch (JoyState.number) + switch (myAxesMapping[JoyState.number]) { case ABS_X : myState.Axis[Joy::AxisX] = JoyState.value * 100.f / 32767.f; break; case ABS_Y : myState.Axis[Joy::AxisY] = JoyState.value * 100.f / 32767.f; break; diff --git a/src/SFML/Window/Linux/Joystick.hpp b/src/SFML/Window/Linux/Joystick.hpp index ea780f493..c03bf08e8 100644 --- a/src/SFML/Window/Linux/Joystick.hpp +++ b/src/SFML/Window/Linux/Joystick.hpp @@ -28,6 +28,12 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#if defined(SFML_SYSTEM_LINUX) + #include + #include +#elif defined(SFML_SYSTEM_FREEBSD) + // #include ? +#endif namespace sf @@ -80,12 +86,13 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - int myDescriptor; ///< Linux descriptor of the joystick - unsigned int myNbButtons; ///< Number of buttons supported by the joystick - bool myAxes[Joy::AxisCount]; ///< Supported axes - JoystickState myState; ///< Current state of the joystick - int myPovX; ///< Last X position of the POV - int myPovY; ///< Last Y position of the POV + int myDescriptor; ///< Linux descriptor of the joystick + unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myAxes[Joy::AxisCount]; ///< Supported axes + JoystickState myState; ///< Current state of the joystick + int myPovX; ///< Last X position of the POV + int myPovY; ///< Last Y position of the POV + char myAxesMapping[ABS_MAX + 1]; ///< Axes mapping (index --> axis id) }; } // namespace priv