Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

First commit of the SDL_haptic subsystem.

Code compiles and works, very limited functionality (linux only).
  • Loading branch information
bobbens committed Jun 1, 2008
1 parent 7aa1355 commit dc7047bb5d3d6cf34aab206d57f6bfa77e8e2025
Showing with 521 additions and 0 deletions.
  1. +18 −0 configure.in
  2. +1 −0 include/SDL.h
  3. +87 −0 include/SDL_haptic.h
  4. +26 −0 src/SDL.c
  5. +127 −0 src/haptic/SDL_haptic.c
  6. +33 −0 src/haptic/SDL_haptic_c.h
  7. +44 −0 src/haptic/SDL_syshaptic.h
  8. +185 −0 src/haptic/linux/SDL_syshaptic.c
@@ -235,6 +235,14 @@ if test x$enable_joystick != xyes; then
else
SOURCES="$SOURCES $srcdir/src/joystick/*.c"
fi
AC_ARG_ENABLE(haptic,
AC_HELP_STRING([--enable-haptic], [Enable the haptic (force feedback) subsystem [[default=yes]]]),
, enable_haptic=yes)
if test x$enable_haptic != xyes; then
AC_DEFINE(SDL_HAPTIC_DISABLE)
else
SOURCES="$SOURCES $srcdir/src/haptic/*.c"
fi
AC_ARG_ENABLE(cdrom,
AC_HELP_STRING([--enable-cdrom], [Enable the cdrom subsystem [[default=yes]]]),
, enable_cdrom=yes)
@@ -2176,6 +2184,16 @@ case "$host" in
;;
esac
fi
# Set up files for the haptic library
if test x$enable_haptic = xyes; then
case $ARCH in
linux)
AC_DEFINE(SDL_HAPTIC_LINUX)
SOURCES="$SOURCES $srcdir/src/haptic/linux/*.c"
have_haptic=yes
;;
esac
fi
# Set up files for the cdrom library
if test x$enable_cdrom = xyes; then
case $ARCH in
@@ -109,6 +109,7 @@ extern "C" {
#define SDL_INIT_VIDEO 0x00000020
#define SDL_INIT_CDROM 0x00000100
#define SDL_INIT_JOYSTICK 0x00000200
#define SDL_INIT_HAPTIC 0x00001000
#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */
#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */
#define SDL_INIT_EVERYTHING 0x0000FFFF
@@ -0,0 +1,87 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 2008 Edgar Simo
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/

/**
* \file SDL_haptic.h
*
* Include file for SDL haptic subsystem
*/

#ifndef _SDL_haptic_h
#define _SDL_haptic_h

#include "SDL_stdinc.h"
#include "SDL_error.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

/* The haptic structure used to identify an SDL haptic */
struct _SDL_Haptic;
typedef struct _SDL_Haptic SDL_Haptic;


/* Different effects that can be generated */
#define SDL_HAPTIC_CONSTANT (1<<0)
#define SDL_HAPTIC_PERIODIC (1<<1)
#define SDL_HAPTIC_RAMP (1<<2)
#define SDL_HAPTIC_SPRING (1<<3)
#define SDL_HAPTIC_FRICTION (1<<4)
#define SDL_HAPTIC_DAMPER (1<<5)
#define SDL_HAPTIC_RUMBLE (1<<6)
#define SDL_HAPTIC_INERTIA (1<<7)
#define SDL_HAPTIC_GAIN (1<<8)
#define SDL_HAPTIC_AUTOCENTER (1<<9)


/* Function prototypes */
/*
* Count the number of joysticks attached to the system
*/
extern DECLSPEC int SDLCALL SDL_NumHaptics(void);

/*
* Get the implementation dependent name of a joystick.
* This can be called before any joysticks are opened.
* If no name can be found, this function returns NULL.
*/
extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"

#endif /* _SDL_haptic_h */

/* vi: set ts=4 sw=4 expandtab: */


@@ -38,6 +38,10 @@
extern int SDL_JoystickInit(void);
extern void SDL_JoystickQuit(void);
#endif
#if !SDL_HAPTIC_DISABLED
extern int SDL_HapticInit(void);
extern int SDL_HapticQuit(void);
#endif
#if !SDL_CDROM_DISABLED
extern int SDL_CDROMInit(void);
extern void SDL_CDROMQuit(void);
@@ -123,6 +127,22 @@ SDL_InitSubSystem(Uint32 flags)
}
#endif

