[SVN] r3662 - in branches/gsoc2008_force_feedback: include src/haptic src/haptic/linux src/joystick src/joystick/linux
svn-owner at libsdl.org
svn-owner at libsdl.org
Wed Jul 2 01:24:37 PDT 2008
Author: bobbens
Date: 2008-07-02 01:24:35 -0700 (Wed, 02 Jul 2008)
New Revision: 3662
Added:
branches/gsoc2008_force_feedback/src/joystick/linux/SDL_sysjoystick_c.h
Modified:
branches/gsoc2008_force_feedback/include/SDL_haptic.h
branches/gsoc2008_force_feedback/src/haptic/SDL_haptic.c
branches/gsoc2008_force_feedback/src/haptic/linux/SDL_syshaptic.c
branches/gsoc2008_force_feedback/src/joystick/SDL_joystick.c
branches/gsoc2008_force_feedback/src/joystick/SDL_joystick_c.h
branches/gsoc2008_force_feedback/src/joystick/linux/SDL_sysjoystick.c
Log:
Exposed some of the joystick stuff to the haptic subsystem.
Added SDL_JoystickIsHaptic().
Modified: branches/gsoc2008_force_feedback/include/SDL_haptic.h
===================================================================
--- branches/gsoc2008_force_feedback/include/SDL_haptic.h 2008-07-02 08:04:50 UTC (rev 3661)
+++ branches/gsoc2008_force_feedback/include/SDL_haptic.h 2008-07-02 08:24:35 UTC (rev 3662)
@@ -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.
*/
Modified: branches/gsoc2008_force_feedback/src/haptic/SDL_haptic.c
===================================================================
--- branches/gsoc2008_force_feedback/src/haptic/SDL_haptic.c 2008-07-02 08:04:50 UTC (rev 3661)
+++ branches/gsoc2008_force_feedback/src/haptic/SDL_haptic.c 2008-07-02 08:24:35 UTC (rev 3662)
@@ -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
Modified: branches/gsoc2008_force_feedback/src/haptic/linux/SDL_syshaptic.c
===================================================================
--- branches/gsoc2008_force_feedback/src/haptic/linux/SDL_syshaptic.c 2008-07-02 08:04:50 UTC (rev 3661)
+++ branches/gsoc2008_force_feedback/src/haptic/linux/SDL_syshaptic.c 2008-07-02 08:24:35 UTC (rev 3662)
@@ -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 */
Modified: branches/gsoc2008_force_feedback/src/joystick/SDL_joystick.c
===================================================================
--- branches/gsoc2008_force_feedback/src/joystick/SDL_joystick.c 2008-07-02 08:04:50 UTC (rev 3661)
+++ branches/gsoc2008_force_feedback/src/joystick/SDL_joystick.c 2008-07-02 08:24:35 UTC (rev 3662)
@@ -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;
}
Modified: branches/gsoc2008_force_feedback/src/joystick/SDL_joystick_c.h
===================================================================
--- branches/gsoc2008_force_feedback/src/joystick/SDL_joystick_c.h 2008-07-02 08:04:50 UTC (rev 3661)
+++ branches/gsoc2008_force_feedback/src/joystick/SDL_joystick_c.h 2008-07-02 08:24:35 UTC (rev 3662)
@@ -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: */
Modified: branches/gsoc2008_force_feedback/src/joystick/linux/SDL_sysjoystick.c
===================================================================
--- branches/gsoc2008_force_feedback/src/joystick/linux/SDL_sysjoystick.c 2008-07-02 08:04:50 UTC (rev 3661)
+++ branches/gsoc2008_force_feedback/src/joystick/linux/SDL_sysjoystick.c 2008-07-02 08:24:35 UTC (rev 3662)
@@ -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
Added: branches/gsoc2008_force_feedback/src/joystick/linux/SDL_sysjoystick_c.h
===================================================================
--- branches/gsoc2008_force_feedback/src/joystick/linux/SDL_sysjoystick_c.h (rev 0)
+++ branches/gsoc2008_force_feedback/src/joystick/linux/SDL_sysjoystick_c.h 2008-07-02 08:24:35 UTC (rev 3662)
@@ -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 at 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
+};
More information about the commits
mailing list