Mercurial > sdl-ios-xcode
changeset 2489:96adc8025331 gsoc2008_force_feedback
Exposed some of the joystick stuff to the haptic subsystem.
Added SDL_JoystickIsHaptic().
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Wed, 02 Jul 2008 08:24:35 +0000 |
parents | 8e2bdbccf7ff |
children | be9b206d44af |
files | 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 |
diffstat | 7 files changed, 149 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/include/SDL_haptic.h Tue Jul 01 18:35:05 2008 +0000 +++ b/include/SDL_haptic.h Wed Jul 02 08:24:35 2008 +0000 @@ -31,6 +31,7 @@ #include "SDL_stdinc.h" #include "SDL_error.h" +#include "SDL_joystick.h" #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ @@ -207,6 +208,22 @@ */ extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index); +/* + * Checks to see if a joystick has haptic features. + * + * Returns SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't + * and -1 on error. + */ +extern DECLSPEC int SDL_JoystickIsHaptic(SDL_Joystick * joystick); + +/* + * Opens a Haptic device for usage from a Joystick device. + * + * Returns a valid pointer to a haptic device on success or NULL + * if an error occurred. + */ +extern DECLSPEC SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick * joystick); + /* * Closes a Haptic device previously opened with SDL_HapticOpen. */
--- a/src/haptic/SDL_haptic.c Tue Jul 01 18:35:05 2008 +0000 +++ b/src/haptic/SDL_haptic.c Wed Jul 02 08:24:35 2008 +0000 @@ -23,6 +23,7 @@ #include "SDL_haptic_c.h" #include "SDL_syshaptic.h" +#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */ static Uint8 SDL_numhaptics = 0; @@ -131,6 +132,39 @@ /* + * Returns SDL_TRUE if joystick has haptic features. + */ +int +SDL_JoystickIsHaptic(SDL_Joystick * joystick) +{ + int ret; + + if (!SDL_PrivateJoystickValid(&joystick)) { + return -1; + } + + ret = SDL_SYS_JoystickIsHaptic(joystick); + + if (ret > 0) return SDL_TRUE; + else if (ret == 0) return SDL_FALSE; + else return -1; +} + + +/* + * Opens a haptic device from a joystick. + */ +SDL_Haptic * +SDL_HapticOpenFromJoystick(SDL_Joystick * joystick) +{ + if (!SDL_PrivateJoystickValid(&joystick)) { + return -1; + } + return -1; +} + + +/* * Checks to see if the haptic device is valid */ static int
--- a/src/haptic/linux/SDL_syshaptic.c Tue Jul 01 18:35:05 2008 +0000 +++ b/src/haptic/linux/SDL_syshaptic.c Wed Jul 02 08:24:35 2008 +0000 @@ -26,6 +26,9 @@ #include "SDL_haptic.h" #include "../SDL_haptic_c.h" #include "../SDL_syshaptic.h" +#include "SDL_joystick.h" +#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ +#include "../../joystick/linux/SDL_sysjoystick_c.h" /* For joystick hwdata */ #include <unistd.h> /* close */ #include <linux/input.h> @@ -244,6 +247,27 @@ /* + * Checks to see if a joystick has haptic features. + */ +int +SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) +{ + if (EV_IsHaptic(joystick->hwdata->fd) > 0) + return 1; + return 0; +} + + +/* + * Opens a SDL_Haptic from a SDL_Joystick. + */ +int +SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) +{ +} + + +/* * Closes the haptic device. */ void @@ -604,5 +628,4 @@ } - #endif /* SDL_HAPTIC_LINUX */
--- a/src/joystick/SDL_joystick.c Tue Jul 01 18:35:05 2008 +0000 +++ b/src/joystick/SDL_joystick.c Wed Jul 02 08:24:35 2008 +0000 @@ -193,8 +193,12 @@ return (opened); } -static int -ValidJoystick(SDL_Joystick ** joystick) + +/* + * Checks to make sure the joystick is valid. + */ +int +SDL_PrivateJoystickValid(SDL_Joystick ** joystick) { int valid; @@ -216,7 +220,7 @@ int SDL_JoystickIndex(SDL_Joystick * joystick) { - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (-1); } return (joystick->index); @@ -228,7 +232,7 @@ int SDL_JoystickNumAxes(SDL_Joystick * joystick) { - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (-1); } return (joystick->naxes); @@ -240,7 +244,7 @@ int SDL_JoystickNumHats(SDL_Joystick * joystick) { - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (-1); } return (joystick->nhats); @@ -252,7 +256,7 @@ int SDL_JoystickNumBalls(SDL_Joystick * joystick) { - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (-1); } return (joystick->nballs); @@ -264,7 +268,7 @@ int SDL_JoystickNumButtons(SDL_Joystick * joystick) { - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (-1); } return (joystick->nbuttons); @@ -278,7 +282,7 @@ { Sint16 state; - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (0); } if (axis < joystick->naxes) { @@ -298,7 +302,7 @@ { Uint8 state; - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (0); } if (hat < joystick->nhats) { @@ -318,7 +322,7 @@ { int retval; - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (-1); } @@ -347,7 +351,7 @@ { Uint8 state; - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return (0); } if (button < joystick->nbuttons) { @@ -367,7 +371,7 @@ { int i; - if (!ValidJoystick(&joystick)) { + if (!SDL_PrivateJoystickValid(&joystick)) { return; }
--- a/src/joystick/SDL_joystick_c.h Tue Jul 01 18:35:05 2008 +0000 +++ b/src/joystick/SDL_joystick_c.h Wed Jul 02 08:24:35 2008 +0000 @@ -36,4 +36,8 @@ Uint8 hat, Uint8 value); extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state); + +/* Internal sanity checking functions */ +extern int SDL_PrivateJoystickValid(SDL_Joystick ** joystick); + /* vi: set ts=4 sw=4 expandtab: */
--- a/src/joystick/linux/SDL_sysjoystick.c Tue Jul 01 18:35:05 2008 +0000 +++ b/src/joystick/linux/SDL_sysjoystick.c Wed Jul 02 08:24:35 2008 +0000 @@ -31,13 +31,11 @@ #include <sys/ioctl.h> #include <limits.h> /* For the definition of PATH_MAX */ #include <linux/joystick.h> -#if SDL_INPUT_LINUXEV -#include <linux/input.h> -#endif #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" #include "../SDL_joystick_c.h" +#include "SDL_sysjoystick_c.h" /* Special joystick configurations */ static struct @@ -278,35 +276,6 @@ } SDL_joylist[MAX_JOYSTICKS]; -/* The private structure used to keep track of a joystick */ -struct joystick_hwdata -{ - int fd; - /* The current linux joystick driver maps hats to two axes */ - struct hwdata_hat - { - int axis[2]; - } *hats; - /* The current linux joystick driver maps balls to two axes */ - struct hwdata_ball - { - int axis[2]; - } *balls; - - /* Support for the Linux 2.4 unified input interface */ -#if SDL_INPUT_LINUXEV - SDL_bool is_hid; - Uint8 key_map[KEY_MAX - BTN_MISC]; - Uint8 abs_map[ABS_MAX]; - struct axis_correct - { - int used; - int coef[3]; - } abs_correct[ABS_MAX]; -#endif -}; - - #ifndef NO_LOGICAL_JOYSTICKS static int
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/joystick/linux/SDL_sysjoystick_c.h Wed Jul 02 08:24:35 2008 +0000 @@ -0,0 +1,53 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + 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 +*/ + +#if SDL_INPUT_LINUXEV +#include <linux/input.h> +#endif + +/* The private structure used to keep track of a joystick */ +struct joystick_hwdata +{ + int fd; + /* The current linux joystick driver maps hats to two axes */ + struct hwdata_hat + { + int axis[2]; + } *hats; + /* The current linux joystick driver maps balls to two axes */ + struct hwdata_ball + { + int axis[2]; + } *balls; + + /* Support for the Linux 2.4 unified input interface */ +#if SDL_INPUT_LINUXEV + SDL_bool is_hid; + Uint8 key_map[KEY_MAX - BTN_MISC]; + Uint8 abs_map[ABS_MAX]; + struct axis_correct + { + int used; + int coef[3]; + } abs_correct[ABS_MAX]; +#endif +};