#if !SDL_HAPTIC_DISABLED
/* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) {
return (-1);
}
SDL_initialized |= SDL_INIT_HAPTIC;
}
#else
if (flags & SDL_INIT_HAPTIC) {
SDL_SetError("SDL not built with haptic (force feedback) support");
return (-1);
}
#endif


#if !SDL_CDROM_DISABLED
/* Initialize the CD-ROM subsystem */
if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
@@ -180,6 +200,12 @@ SDL_QuitSubSystem(Uint32 flags)
SDL_initialized &= ~SDL_INIT_JOYSTICK;
}
#endif
#if !SDL_HAPTIC_DISABLED
if ((flags & SDL_initialized & SDL_INIT_HAPTIC)) {
SDL_HapticQuit();
SDL_initialized &= ~SDL_INIT_HAPTIC;
}
#endif
#if !SDL_TIMERS_DISABLED
if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
SDL_TimerQuit();
@@ -0,0 +1,127 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 2008 Edgar Simo
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"

#include "SDL_haptic_c.h"
#include "SDL_syshaptic.h"


static Uint8 SDL_numhaptics = 0;
SDL_Haptic **SDL_haptics = NULL;
static SDL_Haptic *default_haptic = NULL;


/*
* Initializes the Haptic devices.
*/
int
SDL_HapticInit(void)
{
int arraylen;
int status;

SDL_numhaptics = 0;
status = SDL_SYS_HapticInit();
if (status >= 0) {
arraylen = (status + 1) * sizeof(*SDL_haptics);
SDL_haptics = (SDL_Haptic **) SDL_malloc(arraylen);
if (SDL_haptics == NULL) {
SDL_numhaptics = 0;
} else {
SDL_memset(SDL_haptics, 0, arraylen);
SDL_numhaptics = status;
}
status = 0;
}
default_haptic = NULL;

return status;
}


/*
* Returns the number of available devices.
*/
int
SDL_NumHaptics(void)
{
return SDL_numhaptics;
}


/*
* Gets the name of a Haptic device by index.
*/
const char *
SDL_HapticName(int device_index)
{
if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
SDL_SetError("There are %d haptic devices available", SDL_numhaptics);
return NULL;
}
return SDL_SYS_HapticName(device_index);
}


/*
* Opens a Haptic device
*/
SDL_Haptic *
SDL_HapticOpen(int device_index)
{
int i;
SDL_Haptic *haptic;

if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
SDL_SetError("There are %d haptic devices available", SDL_numhaptics);
return NULL;
}

/* If the haptic is already open, return it */
for (i = 0; SDL_haptics[i]; ++i) {
if (device_index == SDL_haptics[i]->index) {
haptic = SDL_haptics[i];
++haptic->ref_count;
return haptic;
}
}

/* Create and initialize the haptic */
haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
if (haptic != NULL) {
SDL_memset(haptic, 0, (sizeof *haptic));
haptic->index = device_index;
if (SDL_SYS_HapticOpen(haptic) < 0) {
SDL_free(haptic);
haptic = NULL;
} else {
}
}
if (haptic) {
/* Add haptic to list */
++haptic->ref_count;
for (i = 0; SDL_haptics[i]; ++i)
/* Skip to next haptic */ ;
SDL_haptics[i] = haptic;
}
return haptic;
}
@@ -0,0 +1,33 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 2008 Edgar Simo
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/

#include "SDL_haptic.h"

struct _SDL_Haptic;

extern int SDL_HapticInit(void);
extern int SDL_NumHaptics(void);
extern const char * SDL_HapticName(int device_index);
extern struct _SDL_Haptic * SDL_HapticOpen(int device_index);
extern int SDL_HapticOpened(int device_index);
extern int SDL_HapticIndex(struct _SDL_Haptic *haptic);
extern void SDL_HapticClose(struct _SDL_Haptic *haptic);
@@ -0,0 +1,44 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 2008 Edgar Simo
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/

#include "SDL_config.h"

#include "SDL_haptic.h"


struct _SDL_Haptic
{
Uint8 index;
const char* name;

int neffects; /* maximum amount of effects */
unsigned int supported; /* supported effects */

struct haptic_hwdata *hwdata; /* driver dependent */
int ref_count; /* count for multiple opens */
};


extern int SDL_SYS_HapticInit(void);

extern const char * SDL_SYS_HapticName(int index);

0 comments on commit dc7047b

Please sign in to comment.