First commit of the SDL_haptic subsystem. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Sun, 01 Jun 2008 11:44:25 +0000
branchgsoc2008_force_feedback
changeset 24723f73c88c9abb
parent 2471 910af9032c73
child 2473 20730743769d
First commit of the SDL_haptic subsystem.
Code compiles and works, very limited functionality (linux only).
configure.in
include/SDL.h
include/SDL_haptic.h
src/SDL.c
src/haptic/SDL_haptic.c
src/haptic/SDL_haptic_c.h
src/haptic/SDL_syshaptic.h
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/configure.in	Wed Apr 23 06:26:07 2008 +0000
     1.2 +++ b/configure.in	Sun Jun 01 11:44:25 2008 +0000
     1.3 @@ -235,6 +235,14 @@
     1.4  else
     1.5      SOURCES="$SOURCES $srcdir/src/joystick/*.c"
     1.6  fi
     1.7 +AC_ARG_ENABLE(haptic,
     1.8 +AC_HELP_STRING([--enable-haptic], [Enable the haptic (force feedback) subsystem [[default=yes]]]),
     1.9 +              , enable_haptic=yes)
    1.10 +if test x$enable_haptic != xyes; then
    1.11 +    AC_DEFINE(SDL_HAPTIC_DISABLE)
    1.12 +else
    1.13 +    SOURCES="$SOURCES $srcdir/src/haptic/*.c"
    1.14 +fi
    1.15  AC_ARG_ENABLE(cdrom,
    1.16  AC_HELP_STRING([--enable-cdrom], [Enable the cdrom subsystem [[default=yes]]]),
    1.17                , enable_cdrom=yes)
    1.18 @@ -2176,6 +2184,16 @@
    1.19              ;;
    1.20            esac
    1.21          fi
    1.22 +        # Set up files for the haptic library
    1.23 +        if test x$enable_haptic = xyes; then
    1.24 +          case $ARCH in
    1.25 +            linux)
    1.26 +                AC_DEFINE(SDL_HAPTIC_LINUX)
    1.27 +                SOURCES="$SOURCES $srcdir/src/haptic/linux/*.c"
    1.28 +                have_haptic=yes
    1.29 +            ;;
    1.30 +          esac
    1.31 +        fi
    1.32          # Set up files for the cdrom library
    1.33          if test x$enable_cdrom = xyes; then
    1.34            case $ARCH in
     2.1 --- a/include/SDL.h	Wed Apr 23 06:26:07 2008 +0000
     2.2 +++ b/include/SDL.h	Sun Jun 01 11:44:25 2008 +0000
     2.3 @@ -109,6 +109,7 @@
     2.4  #define SDL_INIT_VIDEO		0x00000020
     2.5  #define SDL_INIT_CDROM		0x00000100
     2.6  #define SDL_INIT_JOYSTICK	0x00000200
     2.7 +#define SDL_INIT_HAPTIC    0x00001000
     2.8  #define SDL_INIT_NOPARACHUTE	0x00100000      /* Don't catch fatal signals */
     2.9  #define SDL_INIT_EVENTTHREAD	0x01000000      /* Not supported on all OS's */
    2.10  #define SDL_INIT_EVERYTHING	0x0000FFFF
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/include/SDL_haptic.h	Sun Jun 01 11:44:25 2008 +0000
     3.3 @@ -0,0 +1,87 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 2008 Edgar Simo
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +
    3.26 +/**
    3.27 + * \file SDL_haptic.h
    3.28 + *
    3.29 + * Include file for SDL haptic subsystem
    3.30 + */
    3.31 +
    3.32 +#ifndef _SDL_haptic_h
    3.33 +#define _SDL_haptic_h
    3.34 +
    3.35 +#include "SDL_stdinc.h"
    3.36 +#include "SDL_error.h"
    3.37 +
    3.38 +#include "begin_code.h"
    3.39 +/* Set up for C function definitions, even when using C++ */
    3.40 +#ifdef __cplusplus
    3.41 +/* *INDENT-OFF* */
    3.42 +extern "C" {
    3.43 +   /* *INDENT-ON* */                                                         
    3.44 +#endif
    3.45 +
    3.46 +/* The haptic structure used to identify an SDL haptic */
    3.47 +struct _SDL_Haptic;                                                     
    3.48 +typedef struct _SDL_Haptic SDL_Haptic;
    3.49 +
    3.50 +
    3.51 +/* Different effects that can be generated */
    3.52 +#define SDL_HAPTIC_CONSTANT   (1<<0)
    3.53 +#define SDL_HAPTIC_PERIODIC   (1<<1)
    3.54 +#define SDL_HAPTIC_RAMP       (1<<2)
    3.55 +#define SDL_HAPTIC_SPRING     (1<<3)
    3.56 +#define SDL_HAPTIC_FRICTION   (1<<4)
    3.57 +#define SDL_HAPTIC_DAMPER     (1<<5)
    3.58 +#define SDL_HAPTIC_RUMBLE     (1<<6)
    3.59 +#define SDL_HAPTIC_INERTIA    (1<<7)
    3.60 +#define SDL_HAPTIC_GAIN       (1<<8)
    3.61 +#define SDL_HAPTIC_AUTOCENTER (1<<9)
    3.62 +
    3.63 +
    3.64 +/* Function prototypes */
    3.65 +/*
    3.66 + * Count the number of joysticks attached to the system
    3.67 + */
    3.68 +extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
    3.69 +
    3.70 +/*
    3.71 + * Get the implementation dependent name of a joystick.
    3.72 + * This can be called before any joysticks are opened.
    3.73 + * If no name can be found, this function returns NULL.
    3.74 + */
    3.75 +extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
    3.76 +
    3.77 +
    3.78 +/* Ends C function definitions when using C++ */
    3.79 +#ifdef __cplusplus
    3.80 +/* *INDENT-OFF* */
    3.81 +}
    3.82 +/* *INDENT-ON* */
    3.83 +#endif
    3.84 +#include "close_code.h"
    3.85 +
    3.86 +#endif /* _SDL_haptic_h */
    3.87 +
    3.88 +/* vi: set ts=4 sw=4 expandtab: */
    3.89 +
    3.90 +
     4.1 --- a/src/SDL.c	Wed Apr 23 06:26:07 2008 +0000
     4.2 +++ b/src/SDL.c	Sun Jun 01 11:44:25 2008 +0000
     4.3 @@ -38,6 +38,10 @@
     4.4  extern int SDL_JoystickInit(void);
     4.5  extern void SDL_JoystickQuit(void);
     4.6  #endif
     4.7 +#if !SDL_HAPTIC_DISABLED
     4.8 +extern int SDL_HapticInit(void);
     4.9 +extern int SDL_HapticQuit(void);
    4.10 +#endif
    4.11  #if !SDL_CDROM_DISABLED
    4.12  extern int SDL_CDROMInit(void);
    4.13  extern void SDL_CDROMQuit(void);
    4.14 @@ -123,6 +127,22 @@
    4.15      }
    4.16  #endif
    4.17  
    4.18 +#if !SDL_HAPTIC_DISABLED
    4.19 +    /* Initialize the haptic subsystem */
    4.20 +    if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) {
    4.21 +        if (SDL_HapticInit() < 0) {
    4.22 +            return (-1);
    4.23 +        }
    4.24 +        SDL_initialized |= SDL_INIT_HAPTIC;
    4.25 +    }
    4.26 +#else
    4.27 +    if (flags & SDL_INIT_HAPTIC) {
    4.28 +        SDL_SetError("SDL not built with haptic (force feedback) support");
    4.29 +        return (-1);
    4.30 +    }
    4.31 +#endif
    4.32 +
    4.33 +
    4.34  #if !SDL_CDROM_DISABLED
    4.35      /* Initialize the CD-ROM subsystem */
    4.36      if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
    4.37 @@ -180,6 +200,12 @@
    4.38          SDL_initialized &= ~SDL_INIT_JOYSTICK;
    4.39      }
    4.40  #endif
    4.41 +#if !SDL_HAPTIC_DISABLED
    4.42 +    if ((flags & SDL_initialized & SDL_INIT_HAPTIC)) {
    4.43 +        SDL_HapticQuit();
    4.44 +        SDL_initialized &= ~SDL_INIT_HAPTIC;
    4.45 +    }
    4.46 +#endif
    4.47  #if !SDL_TIMERS_DISABLED
    4.48      if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
    4.49          SDL_TimerQuit();
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/haptic/SDL_haptic.c	Sun Jun 01 11:44:25 2008 +0000
     5.3 @@ -0,0 +1,127 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 2008 Edgar Simo
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +#include "SDL_config.h"
    5.26 +
    5.27 +#include "SDL_haptic_c.h"
    5.28 +#include "SDL_syshaptic.h"
    5.29 +
    5.30 +
    5.31 +static Uint8 SDL_numhaptics = 0;
    5.32 +SDL_Haptic **SDL_haptics = NULL;
    5.33 +static SDL_Haptic *default_haptic = NULL;
    5.34 +
    5.35 +
    5.36 +/*
    5.37 + * Initializes the Haptic devices.
    5.38 + */
    5.39 +int
    5.40 +SDL_HapticInit(void)
    5.41 +{  
    5.42 +   int arraylen;
    5.43 +   int status;
    5.44 +
    5.45 +   SDL_numhaptics = 0;
    5.46 +   status = SDL_SYS_HapticInit();
    5.47 +   if (status >= 0) {
    5.48 +      arraylen = (status + 1) * sizeof(*SDL_haptics);
    5.49 +      SDL_haptics = (SDL_Haptic **) SDL_malloc(arraylen);
    5.50 +      if (SDL_haptics == NULL) {
    5.51 +         SDL_numhaptics = 0;
    5.52 +      } else {
    5.53 +         SDL_memset(SDL_haptics, 0, arraylen);
    5.54 +         SDL_numhaptics = status;
    5.55 +      }
    5.56 +      status = 0;
    5.57 +   }
    5.58 +   default_haptic = NULL;
    5.59 +
    5.60 +   return status;
    5.61 +}
    5.62 +
    5.63 +
    5.64 +/*
    5.65 + * Returns the number of available devices.
    5.66 + */
    5.67 +int
    5.68 +SDL_NumHaptics(void)
    5.69 +{
    5.70 +   return SDL_numhaptics;
    5.71 +}
    5.72 +
    5.73 +
    5.74 +/*
    5.75 + * Gets the name of a Haptic device by index.
    5.76 + */
    5.77 +const char *
    5.78 +SDL_HapticName(int device_index)
    5.79 +{
    5.80 +   if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
    5.81 +      SDL_SetError("There are %d haptic devices available", SDL_numhaptics);
    5.82 +      return NULL;
    5.83 +   }
    5.84 +   return SDL_SYS_HapticName(device_index);
    5.85 +}
    5.86 +
    5.87 +
    5.88 +/*
    5.89 + * Opens a Haptic device
    5.90 + */
    5.91 +SDL_Haptic *
    5.92 +SDL_HapticOpen(int device_index)
    5.93 +{
    5.94 +   int i;
    5.95 +   SDL_Haptic *haptic;
    5.96 +
    5.97 +   if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
    5.98 +      SDL_SetError("There are %d haptic devices available", SDL_numhaptics);
    5.99 +      return NULL;
   5.100 +   }
   5.101 +
   5.102 +   /* If the haptic is already open, return it */
   5.103 +   for (i = 0; SDL_haptics[i]; ++i) {             
   5.104 +      if (device_index == SDL_haptics[i]->index) {
   5.105 +         haptic = SDL_haptics[i];
   5.106 +         ++haptic->ref_count;
   5.107 +         return haptic;
   5.108 +      }
   5.109 +   }
   5.110 +
   5.111 +   /* Create and initialize the haptic */
   5.112 +   haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
   5.113 +   if (haptic != NULL) {
   5.114 +      SDL_memset(haptic, 0, (sizeof *haptic));
   5.115 +      haptic->index = device_index;
   5.116 +      if (SDL_SYS_HapticOpen(haptic) < 0) {
   5.117 +         SDL_free(haptic);
   5.118 +         haptic = NULL;
   5.119 +      } else {
   5.120 +      }
   5.121 +   }
   5.122 +   if (haptic) {
   5.123 +      /* Add haptic to list */
   5.124 +      ++haptic->ref_count;
   5.125 +      for (i = 0; SDL_haptics[i]; ++i)
   5.126 +         /* Skip to next haptic */ ;
   5.127 +      SDL_haptics[i] = haptic;
   5.128 +   }
   5.129 +   return haptic;
   5.130 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/haptic/SDL_haptic_c.h	Sun Jun 01 11:44:25 2008 +0000
     6.3 @@ -0,0 +1,33 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 2008 Edgar Simo
     6.7 +
     6.8 +    This library is free software; you can redistribute it and/or
     6.9 +    modify it under the terms of the GNU Lesser General Public
    6.10 +    License as published by the Free Software Foundation; either
    6.11 +    version 2.1 of the License, or (at your option) any later version.
    6.12 +
    6.13 +    This library is distributed in the hope that it will be useful,
    6.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 +    Lesser General Public License for more details.
    6.17 +
    6.18 +    You should have received a copy of the GNU Lesser General Public
    6.19 +    License along with this library; if not, write to the Free Software
    6.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 +
    6.22 +    Sam Lantinga
    6.23 +    slouken@libsdl.org
    6.24 +*/
    6.25 +
    6.26 +#include "SDL_haptic.h"
    6.27 +
    6.28 +struct _SDL_Haptic;
    6.29 +
    6.30 +extern int SDL_HapticInit(void);
    6.31 +extern int SDL_NumHaptics(void);
    6.32 +extern const char * SDL_HapticName(int device_index);
    6.33 +extern struct _SDL_Haptic * SDL_HapticOpen(int device_index);
    6.34 +extern int SDL_HapticOpened(int device_index);
    6.35 +extern int SDL_HapticIndex(struct _SDL_Haptic *haptic);
    6.36 +extern void SDL_HapticClose(struct _SDL_Haptic *haptic);
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/haptic/SDL_syshaptic.h	Sun Jun 01 11:44:25 2008 +0000
     7.3 @@ -0,0 +1,44 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 2008 Edgar Simo
     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 +#include "SDL_config.h"
    7.27 +
    7.28 +#include "SDL_haptic.h"
    7.29 +
    7.30 +
    7.31 +struct _SDL_Haptic
    7.32 +{  
    7.33 +   Uint8 index;
    7.34 +   const char* name;
    7.35 +
    7.36 +   int neffects; /* maximum amount of effects */
    7.37 +   unsigned int supported; /* supported effects */
    7.38 +
    7.39 +   struct haptic_hwdata *hwdata; /* driver dependent */
    7.40 +   int ref_count; /* count for multiple opens */
    7.41 +};
    7.42 +
    7.43 +
    7.44 +extern int SDL_SYS_HapticInit(void);
    7.45 +
    7.46 +extern const char * SDL_SYS_HapticName(int index);
    7.47 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Sun Jun 01 11:44:25 2008 +0000
     8.3 @@ -0,0 +1,185 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 2008 Edgar Simo
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +*/
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#ifdef SDL_JOYSTICK_LINUX
    8.28 +
    8.29 +#include "SDL_haptic.h"
    8.30 +#include "../SDL_haptic_c.h"
    8.31 +#include "../SDL_syshaptic.h"
    8.32 +
    8.33 +#include <unistd.h> /* close */
    8.34 +#include <linux/input.h>
    8.35 +#include <sys/ioctl.h>
    8.36 +#include <sys/types.h>
    8.37 +#include <sys/stat.h>
    8.38 +#include <fcntl.h>
    8.39 +#include <linux/limits.h>
    8.40 +#include <string.h>
    8.41 +
    8.42 +
    8.43 +#include <stdio.h>
    8.44 +
    8.45 +
    8.46 +#define MAX_HAPTICS  32
    8.47 +
    8.48 +
    8.49 +static struct
    8.50 +{
    8.51 +   char *fname;
    8.52 +   SDL_Haptic *haptic;
    8.53 +} SDL_hapticlist[MAX_HAPTICS];
    8.54 +
    8.55 +struct haptic_hwdata
    8.56 +{
    8.57 +   int fd;
    8.58 +};
    8.59 +
    8.60 +
    8.61 +#define test_bit(nr, addr) \
    8.62 +   (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0)
    8.63 +#define EV_TEST(ev,f) \
    8.64 +   if (test_bit((ev), features)) ret |= (f);
    8.65 +static int
    8.66 +EV_IsHaptic(int fd)
    8.67 +{
    8.68 +   unsigned int ret;
    8.69 +   unsigned long features[1 + FF_MAX/sizeof(unsigned long)];
    8.70 +
    8.71 +   ret = 0;
    8.72 +
    8.73 +   ioctl(fd, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features);
    8.74 +
    8.75 +   EV_TEST(FF_CONSTANT,   SDL_HAPTIC_CONSTANT);
    8.76 +   EV_TEST(FF_PERIODIC,   SDL_HAPTIC_PERIODIC);
    8.77 +   EV_TEST(FF_RAMP,       SDL_HAPTIC_RAMP);
    8.78 +   EV_TEST(FF_SPRING,     SDL_HAPTIC_SPRING);
    8.79 +   EV_TEST(FF_FRICTION,   SDL_HAPTIC_FRICTION);
    8.80 +   EV_TEST(FF_DAMPER,     SDL_HAPTIC_DAMPER);
    8.81 +   EV_TEST(FF_RUMBLE,     SDL_HAPTIC_RUMBLE);
    8.82 +   EV_TEST(FF_INERTIA,    SDL_HAPTIC_INERTIA);
    8.83 +   EV_TEST(FF_GAIN,       SDL_HAPTIC_GAIN);
    8.84 +   EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER);
    8.85 +
    8.86 +   return ret;
    8.87 +}
    8.88 +
    8.89 +int
    8.90 +SDL_SYS_HapticInit(void)
    8.91 +{
    8.92 +   const char joydev_pattern[] = "/dev/input/event%d";
    8.93 +   dev_t dev_nums[MAX_HAPTICS];
    8.94 +   char path[PATH_MAX];
    8.95 +   struct stat sb;
    8.96 +   int fd;
    8.97 +   int i, j, k;
    8.98 +   int duplicate;
    8.99 +   int numhaptics;
   8.100 +
   8.101 +   numhaptics = 0;
   8.102 +
   8.103 +   i = 0;
   8.104 +   for (j = 0; j < MAX_HAPTICS; ++j) {
   8.105 +
   8.106 +      snprintf(path, PATH_MAX, joydev_pattern, i++);
   8.107 +
   8.108 +      /* check to see if file exists */
   8.109 +      if (stat(path,&sb) != 0)
   8.110 +         break;
   8.111 +
   8.112 +      /* check for duplicates */
   8.113 +      duplicate = 0;
   8.114 +      for (k = 0; (k < numhaptics) && !duplicate; ++k) {
   8.115 +         if (sb.st_rdev == dev_nums[k]) {
   8.116 +            duplicate = 1;
   8.117 +         }                                                     
   8.118 +      }                                                         
   8.119 +      if (duplicate) {
   8.120 +         continue;
   8.121 +      }
   8.122 +
   8.123 +      /* try to open */
   8.124 +      fd = open(path, O_RDWR, 0);
   8.125 +      if (fd < 0) continue;
   8.126 +
   8.127 +#ifdef DEBUG_INPUT_EVENTS
   8.128 +      printf("Checking %s\n", path);
   8.129 +#endif          
   8.130 +
   8.131 +      /* see if it works */
   8.132 +      if (EV_IsHaptic(fd)!=0) {
   8.133 +         SDL_hapticlist[numhaptics].fname = SDL_strdup(path);
   8.134 +         SDL_hapticlist[numhaptics].haptic = NULL;
   8.135 +         dev_nums[numhaptics] = sb.st_rdev;
   8.136 +         ++numhaptics;
   8.137 +      }
   8.138 +      close(fd);
   8.139 +   }
   8.140 +
   8.141 +   return numhaptics;
   8.142 +}
   8.143 +
   8.144 +
   8.145 +const char *
   8.146 +SDL_SYS_HapticName(int index)
   8.147 +{
   8.148 +   int fd;
   8.149 +   static char namebuf[128];
   8.150 +   char *name;
   8.151 +
   8.152 +   name = NULL;
   8.153 +   fd = open(SDL_hapticlist[index].fname, O_RDONLY, 0);
   8.154 +   if (fd >= 0) {
   8.155 +      if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) {
   8.156 +         name = SDL_hapticlist[index].fname;
   8.157 +      }
   8.158 +      else {
   8.159 +         name = namebuf;
   8.160 +      }
   8.161 +   }
   8.162 +   close(fd);
   8.163 +
   8.164 +   return name;
   8.165 +}
   8.166 +
   8.167 +
   8.168 +int
   8.169 +SDL_SYS_HapticOpen(SDL_Haptic * haptic)
   8.170 +{
   8.171 +   /* TODO finish
   8.172 +   int fd;
   8.173 +
   8.174 +   fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
   8.175 +   
   8.176 +   if (fd < 0) {
   8.177 +      SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]);
   8.178 +      return (-1);
   8.179 +   }
   8.180 +
   8.181 +   
   8.182 +
   8.183 +   return 0;
   8.184 +   */
   8.185 +}
   8.186 +
   8.187 +
   8.188 +#endif /* SDL_HAPTIC_LINUX */