Exposed some of the joystick stuff to the haptic subsystem. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Wed, 02 Jul 2008 08:24:35 +0000
branchgsoc2008_force_feedback
changeset 248996adc8025331
parent 2488 8e2bdbccf7ff
child 2490 be9b206d44af
Exposed some of the joystick stuff to the haptic subsystem.
Added SDL_JoystickIsHaptic().
include/SDL_haptic.h
src/haptic/SDL_haptic.c
src/haptic/linux/SDL_syshaptic.c
src/joystick/SDL_joystick.c
src/joystick/SDL_joystick_c.h
src/joystick/linux/SDL_sysjoystick.c
src/joystick/linux/SDL_sysjoystick_c.h
     1.1 --- a/include/SDL_haptic.h	Tue Jul 01 18:35:05 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Wed Jul 02 08:24:35 2008 +0000
     1.3 @@ -31,6 +31,7 @@
     1.4  
     1.5  #include "SDL_stdinc.h"
     1.6  #include "SDL_error.h"
     1.7 +#include "SDL_joystick.h"
     1.8  
     1.9  #include "begin_code.h"
    1.10  /* Set up for C function definitions, even when using C++ */
    1.11 @@ -207,6 +208,22 @@
    1.12   */
    1.13  extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
    1.14  
    1.15 +/*
    1.16 + * Checks to see if a joystick has haptic features.
    1.17 + *
    1.18 + * Returns SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't
    1.19 + * and -1 on error.
    1.20 + */
    1.21 +extern DECLSPEC int SDL_JoystickIsHaptic(SDL_Joystick * joystick);
    1.22 +
    1.23 +/*
    1.24 + * Opens a Haptic device for usage from a Joystick device.
    1.25 + *
    1.26 + * Returns a valid pointer to a haptic device on success or NULL
    1.27 + * if an error occurred.
    1.28 + */
    1.29 +extern DECLSPEC SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick * joystick);
    1.30 +
    1.31  /* 
    1.32   * Closes a Haptic device previously opened with SDL_HapticOpen.
    1.33   */
     2.1 --- a/src/haptic/SDL_haptic.c	Tue Jul 01 18:35:05 2008 +0000
     2.2 +++ b/src/haptic/SDL_haptic.c	Wed Jul 02 08:24:35 2008 +0000
     2.3 @@ -23,6 +23,7 @@
     2.4  
     2.5  #include "SDL_haptic_c.h"
     2.6  #include "SDL_syshaptic.h"
     2.7 +#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */
     2.8  
     2.9  
    2.10  static Uint8 SDL_numhaptics = 0;
    2.11 @@ -131,6 +132,39 @@
    2.12  
    2.13  
    2.14  /*
    2.15 + * Returns SDL_TRUE if joystick has haptic features.
    2.16 + */
    2.17 +int
    2.18 +SDL_JoystickIsHaptic(SDL_Joystick * joystick)
    2.19 +{
    2.20 +   int ret;
    2.21 +
    2.22 +   if (!SDL_PrivateJoystickValid(&joystick)) {
    2.23 +      return -1;
    2.24 +   }
    2.25 +
    2.26 +   ret = SDL_SYS_JoystickIsHaptic(joystick);
    2.27 +
    2.28 +   if (ret > 0) return SDL_TRUE;
    2.29 +   else if (ret == 0) return SDL_FALSE;
    2.30 +   else return -1;
    2.31 +}
    2.32 +
    2.33 +
    2.34 +/*
    2.35 + * Opens a haptic device from a joystick.
    2.36 + */
    2.37 +SDL_Haptic *
    2.38 +SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
    2.39 +{
    2.40 +   if (!SDL_PrivateJoystickValid(&joystick)) {
    2.41 +      return -1;
    2.42 +   }
    2.43 +   return -1;
    2.44 +}
    2.45 +
    2.46 +
    2.47 +/*
    2.48   * Checks to see if the haptic device is valid
    2.49   */
    2.50  static int
     3.1 --- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 18:35:05 2008 +0000
     3.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Wed Jul 02 08:24:35 2008 +0000
     3.3 @@ -26,6 +26,9 @@
     3.4  #include "SDL_haptic.h"
     3.5  #include "../SDL_haptic_c.h"
     3.6  #include "../SDL_syshaptic.h"
     3.7 +#include "SDL_joystick.h"
     3.8 +#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
     3.9 +#include "../../joystick/linux/SDL_sysjoystick_c.h" /* For joystick hwdata */ 
    3.10  
    3.11  #include <unistd.h> /* close */
    3.12  #include <linux/input.h>
    3.13 @@ -244,6 +247,27 @@
    3.14  
    3.15  
    3.16  /*
    3.17 + * Checks to see if a joystick has haptic features.
    3.18 + */
    3.19 +int
    3.20 +SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
    3.21 +{
    3.22 +   if (EV_IsHaptic(joystick->hwdata->fd) > 0)
    3.23 +      return 1;
    3.24 +   return 0;
    3.25 +}
    3.26 +
    3.27 +
    3.28 +/*
    3.29 + * Opens a SDL_Haptic from a SDL_Joystick.
    3.30 + */
    3.31 +int
    3.32 +SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
    3.33 +{
    3.34 +}
    3.35 +
    3.36 +
    3.37 +/*
    3.38   * Closes the haptic device.
    3.39   */
    3.40  void
    3.41 @@ -604,5 +628,4 @@
    3.42  }
    3.43  
    3.44  
    3.45 -
    3.46  #endif /* SDL_HAPTIC_LINUX */
     4.1 --- a/src/joystick/SDL_joystick.c	Tue Jul 01 18:35:05 2008 +0000
     4.2 +++ b/src/joystick/SDL_joystick.c	Wed Jul 02 08:24:35 2008 +0000
     4.3 @@ -193,8 +193,12 @@
     4.4      return (opened);
     4.5  }
     4.6  
     4.7 -static int
     4.8 -ValidJoystick(SDL_Joystick ** joystick)
     4.9 +
    4.10 +/*
    4.11 + * Checks to make sure the joystick is valid.
    4.12 + */
    4.13 +int
    4.14 +SDL_PrivateJoystickValid(SDL_Joystick ** joystick)
    4.15  {
    4.16      int valid;
    4.17  
    4.18 @@ -216,7 +220,7 @@
    4.19  int
    4.20  SDL_JoystickIndex(SDL_Joystick * joystick)
    4.21  {
    4.22 -    if (!ValidJoystick(&joystick)) {
    4.23 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.24          return (-1);
    4.25      }
    4.26      return (joystick->index);
    4.27 @@ -228,7 +232,7 @@
    4.28  int
    4.29  SDL_JoystickNumAxes(SDL_Joystick * joystick)
    4.30  {
    4.31 -    if (!ValidJoystick(&joystick)) {
    4.32 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.33          return (-1);
    4.34      }
    4.35      return (joystick->naxes);
    4.36 @@ -240,7 +244,7 @@
    4.37  int
    4.38  SDL_JoystickNumHats(SDL_Joystick * joystick)
    4.39  {
    4.40 -    if (!ValidJoystick(&joystick)) {
    4.41 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.42          return (-1);
    4.43      }
    4.44      return (joystick->nhats);
    4.45 @@ -252,7 +256,7 @@
    4.46  int
    4.47  SDL_JoystickNumBalls(SDL_Joystick * joystick)
    4.48  {
    4.49 -    if (!ValidJoystick(&joystick)) {
    4.50 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.51          return (-1);
    4.52      }
    4.53      return (joystick->nballs);
    4.54 @@ -264,7 +268,7 @@
    4.55  int
    4.56  SDL_JoystickNumButtons(SDL_Joystick * joystick)
    4.57  {
    4.58 -    if (!ValidJoystick(&joystick)) {
    4.59 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.60          return (-1);
    4.61      }
    4.62      return (joystick->nbuttons);
    4.63 @@ -278,7 +282,7 @@
    4.64  {
    4.65      Sint16 state;
    4.66  
    4.67 -    if (!ValidJoystick(&joystick)) {
    4.68 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.69          return (0);
    4.70      }
    4.71      if (axis < joystick->naxes) {
    4.72 @@ -298,7 +302,7 @@
    4.73  {
    4.74      Uint8 state;
    4.75  
    4.76 -    if (!ValidJoystick(&joystick)) {
    4.77 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.78          return (0);
    4.79      }
    4.80      if (hat < joystick->nhats) {
    4.81 @@ -318,7 +322,7 @@
    4.82  {
    4.83      int retval;
    4.84  
    4.85 -    if (!ValidJoystick(&joystick)) {
    4.86 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.87          return (-1);
    4.88      }
    4.89  
    4.90 @@ -347,7 +351,7 @@
    4.91  {
    4.92      Uint8 state;
    4.93  
    4.94 -    if (!ValidJoystick(&joystick)) {
    4.95 +    if (!SDL_PrivateJoystickValid(&joystick)) {
    4.96          return (0);
    4.97      }
    4.98      if (button < joystick->nbuttons) {
    4.99 @@ -367,7 +371,7 @@
   4.100  {
   4.101      int i;
   4.102  
   4.103 -    if (!ValidJoystick(&joystick)) {
   4.104 +    if (!SDL_PrivateJoystickValid(&joystick)) {
   4.105          return;
   4.106      }
   4.107  
     5.1 --- a/src/joystick/SDL_joystick_c.h	Tue Jul 01 18:35:05 2008 +0000
     5.2 +++ b/src/joystick/SDL_joystick_c.h	Wed Jul 02 08:24:35 2008 +0000
     5.3 @@ -36,4 +36,8 @@
     5.4                                    Uint8 hat, Uint8 value);
     5.5  extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
     5.6                                       Uint8 button, Uint8 state);
     5.7 +
     5.8 +/* Internal sanity checking functions */
     5.9 +extern int SDL_PrivateJoystickValid(SDL_Joystick ** joystick);
    5.10 +
    5.11  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Tue Jul 01 18:35:05 2008 +0000
     6.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Wed Jul 02 08:24:35 2008 +0000
     6.3 @@ -31,13 +31,11 @@
     6.4  #include <sys/ioctl.h>
     6.5  #include <limits.h>             /* For the definition of PATH_MAX */
     6.6  #include <linux/joystick.h>
     6.7 -#if SDL_INPUT_LINUXEV
     6.8 -#include <linux/input.h>
     6.9 -#endif
    6.10  
    6.11  #include "SDL_joystick.h"
    6.12  #include "../SDL_sysjoystick.h"
    6.13  #include "../SDL_joystick_c.h"
    6.14 +#include "SDL_sysjoystick_c.h"
    6.15  
    6.16  /* Special joystick configurations */
    6.17  static struct
    6.18 @@ -278,35 +276,6 @@
    6.19  } SDL_joylist[MAX_JOYSTICKS];
    6.20  
    6.21  
    6.22 -/* The private structure used to keep track of a joystick */
    6.23 -struct joystick_hwdata
    6.24 -{
    6.25 -    int fd;
    6.26 -    /* The current linux joystick driver maps hats to two axes */
    6.27 -    struct hwdata_hat
    6.28 -    {
    6.29 -        int axis[2];
    6.30 -    } *hats;
    6.31 -    /* The current linux joystick driver maps balls to two axes */
    6.32 -    struct hwdata_ball
    6.33 -    {
    6.34 -        int axis[2];
    6.35 -    } *balls;
    6.36 -
    6.37 -    /* Support for the Linux 2.4 unified input interface */
    6.38 -#if SDL_INPUT_LINUXEV
    6.39 -    SDL_bool is_hid;
    6.40 -    Uint8 key_map[KEY_MAX - BTN_MISC];
    6.41 -    Uint8 abs_map[ABS_MAX];
    6.42 -    struct axis_correct
    6.43 -    {
    6.44 -        int used;
    6.45 -        int coef[3];
    6.46 -    } abs_correct[ABS_MAX];
    6.47 -#endif
    6.48 -};
    6.49 -
    6.50 -
    6.51  #ifndef NO_LOGICAL_JOYSTICKS
    6.52  
    6.53  static int
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/joystick/linux/SDL_sysjoystick_c.h	Wed Jul 02 08:24:35 2008 +0000
     7.3 @@ -0,0 +1,53 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997-2006 Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Lesser General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2.1 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Lesser General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Lesser General Public
    7.19 +    License along with this library; if not, write to the Free Software
    7.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@libsdl.org
    7.24 +*/
    7.25 +
    7.26 +#if SDL_INPUT_LINUXEV
    7.27 +#include <linux/input.h>
    7.28 +#endif
    7.29 +
    7.30 +/* The private structure used to keep track of a joystick */
    7.31 +struct joystick_hwdata
    7.32 +{
    7.33 +   int fd;
    7.34 +   /* The current linux joystick driver maps hats to two axes */
    7.35 +   struct hwdata_hat
    7.36 +   {   
    7.37 +      int axis[2];
    7.38 +   } *hats;
    7.39 +   /* The current linux joystick driver maps balls to two axes */
    7.40 +   struct hwdata_ball
    7.41 +   {   
    7.42 +      int axis[2];
    7.43 +   } *balls;
    7.44 +
    7.45 +   /* Support for the Linux 2.4 unified input interface */
    7.46 +#if SDL_INPUT_LINUXEV
    7.47 +   SDL_bool is_hid;
    7.48 +   Uint8 key_map[KEY_MAX - BTN_MISC];
    7.49 +   Uint8 abs_map[ABS_MAX];
    7.50 +   struct axis_correct
    7.51 +   {
    7.52 +      int used;
    7.53 +      int coef[3];
    7.54 +   } abs_correct[ABS_MAX];
    7.55 +#endif
    7.56 +};