Commit 4fd9c25f authored by Sam Lantinga's avatar Sam Lantinga

Final merge of Google Summer of Code 2008 work...

Force Feedback for SDL
by Edgar Simo, mentored by Ryan C. Gordon

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403159
parent 0aca8112
...@@ -42,7 +42,7 @@ SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@ ...@@ -42,7 +42,7 @@ SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@
DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS docs docs.html include INSTALL Makefile.dc Makefile.minimal Makefile.in README* sdl-config.in sdl.m4 sdl.pc.in SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualC.html VisualC VisualCE Watcom-OS2.zip Watcom-Win32.zip WhatsNew Xcode DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS docs docs.html include INSTALL Makefile.dc Makefile.minimal Makefile.in README* sdl-config.in sdl.m4 sdl.pc.in SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualC.html VisualC VisualCE Watcom-OS2.zip Watcom-Win32.zip WhatsNew Xcode
HDRS = SDL.h SDL_audio.h SDL_cdrom.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_pixels.h SDL_platform.h SDL_quit.h SDL_rect.h SDL_rwops.h SDL_scancode.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h HDRS = SDL.h SDL_audio.h SDL_cdrom.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_haptic.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_pixels.h SDL_platform.h SDL_quit.h SDL_rect.h SDL_rwops.h SDL_scancode.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h
LT_AGE = @LT_AGE@ LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@ LT_CURRENT = @LT_CURRENT@
......
...@@ -15,6 +15,7 @@ SOURCES = \ ...@@ -15,6 +15,7 @@ SOURCES = \
src/events/*.c \ src/events/*.c \
src/file/*.c \ src/file/*.c \
src/joystick/*.c \ src/joystick/*.c \
src/haptic/*.c \
src/stdlib/*.c \ src/stdlib/*.c \
src/thread/*.c \ src/thread/*.c \
src/timer/*.c \ src/timer/*.c \
...@@ -22,6 +23,7 @@ SOURCES = \ ...@@ -22,6 +23,7 @@ SOURCES = \
src/audio/dummy/*.c \ src/audio/dummy/*.c \
src/video/dummy/*.c \ src/video/dummy/*.c \
src/joystick/dummy/*.c \ src/joystick/dummy/*.c \
src/haptic/dummy/*.c \
src/cdrom/dummy/*.c \ src/cdrom/dummy/*.c \
src/thread/generic/*.c \ src/thread/generic/*.c \
src/timer/dummy/*.c \ src/timer/dummy/*.c \
......
...@@ -235,6 +235,14 @@ if test x$enable_joystick != xyes; then ...@@ -235,6 +235,14 @@ if test x$enable_joystick != xyes; then
else else
SOURCES="$SOURCES $srcdir/src/joystick/*.c" SOURCES="$SOURCES $srcdir/src/joystick/*.c"
fi 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_DISABLED)
else
SOURCES="$SOURCES $srcdir/src/haptic/*.c"
fi
AC_ARG_ENABLE(cdrom, AC_ARG_ENABLE(cdrom,
AC_HELP_STRING([--enable-cdrom], [Enable the cdrom subsystem [[default=yes]]]), AC_HELP_STRING([--enable-cdrom], [Enable the cdrom subsystem [[default=yes]]]),
, enable_cdrom=yes) , enable_cdrom=yes)
...@@ -2179,6 +2187,18 @@ case "$host" in ...@@ -2179,6 +2187,18 @@ case "$host" in
;; ;;
esac esac
fi fi
# Set up files for the haptic library
if test x$enable_haptic = xyes; then
if test x$use_input_events = xyes; then
case $ARCH in
linux)
AC_DEFINE(SDL_HAPTIC_LINUX)
SOURCES="$SOURCES $srcdir/src/haptic/linux/*.c"
have_haptic=yes
;;
esac
fi
fi
# Set up files for the cdrom library # Set up files for the cdrom library
if test x$enable_cdrom = xyes; then if test x$enable_cdrom = xyes; then
case $ARCH in case $ARCH in
...@@ -2316,6 +2336,13 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau ...@@ -2316,6 +2336,13 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
fi fi
have_joystick=yes have_joystick=yes
fi fi
if test x$enable_haptic = xyes; then
if test x$have_dinput = xyes; then
AC_DEFINE(SDL_HAPTIC_DINPUT)
SOURCES="$SOURCES $srcdir/src/haptic/win32/SDL_syshaptic.c"
have_haptic=yes
fi
fi
# Set up files for the cdrom library # Set up files for the cdrom library
if test x$enable_cdrom = xyes; then if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_WIN32) AC_DEFINE(SDL_CDROM_WIN32)
...@@ -2457,6 +2484,13 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau ...@@ -2457,6 +2484,13 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/joystick/darwin/*.c" SOURCES="$SOURCES $srcdir/src/joystick/darwin/*.c"
have_joystick=yes have_joystick=yes
fi fi
# Set up files for the haptic library
if test x$enable_haptic = xyes; then
AC_DEFINE(SDL_HAPTIC_IOKIT)
SOURCES="$SOURCES $srcdir/src/haptic/darwin/*.c"
have_haptic=yes
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,ForceFeedback"
fi
# Set up files for the cdrom library # Set up files for the cdrom library
if test x$enable_cdrom = xyes; then if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_MACOSX) AC_DEFINE(SDL_CDROM_MACOSX)
...@@ -2565,6 +2599,12 @@ if test x$enable_joystick = xyes; then ...@@ -2565,6 +2599,12 @@ if test x$enable_joystick = xyes; then
SOURCES="$SOURCES $srcdir/src/joystick/dummy/*.c" SOURCES="$SOURCES $srcdir/src/joystick/dummy/*.c"
fi fi
fi fi
if test x$have_haptic != xyes; then
if test x$enable_haptic = xyes; then
AC_DEFINE(SDL_HAPTIC_DISABLED)
fi
SOURCES="$SOURCES $srcdir/src/haptic/dummy/*.c"
fi
if test x$have_cdrom != xyes; then if test x$have_cdrom != xyes; then
if test x$enable_cdrom = xyes; then if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_DISABLED) AC_DEFINE(SDL_CDROM_DISABLED)
......
...@@ -104,14 +104,15 @@ extern "C" { ...@@ -104,14 +104,15 @@ extern "C" {
/* These are the flags which may be passed to SDL_Init() -- you should /* These are the flags which may be passed to SDL_Init() -- you should
specify the subsystems which you will be using in your application. specify the subsystems which you will be using in your application.
*/ */
#define SDL_INIT_TIMER 0x00000001 #define SDL_INIT_TIMER 0x00000001
#define SDL_INIT_AUDIO 0x00000010 #define SDL_INIT_AUDIO 0x00000010
#define SDL_INIT_VIDEO 0x00000020 #define SDL_INIT_VIDEO 0x00000020
#define SDL_INIT_CDROM 0x00000100 #define SDL_INIT_CDROM 0x00000100
#define SDL_INIT_JOYSTICK 0x00000200 #define SDL_INIT_JOYSTICK 0x00000200
#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */ #define SDL_INIT_HAPTIC 0x00001000
#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */ #define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */
#define SDL_INIT_EVERYTHING 0x0000FFFF #define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */
#define SDL_INIT_EVERYTHING 0x0000FFFF
/* This function loads the SDL dynamically linked library and initializes /* This function loads the SDL dynamically linked library and initializes
* the subsystems specified by 'flags' (and those satisfying dependencies) * the subsystems specified by 'flags' (and those satisfying dependencies)
......
...@@ -149,6 +149,7 @@ ...@@ -149,6 +149,7 @@
#undef SDL_EVENTS_DISABLED #undef SDL_EVENTS_DISABLED
#undef SDL_FILE_DISABLED #undef SDL_FILE_DISABLED
#undef SDL_JOYSTICK_DISABLED #undef SDL_JOYSTICK_DISABLED
#undef SDL_HAPTIC_DISABLED
#undef SDL_LOADSO_DISABLED #undef SDL_LOADSO_DISABLED
#undef SDL_THREADS_DISABLED #undef SDL_THREADS_DISABLED
#undef SDL_TIMERS_DISABLED #undef SDL_TIMERS_DISABLED
...@@ -215,6 +216,10 @@ ...@@ -215,6 +216,10 @@
#undef SDL_JOYSTICK_WINMM #undef SDL_JOYSTICK_WINMM
#undef SDL_JOYSTICK_USBHID #undef SDL_JOYSTICK_USBHID
#undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H #undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
#undef SDL_HAPTIC_DUMMY
#undef SDL_HAPTIC_LINUX
#undef SDL_HAPTIC_IOKIT
#undef SDL_HAPTIC_DINPUT
/* Enable various shared object loading systems */ /* Enable various shared object loading systems */
#undef SDL_LOADSO_BEOS #undef SDL_LOADSO_BEOS
......
...@@ -89,6 +89,7 @@ typedef unsigned long uintptr_t; ...@@ -89,6 +89,7 @@ typedef unsigned long uintptr_t;
/* Enable various input drivers */ /* Enable various input drivers */
#define SDL_JOYSTICK_DC 1 #define SDL_JOYSTICK_DC 1
#define SDL_HAPTIC_DUMMY 1
/* Enable various shared object loading systems */ /* Enable various shared object loading systems */
#define SDL_LOADSO_DUMMY 1 #define SDL_LOADSO_DUMMY 1
......
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
/* Enable various input drivers */ /* Enable various input drivers */
#define SDL_JOYSTICK_IOKIT 1 #define SDL_JOYSTICK_IOKIT 1
#define SDL_HAPTIC_IOKIT 1
/* Enable various shared object loading systems */ /* Enable various shared object loading systems */
#ifdef __ppc__ #ifdef __ppc__
......
...@@ -47,6 +47,9 @@ typedef unsigned long uintptr_t; ...@@ -47,6 +47,9 @@ typedef unsigned long uintptr_t;
/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */ /* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
#define SDL_JOYSTICK_DISABLED 1 #define SDL_JOYSTICK_DISABLED 1
/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
#define SDL_HAPTIC_DUMMY 1
/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */ /* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
#define SDL_LOADSO_DISABLED 1 #define SDL_LOADSO_DISABLED 1
......
...@@ -118,6 +118,7 @@ typedef unsigned long long uint64_t; ...@@ -118,6 +118,7 @@ typedef unsigned long long uint64_t;
/* Enable various input drivers */ /* Enable various input drivers */
#define SDL_JOYSTICK_OS2 1 #define SDL_JOYSTICK_OS2 1
#define SDL_HAPTIC_DUMMY 1
/* Enable various shared object loading systems */ /* Enable various shared object loading systems */
#define SDL_LOADSO_OS2 1 #define SDL_LOADSO_OS2 1
......
...@@ -139,8 +139,10 @@ typedef unsigned int uintptr_t; ...@@ -139,8 +139,10 @@ typedef unsigned int uintptr_t;
/* Enable various input drivers */ /* Enable various input drivers */
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
#define SDL_JOYSTICK_DISABLED 1 #define SDL_JOYSTICK_DISABLED 1
#define SDL_HAPTIC_DUMMY 1
#else #else
#define SDL_JOYSTICK_WINMM 1 #define SDL_JOYSTICK_DINPUT 1
#define SDL_HAPTIC_DINPUT 1
#endif #endif
/* Enable various shared object loading systems */ /* Enable various shared object loading systems */
......
This diff is collapsed.
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
extern int SDL_JoystickInit(void); extern int SDL_JoystickInit(void);
extern void SDL_JoystickQuit(void); extern void SDL_JoystickQuit(void);
#endif #endif
#if !SDL_HAPTIC_DISABLED
extern int SDL_HapticInit(void);
extern int SDL_HapticQuit(void);
#endif
#if !SDL_CDROM_DISABLED #if !SDL_CDROM_DISABLED
extern int SDL_CDROMInit(void); extern int SDL_CDROMInit(void);
extern void SDL_CDROMQuit(void); extern void SDL_CDROMQuit(void);
...@@ -47,6 +51,10 @@ extern void SDL_StartTicks(void); ...@@ -47,6 +51,10 @@ extern void SDL_StartTicks(void);
extern int SDL_TimerInit(void); extern int SDL_TimerInit(void);
extern void SDL_TimerQuit(void); extern void SDL_TimerQuit(void);
#endif #endif
#if defined(__WIN32__)
extern int SDL_HelperWindowCreate(void);
extern int SDL_HelperWindowDestroy(void);
#endif
/* The initialized subsystems */ /* The initialized subsystems */
static Uint32 SDL_initialized = 0; static Uint32 SDL_initialized = 0;
...@@ -123,6 +131,22 @@ SDL_InitSubSystem(Uint32 flags) ...@@ -123,6 +131,22 @@ SDL_InitSubSystem(Uint32 flags)
} }
#endif #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 #if !SDL_CDROM_DISABLED
/* Initialize the CD-ROM subsystem */ /* Initialize the CD-ROM subsystem */
if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) { if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
...@@ -152,6 +176,12 @@ SDL_Init(Uint32 flags) ...@@ -152,6 +176,12 @@ SDL_Init(Uint32 flags)
/* Clear the error message */ /* Clear the error message */
SDL_ClearError(); SDL_ClearError();
#if defined(__WIN32__)
if (SDL_HelperWindowCreate() < 0) {
return -1;
}
#endif
/* Initialize the desired subsystems */ /* Initialize the desired subsystems */
if (SDL_InitSubSystem(flags) < 0) { if (SDL_InitSubSystem(flags) < 0) {
return (-1); return (-1);
...@@ -180,6 +210,12 @@ SDL_QuitSubSystem(Uint32 flags) ...@@ -180,6 +210,12 @@ SDL_QuitSubSystem(Uint32 flags)
SDL_initialized &= ~SDL_INIT_JOYSTICK; SDL_initialized &= ~SDL_INIT_JOYSTICK;
} }
#endif #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 !SDL_TIMERS_DISABLED
if ((flags & SDL_initialized & SDL_INIT_TIMER)) { if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
SDL_TimerQuit(); SDL_TimerQuit();
...@@ -217,6 +253,10 @@ SDL_Quit(void) ...@@ -217,6 +253,10 @@ SDL_Quit(void)
printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n"); printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n");
fflush(stdout); fflush(stdout);
#endif #endif
#if defined(__WIN32__)
SDL_HelperWindowDestroy();
#endif
SDL_QuitSubSystem(SDL_INIT_EVERYTHING); SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
#ifdef CHECK_LEAKS #ifdef CHECK_LEAKS
......
This diff is collapsed.
/*
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"
/*
* Number of haptic devices on the system.
*/
extern Uint8 SDL_numhaptics;
struct haptic_effect
{
SDL_HapticEffect effect; /* The current event */
struct haptic_hweffect *hweffect; /* The hardware behind the event */
};
/*
* The real SDL_Haptic struct.
*/
struct _SDL_Haptic
{
Uint8 index; /* Stores index it is attached to */
struct haptic_effect *effects; /* Allocated effects */
int neffects; /* Maximum amount of effects */
int nplaying; /* Maximum amount of effects to play at the same time */
unsigned int supported; /* Supported effects */
int naxes; /* Number of axes on the device. */
struct haptic_hwdata *hwdata; /* Driver dependent */
int ref_count; /* Count for multiple opens */
};
/*
* Scans the system for haptic devices.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticInit(void);
/*
* Gets the device dependent name of the haptic device
*/
extern const char *SDL_SYS_HapticName(int index);
/*
* Opens the haptic device for usage. The haptic device should have
* the index value set previously.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticOpen(SDL_Haptic * haptic);
/*
* Returns the index of the haptic core pointer or -1 if none is found.
*/
int SDL_SYS_HapticMouse(void);
/*
* Checks to see if the joystick has haptic capabilities.
*
* Returns >0 if haptic capabilities are detected, 0 if haptic
* capabilities aren't detected and -1 on error.
*/
extern int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick);
/*
* Opens the haptic device for usage using the same device as
* the joystick.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic,
SDL_Joystick * joystick);
/*
* Checks to see if haptic device and joystick device are the same.
*
* Returns 1 if they are the same, 0 if they aren't.
*/
extern int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic,
SDL_Joystick * joystick);
/*
* Closes a haptic device after usage.
*/
extern void SDL_SYS_HapticClose(SDL_Haptic * haptic);
/*
* Performs a cleanup on the haptic subsystem.
*/
extern void SDL_SYS_HapticQuit(void);
/*
* Creates a new haptic effect on the haptic device using base
* as a template for the effect.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
struct haptic_effect *effect,
SDL_HapticEffect * base);
/*
* Updates the haptic effect on the haptic device using data
* as a template.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
struct haptic_effect *effect,
SDL_HapticEffect * data);
/*
* Runs the effect on the haptic device.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
struct haptic_effect *effect,
Uint32 iterations);
/*
* Stops the effect on the haptic device.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic,
struct haptic_effect *effect);
/*
* Cleanups up the effect on the haptic device.
*/
extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
struct haptic_effect *effect);
/*
* Queries the device for the status of effect.
*
* Returns 0 if device is stopped, >0 if device is playing and
* -1 on error.
*/
extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
struct haptic_effect *effect);
/*
* Sets the global gain of the haptic device.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain);
/*
* Sets the autocenter feature of the haptic device.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
/*
* Pauses the haptic device.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticPause(SDL_Haptic * haptic);
/*
* Unpauses the haptic device.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
/*
* Stops all the currently playing haptic effects on the device.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic);
This diff is collapsed.
/*
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"
#if defined(SDL_HAPTIC_DUMMY) || defined(SDL_HAPTIC_DISABLED)
#include "SDL_haptic.h"
#include "../SDL_syshaptic.h"
static int
SDL_SYS_LogicError(void)
{
SDL_SetError("Logic error: No haptic devices available.");;
}
int
SDL_SYS_HapticInit(void)
{
return 0;
}
const char *
SDL_SYS_HapticName(int index)
{
SDL_SYS_LogicError();
return NULL;
}
int
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticMouse(void)
{
return -1;
}
int
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
{
return 0;
}
int
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
return 0;
}
void
SDL_SYS_HapticClose(SDL_Haptic * haptic)
{
return;
}
void
SDL_SYS_HapticQuit(void)
{
return;
}
int
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
struct haptic_effect *effect, SDL_HapticEffect * base)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
struct haptic_effect *effect,
SDL_HapticEffect * data)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
Uint32 iterations)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
{
SDL_SYS_LogicError();
return -1;
}
void
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
{
SDL_SYS_LogicError();
return;
}
int
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
struct haptic_effect *effect)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticPause(SDL_Haptic * haptic)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
{
SDL_SYS_LogicError();
return -1;
}
int
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
{
SDL_SYS_LogicError();
return -1;
}
#endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */
This diff is collapsed.
This diff is collapsed.
...@@ -193,8 +193,12 @@ SDL_JoystickOpened(int device_index) ...@@ -193,8 +193,12 @@ SDL_JoystickOpened(int device_index)
return (opened); return (opened);
} }
static int
ValidJoystick(SDL_Joystick ** joystick) /*
* Checks to make sure the joystick is valid.
*/
int
SDL_PrivateJoystickValid(SDL_Joystick ** joystick)
{ {
int valid; int valid;
...@@ -216,7 +220,7 @@ ValidJoystick(SDL_Joystick ** joystick) ...@@ -216,7 +220,7 @@ ValidJoystick(SDL_Joystick ** joystick)
int int
SDL_JoystickIndex(SDL_Joystick * joystick) SDL_JoystickIndex(SDL_Joystick * joystick)
{ {
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (-1); return (-1);
} }
return (joystick->index); return (joystick->index);
...@@ -228,7 +232,7 @@ SDL_JoystickIndex(SDL_Joystick * joystick) ...@@ -228,7 +232,7 @@ SDL_JoystickIndex(SDL_Joystick * joystick)
int int
SDL_JoystickNumAxes(SDL_Joystick * joystick) SDL_JoystickNumAxes(SDL_Joystick * joystick)
{ {
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (-1); return (-1);
} }
return (joystick->naxes); return (joystick->naxes);
...@@ -240,7 +244,7 @@ SDL_JoystickNumAxes(SDL_Joystick * joystick) ...@@ -240,7 +244,7 @@ SDL_JoystickNumAxes(SDL_Joystick * joystick)
int int
SDL_JoystickNumHats(SDL_Joystick * joystick) SDL_JoystickNumHats(SDL_Joystick * joystick)
{ {
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (-1); return (-1);
} }
return (joystick->nhats); return (joystick->nhats);
...@@ -252,7 +256,7 @@ SDL_JoystickNumHats(SDL_Joystick * joystick) ...@@ -252,7 +256,7 @@ SDL_JoystickNumHats(SDL_Joystick * joystick)
int int
SDL_JoystickNumBalls(SDL_Joystick * joystick) SDL_JoystickNumBalls(SDL_Joystick * joystick)
{ {
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (-1); return (-1);
} }
return (joystick->nballs); return (joystick->nballs);
...@@ -264,7 +268,7 @@ SDL_JoystickNumBalls(SDL_Joystick * joystick) ...@@ -264,7 +268,7 @@ SDL_JoystickNumBalls(SDL_Joystick * joystick)
int int
SDL_JoystickNumButtons(SDL_Joystick * joystick) SDL_JoystickNumButtons(SDL_Joystick * joystick)
{ {
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (-1); return (-1);
} }
return (joystick->nbuttons); return (joystick->nbuttons);
...@@ -278,7 +282,7 @@ SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis) ...@@ -278,7 +282,7 @@ SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis)
{ {
Sint16 state; Sint16 state;
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (0); return (0);
} }
if (axis < joystick->naxes) { if (axis < joystick->naxes) {
...@@ -298,7 +302,7 @@ SDL_JoystickGetHat(SDL_Joystick * joystick, int hat) ...@@ -298,7 +302,7 @@ SDL_JoystickGetHat(SDL_Joystick * joystick, int hat)
{ {
Uint8 state; Uint8 state;
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (0); return (0);
} }
if (hat < joystick->nhats) { if (hat < joystick->nhats) {
...@@ -318,7 +322,7 @@ SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy) ...@@ -318,7 +322,7 @@ SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy)
{ {
int retval; int retval;
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (-1); return (-1);
} }
...@@ -347,7 +351,7 @@ SDL_JoystickGetButton(SDL_Joystick * joystick, int button) ...@@ -347,7 +351,7 @@ SDL_JoystickGetButton(SDL_Joystick * joystick, int button)
{ {
Uint8 state; Uint8 state;
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return (0); return (0);
} }
if (button < joystick->nbuttons) { if (button < joystick->nbuttons) {
...@@ -367,7 +371,7 @@ SDL_JoystickClose(SDL_Joystick * joystick) ...@@ -367,7 +371,7 @@ SDL_JoystickClose(SDL_Joystick * joystick)
{ {
int i; int i;
if (!ValidJoystick(&joystick)) { if (!SDL_PrivateJoystickValid(&joystick)) {
return; return;
} }
......
...@@ -36,4 +36,8 @@ extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick, ...@@ -36,4 +36,8 @@ extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick,
Uint8 hat, Uint8 value); Uint8 hat, Uint8 value);
extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick, extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
Uint8 button, Uint8 state); Uint8 button, Uint8 state);
/* Internal sanity checking functions */
extern int SDL_PrivateJoystickValid(SDL_Joystick ** joystick);
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */
...@@ -48,59 +48,14 @@ ...@@ -48,59 +48,14 @@
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <Carbon/Carbon.h> /* for NewPtrClear, DisposePtr */ #include <Carbon/Carbon.h> /* for NewPtrClear, DisposePtr */
/* For force feedback testing. */
#include <ForceFeedback/ForceFeedback.h>
#include <ForceFeedback/ForceFeedbackConstants.h>
#include "SDL_joystick.h" #include "SDL_joystick.h"
#include "../SDL_sysjoystick.h" #include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h" #include "../SDL_joystick_c.h"
#include "SDL_sysjoystick_c.h"
struct recElement
{
IOHIDElementCookie cookie; /* unique value which identifies element, will NOT change */
long min; /* reported min value possible */
long max; /* reported max value possible */
#if 0
/* TODO: maybe should handle the following stuff somehow? */
long scaledMin; /* reported scaled min value possible */
long scaledMax; /* reported scaled max value possible */
long size; /* size in bits of data return from element */
Boolean relative; /* are reports relative to last report (deltas) */
Boolean wrapping; /* does element wrap around (one value higher than max is min) */
Boolean nonLinear; /* are the values reported non-linear relative to element movement */
Boolean preferredState; /* does element have a preferred state (such as a button) */
Boolean nullState; /* does element have null state */
#endif /* 0 */
/* runtime variables used for auto-calibration */
long minReport; /* min returned value */
long maxReport; /* max returned value */
struct recElement *pNext; /* next element in list */
};
typedef struct recElement recElement;
struct joystick_hwdata
{
IOHIDDeviceInterface **interface; /* interface to device, NULL = no interface */
char product[256]; /* name of product */
long usage; /* usage page from IOUSBHID Parser.h which defines general usage */
long usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */
long axes; /* number of axis (calculated, not reported by device) */
long buttons; /* number of buttons (calculated, not reported by device) */
long hats; /* number of hat switches (calculated, not reported by device) */
long elements; /* number of total elements (shouldbe total of above) (calculated, not reported by device) */
recElement *firstAxis;
recElement *firstButton;
recElement *firstHat;
int removed;
int uncentered;
struct joystick_hwdata *pNext; /* next device */
};
typedef struct joystick_hwdata recDevice;
/* Linked list of all available devices */ /* Linked list of all available devices */
...@@ -594,6 +549,12 @@ HIDDisposeDevice(recDevice ** ppDevice) ...@@ -594,6 +549,12 @@ HIDDisposeDevice(recDevice ** ppDevice)
/* save next device prior to disposing of this device */ /* save next device prior to disposing of this device */
pDeviceNext = (*ppDevice)->pNext; pDeviceNext = (*ppDevice)->pNext;
/* free posible io_service_t */
if ((*ppDevice)->ffservice) {
IOObjectRelease((*ppDevice)->ffservice);
(*ppDevice)->ffservice = 0;
}
/* free element lists */ /* free element lists */
HIDDisposeElementList(&(*ppDevice)->firstAxis); HIDDisposeElementList(&(*ppDevice)->firstAxis);
HIDDisposeElementList(&(*ppDevice)->firstButton); HIDDisposeElementList(&(*ppDevice)->firstButton);
...@@ -686,12 +647,6 @@ SDL_SYS_JoystickInit(void) ...@@ -686,12 +647,6 @@ SDL_SYS_JoystickInit(void)
if (!device) if (!device)
continue; continue;
/* dump device object, it is no longer needed */
result = IOObjectRelease(ioHIDDeviceObject);
/* if (KERN_SUCCESS != result)
HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
*/
/* Filter device list to non-keyboard/mouse stuff */ /* Filter device list to non-keyboard/mouse stuff */
if ((device->usagePage != kHIDPage_GenericDesktop) || if ((device->usagePage != kHIDPage_GenericDesktop) ||
((device->usage != kHIDUsage_GD_Joystick && ((device->usage != kHIDUsage_GD_Joystick &&
...@@ -704,6 +659,14 @@ SDL_SYS_JoystickInit(void) ...@@ -704,6 +659,14 @@ SDL_SYS_JoystickInit(void)
continue; continue;
} }
/* We have to do some storage of the io_service_t for
* SDL_HapticOpenFromJoystick */
if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
device->ffservice = ioHIDDeviceObject;
} else {
device->ffservice = 0;
}
/* Add device to the end of the list */ /* Add device to the end of the list */
if (lastDevice) if (lastDevice)
lastDevice->pNext = device; lastDevice->pNext = device;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -7,7 +7,7 @@ EXE = @EXE@ ...@@ -7,7 +7,7 @@ EXE = @EXE@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@
LIBS = @LIBS@ LIBS = @LIBS@
TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testaudioinfo$(EXE) testmultiaudio$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testgl2$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testsprite2$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) testwm2$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE) TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testaudioinfo$(EXE) testmultiaudio$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testgl2$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testsprite2$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) testwm2$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE) testhaptic$(EXE)
all: Makefile $(TARGETS) all: Makefile $(TARGETS)
...@@ -125,6 +125,9 @@ torturethread$(EXE): $(srcdir)/torturethread.c ...@@ -125,6 +125,9 @@ torturethread$(EXE): $(srcdir)/torturethread.c
testloadso$(EXE): $(srcdir)/testloadso.c testloadso$(EXE): $(srcdir)/testloadso.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS) $(CC) -o $@ $? $(CFLAGS) $(LIBS)
testhaptic$(EXE): $(srcdir)/testhaptic.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
clean: clean:
rm -f $(TARGETS) rm -f $(TARGETS)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment