src/haptic/linux/SDL_syshaptic.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 10 Jan 2010 05:06:03 +0000
changeset 3623 9a73fecd9181
parent 3218 81773a1eac83
child 3680 7c18b38f0f9a
permissions -rw-r--r--
Reverted r5460 ... this was merged from 1.2, but was later reverted there.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
    Copyright (C) 2008 Edgar Simo
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
    Lesser General Public License for more details.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    Sam Lantinga
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    slouken@libsdl.org
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
*/
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#include "SDL_config.h"
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
#ifdef SDL_HAPTIC_LINUX
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_haptic.h"
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "../SDL_syshaptic.h"
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_joystick.h"
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "../../joystick/SDL_sysjoystick.h"     /* For the real SDL_Joystick */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#include "../../joystick/linux/SDL_sysjoystick_c.h"     /* For joystick hwdata */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include <unistd.h>             /* close */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include <linux/input.h>        /* Force feedback linux stuff. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include <fcntl.h>              /* O_RDWR */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include <limits.h>             /* INT_MAX */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include <errno.h>              /* errno, strerror */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#include <math.h>               /* atan2 */
3218
81773a1eac83 Patch from David Carre:
Sam Lantinga <slouken@libsdl.org>
parents: 3080
diff changeset
    38
#include <sys/stat.h>           /* stat */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
/* Just in case. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
#ifndef M_PI
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
#  define M_PI     3.14159265358979323846
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
#endif
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
#define MAX_HAPTICS  32         /* It's doubtful someone has more then 32 evdev */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
 * List of available haptic devices.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
static struct
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
    char *fname;                /* Dev path name (like /dev/input/event1) */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
    SDL_Haptic *haptic;         /* Assosciated haptic. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
} SDL_hapticlist[MAX_HAPTICS];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
 * Haptic system hardware data.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
struct haptic_hwdata
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    int fd;                     /* File descriptor of the device. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    char *fname;                /* Points to the name in SDL_hapticlist. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
};
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
 * Haptic system effect data.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
struct haptic_hweffect
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
    struct ff_effect effect;    /* The linux kernel effect structure. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
};
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
#define test_bit(nr, addr) \
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
   (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
#define EV_TEST(ev,f) \
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
   if (test_bit((ev), features)) ret |= (f);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
 * Test whether a device has haptic properties.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
 * Returns available properties or 0 if there are none.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
static int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
EV_IsHaptic(int fd)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    unsigned int ret;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    unsigned long features[1 + FF_MAX / sizeof(unsigned long)];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    /* Ask device for what it has. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
    ret = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
        SDL_SetError("Haptic: Unable to get device's features: %s",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
                     strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
    /* Convert supported features to SDL_HAPTIC platform-neutral features. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
    EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    EV_TEST(FF_SINE, SDL_HAPTIC_SINE);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    EV_TEST(FF_SQUARE, SDL_HAPTIC_SQUARE);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    EV_TEST(FF_TRIANGLE, SDL_HAPTIC_TRIANGLE);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
    EV_TEST(FF_SAW_UP, SDL_HAPTIC_SAWTOOTHUP);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
    EV_TEST(FF_SAW_DOWN, SDL_HAPTIC_SAWTOOTHDOWN);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
    EV_TEST(FF_RAMP, SDL_HAPTIC_RAMP);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
    EV_TEST(FF_SPRING, SDL_HAPTIC_SPRING);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
    EV_TEST(FF_FRICTION, SDL_HAPTIC_FRICTION);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
    EV_TEST(FF_DAMPER, SDL_HAPTIC_DAMPER);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    EV_TEST(FF_INERTIA, SDL_HAPTIC_INERTIA);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
    EV_TEST(FF_CUSTOM, SDL_HAPTIC_CUSTOM);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
    EV_TEST(FF_GAIN, SDL_HAPTIC_GAIN);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
    EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
    /* Return what it supports. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
    return ret;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
 * Tests whether a device is a mouse or not.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
static int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
EV_IsMouse(int fd)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
    unsigned long argp[40];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    /* Ask for supported features. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(argp)), argp) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
    /* Currently we only test for BTN_MOUSE which can give fake positives. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
    if (test_bit(BTN_MOUSE, argp) != 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
        return 1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
 * Initializes the haptic subsystem by finding available devices.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
SDL_SYS_HapticInit(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
    const char joydev_pattern[] = "/dev/input/event%d";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    dev_t dev_nums[MAX_HAPTICS];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
    char path[PATH_MAX];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
    struct stat sb;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
    int fd;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
    int i, j, k;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
    int duplicate;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
    int numhaptics;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
    numhaptics = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    /* 
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
     * Limit amount of checks to MAX_HAPTICS since we may or may not have
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
     * permission to some or all devices.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
     */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    i = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    for (j = 0; j < MAX_HAPTICS; ++j) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
        snprintf(path, PATH_MAX, joydev_pattern, i++);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
        /* check to see if file exists */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
        if (stat(path, &sb) != 0)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
            break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
        /* check for duplicates */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
        duplicate = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
        for (k = 0; (k < numhaptics) && !duplicate; ++k) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
            if (sb.st_rdev == dev_nums[k]) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
                duplicate = 1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
            }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
        if (duplicate) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
            continue;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
        /* try to open */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
        fd = open(path, O_RDWR, 0);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
        if (fd < 0)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
            continue;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
