This repository has been archived by the owner. It is now read-only.
Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
First commit of the SDL_haptic subsystem.
Code compiles and works, very limited functionality (linux only).
- Loading branch information
Showing
with
521 additions
and 0 deletions.
- +18 −0 configure.in
- +1 −0 include/SDL.h
- +87 −0 include/SDL_haptic.h
- +26 −0 src/SDL.c
- +127 −0 src/haptic/SDL_haptic.c
- +33 −0 src/haptic/SDL_haptic_c.h
- +44 −0 src/haptic/SDL_syshaptic.h
- +185 −0 src/haptic/linux/SDL_syshaptic.c
@@ -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: */ | ||
|
||
|
@@ -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); | ||
|
Oops, something went wrong.