#ifdef DEBUG_INPUT_EVENTS
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
        printf("Checking %s\n", path);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
#endif
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
        /* see if it works */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
        if (EV_IsHaptic(fd) > 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
            SDL_hapticlist[numhaptics].fname = SDL_strdup(path);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
            SDL_hapticlist[numhaptics].haptic = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
            dev_nums[numhaptics] = sb.st_rdev;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
            ++numhaptics;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
        close(fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
    return numhaptics;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
 * Gets the name from a file descriptor.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
static const char *
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
SDL_SYS_HapticNameFromFD(int fd)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
    static char namebuf[128];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
    /* We use the evdev name ioctl. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
    if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
        return NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
    return namebuf;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
 * Return the name of a haptic device, does not need to be opened.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
const char *
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
SDL_SYS_HapticName(int index)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
    int fd;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
    const char *name;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
    /* Open the haptic device. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
    name = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
    fd = open(SDL_hapticlist[index].fname, O_RDONLY, 0);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
    if (fd >= 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
        name = SDL_SYS_HapticNameFromFD(fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
        if (name == NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
            /* No name found, return device character device */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
            name = SDL_hapticlist[index].fname;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
    close(fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
    return name;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
 * Opens the haptic device from the file descriptor.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
static int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
    const char *name;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
    /* Allocate the hwdata */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
    haptic->hwdata = (struct haptic_hwdata *)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
        SDL_malloc(sizeof(*haptic->hwdata));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
    if (haptic->hwdata == NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
        SDL_OutOfMemory();
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
        goto open_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
    SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
    /* Set the data. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
    haptic->hwdata->fd = fd;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    haptic->supported = EV_IsHaptic(fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
    haptic->naxes = 2;          /* Hardcoded for now, not sure if it's possible to find out. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
    /* Set the effects */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
    if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
        SDL_SetError("Haptic: Unable to query device memory: %s",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
                     strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
        goto open_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
    haptic->nplaying = haptic->neffects;        /* Linux makes no distinction. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
    haptic->effects = (struct haptic_effect *)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
        SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
    if (haptic->effects == NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
        SDL_OutOfMemory();
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
        goto open_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
    /* Clear the memory */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
    SDL_memset(haptic->effects, 0,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
               sizeof(struct haptic_effect) * haptic->neffects);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    /* Error handling */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
  open_err:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
    close(fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
    if (haptic->hwdata != NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
        free(haptic->hwdata);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
        haptic->hwdata = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
    return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
 * Opens a haptic device for usage.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
    int fd;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
    int ret;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
    /* Open the character device */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
    if (fd < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
        SDL_SetError("Haptic: Unable to open %s: %s",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
                     SDL_hapticlist[haptic->index], strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
    /* Try to create the haptic. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
    ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
    if (ret < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
    /* Set the fname. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
    haptic->hwdata->fname = SDL_hapticlist[haptic->index].fname;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
 * Opens a haptic device from first mouse it finds for usage.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
SDL_SYS_HapticMouse(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
    int fd;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    int i;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
    for (i = 0; i < SDL_numhaptics; i++) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
        /* Open the device. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
        fd = open(SDL_hapticlist[i].fname, O_RDWR, 0);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
        if (fd < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
            SDL_SetError("Haptic: Unable to open %s: %s",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
                         SDL_hapticlist[i], strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
            return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
        /* Is it a mouse? */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
        if (EV_IsMouse(fd)) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
            close(fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
            return i;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
        close(fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
    return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
 * Checks to see if a joystick has haptic features.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
    return EV_IsHaptic(joystick->hwdata->fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
 * Checks to see if the haptic device and joystick and in reality the same.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   377
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
    /* We are assuming linux is using evdev which should trump the old
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   381
     * joystick methods. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
    if (SDL_strcmp(joystick->hwdata->fname, haptic->hwdata->fname) == 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
        return 1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
 * Opens a SDL_Haptic from a SDL_Joystick.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
    int i;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
    int fd;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
    int ret;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
3080
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   399
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
    /* Find the joystick in the haptic list. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
    for (i = 0; i < MAX_HAPTICS; i++) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
        if (SDL_hapticlist[i].fname != NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
            if (SDL_strcmp(SDL_hapticlist[i].fname, joystick->hwdata->fname)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
                == 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
                haptic->index = i;
3080
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   406
                break;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
            }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
    }
3080
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   410
    if (i >= MAX_HAPTICS) {
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   411
        SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   412
        return -1;
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   413
    }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    fd = open(joystick->hwdata->fname, O_RDWR, 0);
3080
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   416
    if (fd < 0) {
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   417
        SDL_SetError("Haptic: Unable to open %s: %s",
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   418
                     joystick->hwdata->fname, strerror(errno));
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   419
        return -1;
4094b4f1c3a1 More verbosity and error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
   420
    }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
    ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
    if (ret < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
    haptic->hwdata->fname = SDL_hapticlist[haptic->index].fname;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   430
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
 * Closes the haptic device.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
void
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
SDL_SYS_HapticClose(SDL_Haptic * haptic)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
    if (haptic->hwdata) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
        /* Free effects. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
        SDL_free(haptic->effects);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   441
        haptic->effects = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   442
        haptic->neffects = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   443
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
        /* Clean up */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
        close(haptic->hwdata->fd);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
        /* Free */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
        SDL_free(haptic->hwdata);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
        haptic->hwdata = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   452
    /* Clear the rest. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
    SDL_memset(haptic, 0, sizeof(SDL_Haptic));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   455
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
/* 
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
 * Clean up after system specific haptic stuff
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   460
void
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   461
SDL_SYS_HapticQuit(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
    int i;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   465
    for (i = 0; SDL_hapticlist[i].fname != NULL; i++) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   466
        /* Opened and not closed haptics are leaked, this is on purpose.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   467
         * Close your haptic devices after usage. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   468
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   469
        SDL_free(SDL_hapticlist[i].fname);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   470
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
    SDL_hapticlist[0].fname = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
 * Converts an SDL button to a ff_trigger button.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
static Uint16
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
SDL_SYS_ToButton(Uint16 button)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
    Uint16 ff_button;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
    ff_button = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
    /*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
     * Not sure what the proper syntax is because this actually isn't implemented
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
     * in the current kernel from what I've seen (2.6.26).
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
     */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   489
    if (button != 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
        ff_button = BTN_GAMEPAD + button - 1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   492
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
    return ff_button;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   495
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   496
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
 * Returns the ff_effect usable direction from a SDL_HapticDirection.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
static Uint16
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
SDL_SYS_ToDirection(SDL_HapticDirection * dir)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
    Uint32 tmp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
    float f;                    /* Ideally we'd use fixed point math instead of floats... */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
    switch (dir->type) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
    case SDL_HAPTIC_POLAR:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
        /* Linux directions are inverted. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
        tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
        return (Uint16) tmp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
    case SDL_HAPTIC_CARTESIAN:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
        /* We must invert "x" and "y" to go clockwise. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
        f = atan2(dir->dir[0], dir->dir[1]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
        tmp = (int) (f * 18000. / M_PI) % 36000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
        tmp = (tmp * 0xFFFF) / 36000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
        return (Uint16) tmp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
    case SDL_HAPTIC_SPHERICAL:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   520
        tmp = (36000 - dir->dir[0]) + 27000;    /* Convert to polars */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
        tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
        return (Uint16) tmp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
    default:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
        SDL_SetError("Haptic: Unsupported direction type.");
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
        return (Uint16) - 1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   528
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   529
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   530
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   532
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
#define  CLAMP(x)    (((x) > 32767) ? 32767 : x)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
 * Initializes the linux effect struct from a haptic_effect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   536
 * Values above 32767 (for unsigned) are unspecified so we must clamp.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
static int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
    Uint32 tmp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
    SDL_HapticConstant *constant;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
    SDL_HapticPeriodic *periodic;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
    SDL_HapticCondition *condition;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
    SDL_HapticRamp *ramp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
    /* Clear up */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
    SDL_memset(dest, 0, sizeof(struct ff_effect));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   549
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
    switch (src->type) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
    case SDL_HAPTIC_CONSTANT:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
        constant = &src->constant;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   553
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
        /* Header */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
        dest->type = FF_CONSTANT;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
        dest->direction = SDL_SYS_ToDirection(&constant->direction);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   557
        if (dest->direction == (Uint16) - 1)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
            return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
        /* Replay */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
        dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
            0 : CLAMP(constant->length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
        dest->replay.delay = CLAMP(constant->delay);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
        /* Trigger */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
        dest->trigger.button = SDL_SYS_ToButton(constant->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
        dest->trigger.interval = CLAMP(constant->interval);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
        /* Constant */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   570
        dest->u.constant.level = constant->level;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
        /* Envelope */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
        dest->u.constant.envelope.attack_length =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
            CLAMP(constant->attack_length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
        dest->u.constant.envelope.attack_level =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
            CLAMP(constant->attack_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   577
        dest->u.constant.envelope.fade_length = CLAMP(constant->fade_length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
        dest->u.constant.envelope.fade_level = CLAMP(constant->fade_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   579
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
        break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
    case SDL_HAPTIC_SINE:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
    case SDL_HAPTIC_SQUARE:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
    case SDL_HAPTIC_TRIANGLE:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
    case SDL_HAPTIC_SAWTOOTHUP:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
    case SDL_HAPTIC_SAWTOOTHDOWN:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
        periodic = &src->periodic;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
        /* Header */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
        dest->type = FF_PERIODIC;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
        dest->direction = SDL_SYS_ToDirection(&periodic->direction);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
        if (dest->direction == (Uint16) - 1)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
            return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
        /* Replay */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
        dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ?
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
            0 : CLAMP(periodic->length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
        dest->replay.delay = CLAMP(periodic->delay);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
        /* Trigger */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
        dest->trigger.button = SDL_SYS_ToButton(periodic->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   602
        dest->trigger.interval = CLAMP(periodic->interval);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
        /* Periodic */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
        if (periodic->type == SDL_HAPTIC_SINE)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
            dest->u.periodic.waveform = FF_SINE;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
        else if (periodic->type == SDL_HAPTIC_SQUARE)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
            dest->u.periodic.waveform = FF_SQUARE;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
        else if (periodic->type == SDL_HAPTIC_TRIANGLE)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
            dest->u.periodic.waveform = FF_TRIANGLE;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
        else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
            dest->u.periodic.waveform = FF_SAW_UP;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
        else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
            dest->u.periodic.waveform = FF_SAW_DOWN;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
        dest->u.periodic.period = CLAMP(periodic->period);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
        dest->u.periodic.magnitude = periodic->magnitude;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
        dest->u.periodic.offset = periodic->offset;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
        /* Phase is calculated based of offset from period and then clamped. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   619
        tmp = ((periodic->phase % 36000) * dest->u.periodic.period) / 36000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   620
        dest->u.periodic.phase = CLAMP(tmp);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   622
        /* Envelope */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   623
        dest->u.periodic.envelope.attack_length =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   624
            CLAMP(periodic->attack_length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   625
        dest->u.periodic.envelope.attack_level =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   626
            CLAMP(periodic->attack_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   627
        dest->u.periodic.envelope.fade_length = CLAMP(periodic->fade_length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   628
        dest->u.periodic.envelope.fade_level = CLAMP(periodic->fade_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
        break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
    case SDL_HAPTIC_SPRING:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
    case SDL_HAPTIC_DAMPER:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   634
    case SDL_HAPTIC_INERTIA:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
    case SDL_HAPTIC_FRICTION:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
        condition = &src->condition;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   637
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   638
        /* Header */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   639
        if (condition->type == SDL_HAPTIC_SPRING)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   640
            dest->type = FF_SPRING;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   641
        else if (condition->type == SDL_HAPTIC_DAMPER)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
            dest->type = FF_DAMPER;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   643
        else if (condition->type == SDL_HAPTIC_INERTIA)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   644
            dest->type = FF_INERTIA;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   645
        else if (condition->type == SDL_HAPTIC_FRICTION)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
            dest->type = FF_FRICTION;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   647
        dest->direction = 0;    /* Handled by the condition-specifics. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   648
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   649
        /* Replay */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
        dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ?
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   651
            0 : CLAMP(condition->length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   652
        dest->replay.delay = CLAMP(condition->delay);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   653
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   654
        /* Trigger */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   655
        dest->trigger.button = SDL_SYS_ToButton(condition->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
        dest->trigger.interval = CLAMP(condition->interval);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   657
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   658
        /* Condition */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
        /* X axis */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
        dest->u.condition[0].right_saturation =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   661
            CLAMP(condition->right_sat[0]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   662
        dest->u.condition[0].left_saturation = CLAMP(condition->left_sat[0]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   663
        dest->u.condition[0].right_coeff = condition->right_coeff[0];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
        dest->u.condition[0].left_coeff = condition->left_coeff[0];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   665
        dest->u.condition[0].deadband = CLAMP(condition->deadband[0]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   666
        dest->u.condition[0].center = condition->center[0];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   667
        /* Y axis */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   668
        dest->u.condition[1].right_saturation =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   669
            CLAMP(condition->right_sat[1]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   670
        dest->u.condition[1].left_saturation = CLAMP(condition->left_sat[1]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   671
        dest->u.condition[1].right_coeff = condition->right_coeff[1];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   672
        dest->u.condition[1].left_coeff = condition->left_coeff[1];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   673
        dest->u.condition[1].deadband = CLAMP(condition->deadband[1]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   674
        dest->u.condition[1].center = condition->center[1];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   675
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   676
        /*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   677
         * There is no envelope in the linux force feedback api for conditions.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   678
         */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   679
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   680
        break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   681
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
    case SDL_HAPTIC_RAMP:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   683
        ramp = &src->ramp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   684
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
        /* Header */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   686
        dest->type = FF_RAMP;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   687
        dest->direction = SDL_SYS_ToDirection(&ramp->direction);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   688
        if (dest->direction == (Uint16) - 1)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   689
            return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   690
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
        /* Replay */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   692
        dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ?
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   693
            0 : CLAMP(ramp->length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   694
        dest->replay.delay = CLAMP(ramp->delay);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   695
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   696
        /* Trigger */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
        dest->trigger.button = SDL_SYS_ToButton(ramp->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   698
        dest->trigger.interval = CLAMP(ramp->interval);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
        /* Ramp */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   701
        dest->u.ramp.start_level = ramp->start;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   702
        dest->u.ramp.end_level = ramp->end;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   703
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   704
        /* Envelope */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   705
        dest->u.ramp.envelope.attack_length = CLAMP(ramp->attack_length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   706
        dest->u.ramp.envelope.attack_level = CLAMP(ramp->attack_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   707
        dest->u.ramp.envelope.fade_length = CLAMP(ramp->fade_length);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   708
        dest->u.ramp.envelope.fade_level = CLAMP(ramp->fade_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   709
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   710
        break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   711
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   712
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   713
    default:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   714
        SDL_SetError("Haptic: Unknown effect type.");
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   715
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   716
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   717
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   718
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   719
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   720
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   721
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   722
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   723
 * Creates a new haptic effect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   724
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   725
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   726
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   727
                        SDL_HapticEffect * base)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   728
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   729
    struct ff_effect *linux_effect;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   730
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   731
    /* Allocate the hardware effect */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   732
    effect->hweffect = (struct haptic_hweffect *)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   733
        SDL_malloc(sizeof(struct haptic_hweffect));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   734
    if (effect->hweffect == NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   735
        SDL_OutOfMemory();
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   736
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   737
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   738
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   739
    /* Prepare the ff_effect */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   740
    linux_effect = &effect->hweffect->effect;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   741
    if (SDL_SYS_ToFFEffect(linux_effect, base) != 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   742
        goto new_effect_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   744
    linux_effect->id = -1;      /* Have the kernel give it an id */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   745
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   746
    /* Upload the effect */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   747
    if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   748
        SDL_SetError("Haptic: Error uploading effect to the device: %s",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   749
                     strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   750
        goto new_effect_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   751
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   752
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   753
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   754
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
  new_effect_err:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
    free(effect->hweffect);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   757
    effect->hweffect = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
    return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   760
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   761
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   762
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   763
 * Updates an effect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   764
 *
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   765
 * Note: Dynamically updating the direction can in some cases force
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   766
 * the effect to restart and run once.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   767
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   768
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   769
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   770
                           struct haptic_effect *effect,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   771
                           SDL_HapticEffect * data)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   772
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   773
    struct ff_effect linux_effect;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   774
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   775
    /* Create the new effect */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   776
    if (SDL_SYS_ToFFEffect(&linux_effect, data) != 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   777
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   778
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   779
    linux_effect.id = effect->hweffect->effect.id;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   780
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   781
    /* See if it can be uploaded. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   782
    if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   783
        SDL_SetError("Haptic: Error updating the effect: %s",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   784
                     strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   786
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   787
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   788
    /* Copy the new effect into memory. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   789
    SDL_memcpy(&effect->hweffect->effect, &linux_effect,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   790
               sizeof(struct ff_effect));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   791
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   792
    return effect->hweffect->effect.id;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   795
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   796
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   797
 * Runs an effect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   798
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   799
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   800
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   801
                        Uint32 iterations)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   802
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   803
    struct input_event run;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   805
    /* Prepare to run the effect */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   806
    run.type = EV_FF;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   807
    run.code = effect->hweffect->effect.id;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   808
    /* We don't actually have infinity here, so we just do INT_MAX which is pretty damn close. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   809
    run.value = (iterations > INT_MAX) ? INT_MAX : iterations;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   810
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   811
    if (write(haptic->hwdata->fd, (const void *) &run, sizeof(run)) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   812
        SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   813
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   814
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   815
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   816
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   817
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   818
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   819
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   820
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   821
 * Stops an effect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   822
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   823
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   824
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   825
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   826
    struct input_event stop;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   827
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   828
    stop.type = EV_FF;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   829
    stop.code = effect->hweffect->effect.id;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   830
    stop.value = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   831
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   832
    if (write(haptic->hwdata->fd, (const void *) &stop, sizeof(stop)) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   833
        SDL_SetError("Haptic: Unable to stop the effect: %s",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   834
                     strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   835
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   836
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   837
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   838
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   839
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   840
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   841
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   842
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   843
 * Frees the effect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   844
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   845
void
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   846
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   847
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   848
    if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   849
        SDL_SetError("Haptic: Error removing the effect from the device: %s",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   850
                     strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   851
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   852
    SDL_free(effect->hweffect);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   853
    effect->hweffect = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   854
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   855
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   856
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   857
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   858
 * Gets the status of a haptic effect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   859
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   860
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   861
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   862
                              struct haptic_effect *effect)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   863
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   864
#if 0                           /* Not supported atm. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   865
    struct input_event ie;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   866
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   867
    ie.type = EV_FF;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   868
    ie.type = EV_FF_STATUS;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   869
    ie.code = effect->hweffect->effect.id;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   870
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   871
    if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   872
        SDL_SetError("Haptic: Error getting device status.");
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   873
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   874
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   875
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   876
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   877
#endif
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   878
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   879
    return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   880
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   881
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   882
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   883
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   884
 * Sets the gain.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   885
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   886
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   887
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   888
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   889
    struct input_event ie;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   890
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   891
    ie.type = EV_FF;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   892
    ie.code = FF_GAIN;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   893
    ie.value = (0xFFFFUL * gain) / 100;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   894
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   895
    if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   896
        SDL_SetError("Haptic: Error setting gain: %s", strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   897
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   898
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   899
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   900
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   901
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   902
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   903
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   904
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   905
 * Sets the autocentering.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   906
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   907
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   908
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   909
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   910
    struct input_event ie;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   911
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   912
    ie.type = EV_FF;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   913
    ie.code = FF_AUTOCENTER;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   914
    ie.value = (0xFFFFUL * autocenter) / 100;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   915
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   916
    if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   917
        SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   918
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   919
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   920
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   921
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   922
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   923
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   924
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   925
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   926
 * Pausing is not supported atm by linux.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   927
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   928
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   929
SDL_SYS_HapticPause(SDL_Haptic * haptic)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   930
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   931
    return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   932
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   933
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   934
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   935
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   936
 * Unpausing is not supported atm by linux.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   937
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   938
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   939
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   940
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   941
    return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   942
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   943
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   944
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   945
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   946
 * Stops all the currently playing effects.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   947
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   948
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   949
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   950
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   951
    int i, ret;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   952
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   953
    /* Linux does not support this natively so we have to loop. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   954
    for (i = 0; i < haptic->neffects; i++) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   955
        if (haptic->effects[i].hweffect != NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   956
            ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   957
            if (ret < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   958
                SDL_SetError
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   959
                    ("Haptic: Error while trying to stop all playing effects.");
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   960
                return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   961
            }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   962
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   963
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   964
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   965
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   966
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   967
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   968
#endif /* SDL_HAPTIC_LINUX */