src/haptic/darwin/SDL_syshaptic.c
author Edward Rudd <urkle@outoforder.cc>
Tue, 04 Feb 2014 18:17:16 -0500
changeset 8173 23919d993046
parent 8149 681eb46b8ac4
child 8176 9efac2fd6ed6
permissions -rw-r--r--
Implement new backend methods for haptic and hot plugging on OS X
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
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
     7
  arising from the use of this software.
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    11
  freely, subject to the following restrictions:
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5358
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7719
diff changeset
    21
#include "../../SDL_internal.h"
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#ifdef SDL_HAPTIC_IOKIT
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    25
#include "SDL_assert.h"
2713
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/darwin/SDL_sysjoystick_c.h"    /* For joystick hwdata */
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    31
#include "SDL_syshaptic_c.h"
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include <IOKit/IOKitLib.h>
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include <IOKit/hid/IOHIDKeys.h>
2729
6c8bc4d87282 Missing an include.
Edgar Simo <bobbens@gmail.com>
parents: 2713
diff changeset
    35
#include <IOKit/hid/IOHIDUsageTables.h>
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include <ForceFeedback/ForceFeedback.h>
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#include <ForceFeedback/ForceFeedbackConstants.h>
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
3048
b717ce4dfe36 Fixed compilation on Mac OS X 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
    39
#ifndef IO_OBJECT_NULL
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7132
diff changeset
    40
#define IO_OBJECT_NULL  ((io_service_t)0)
3048
b717ce4dfe36 Fixed compilation on Mac OS X 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
    41
#endif
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
 * List of available haptic devices.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
 */
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    46
typedef struct SDL_hapticlist_item
2713
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
    char name[256];             /* Name of the device. */
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
    io_service_t dev;           /* Node we use to create the device. */
7132
1415923c2eab Corrected spelling in C source files.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
    51
    SDL_Haptic *haptic;         /* Haptic currently associated with it. */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
    /* Usage pages for determining if it's a mouse or not. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
    long usage;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
    long usagePage;
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    56
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    57
    struct SDL_hapticlist_item *next;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    58
} SDL_hapticlist_item;
2713
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
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
 * Haptic system hardware data.
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
struct haptic_hwdata
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    FFDeviceObjectReference device;     /* Hardware device. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
    UInt8 axes[3];
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
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
 * Haptic system effect data.
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 haptic_hweffect
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
    FFEffectObjectReference ref;        /* Reference. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    struct FFEFFECT effect;     /* Hardware effect. */
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
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
 * Prototypes.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
static int HIDGetDeviceProduct(io_service_t dev, char *name);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    86
static SDL_hapticlist_item *SDL_hapticlist = NULL;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    87
static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    88
static int numhaptics = 0;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7132
diff changeset
    90
/*
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
 * Like strerror but for force feedback errors.
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
static const char *
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
FFStrError(HRESULT err)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    switch (err) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
    case FFERR_DEVICEFULL:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
        return "device full";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
        /* This should be valid, but for some reason isn't defined... */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   100
        /* case FFERR_DEVICENOTREG:
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
           return "device not registered"; */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
    case FFERR_DEVICEPAUSED:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
        return "device paused";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    case FFERR_DEVICERELEASED:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
        return "device released";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
    case FFERR_EFFECTPLAYING:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
        return "effect playing";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
    case FFERR_EFFECTTYPEMISMATCH:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
        return "effect type mismatch";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
    case FFERR_EFFECTTYPENOTSUPPORTED:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
        return "effect type not supported";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    case FFERR_GENERIC:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
        return "undetermined error";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
    case FFERR_HASEFFECTS:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
        return "device has effects";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
    case FFERR_INCOMPLETEEFFECT:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
        return "incomplete effect";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
    case FFERR_INTERNAL:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
        return "internal fault";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
    case FFERR_INVALIDDOWNLOADID:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
        return "invalid download id";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
    case FFERR_INVALIDPARAM:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
        return "invalid parameter";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
    case FFERR_MOREDATA:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
        return "more data";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
    case FFERR_NOINTERFACE:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
        return "interface not supported";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
    case FFERR_NOTDOWNLOADED:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
        return "effect is not downloaded";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    case FFERR_NOTINITIALIZED:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
        return "object has not been initialized";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
    case FFERR_OUTOFMEMORY:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
        return "out of memory";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
    case FFERR_UNPLUGGED:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
        return "device is unplugged";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
    case FFERR_UNSUPPORTED:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
        return "function call unsupported";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    case FFERR_UNSUPPORTEDAXIS:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
        return "axis unsupported";
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
    default:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
        return "unknown error";
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
}
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
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
 * Initializes the haptic subsystem.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
SDL_SYS_HapticInit(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
    IOReturn result;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
    io_iterator_t iter;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
    CFDictionaryRef match;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
    io_service_t device;
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
    /* Get HID devices. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
    match = IOServiceMatching(kIOHIDDeviceKey);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    if (match == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   161
        return SDL_SetError("Haptic: Failed to get IOServiceMatching.");
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    }
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
    /* Now search I/O Registry for matching devices. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
    if (result != kIOReturnSuccess) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   167
        return SDL_SetError("Haptic: Couldn't create a HID object iterator.");
2713
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
    /* IOServiceGetMatchingServices consumes dictionary. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
    if (!IOIteratorIsValid(iter)) {     /* No iterator. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
        return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
    while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) {
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   176
        PRIVATE_MaybeAddDevice(device);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   177
        /* always release as the AddDevice will retain IF it's a forcefeedback device */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   178
        IOObjectRelease(device);
2713
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
    IOObjectRelease(iter);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
    return numhaptics;
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
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   185
int
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   186
SDL_SYS_NumHaptics()
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   187
{
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   188
    return numhaptics;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   189
}
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   190
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   191
static SDL_hapticlist_item *
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   192
HapticByDevIndex(int device_index)
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   193
{
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   194
    SDL_hapticlist_item *item = SDL_hapticlist;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   195
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   196
    if ((device_index < 0) || (device_index >= numhaptics)) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   197
        return NULL;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   198
    }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   199
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   200
    while (device_index > 0) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   201
        SDL_assert(item != NULL);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   202
        device_index--;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   203
        item = item->next;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   204
    }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   205
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   206
    return item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   207
}
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   208
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   209
int
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   210
PRIVATE_MaybeAddDevice( io_object_t device )
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   211
{
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   212
    IOReturn result;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   213
    CFMutableDictionaryRef hidProperties;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   214
    CFTypeRef refCF;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   215
    SDL_hapticlist_item *item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   216
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   217
    /* Check for force feedback. */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   218
    if (FFIsForceFeedback(device) != FF_OK) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   219
        return -1;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   220
    }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   221
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   222
    /* Make sure we don't already have it */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   223
    for (item = SDL_hapticlist; item ; item = item->next)
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   224
    {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   225
        if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   226
            /* Already added */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   227
            return -1;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   228
        }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   229
    }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   230
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   231
    item = (SDL_hapticlist_item *)SDL_malloc( sizeof(SDL_hapticlist_item));
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   232
    if (item == NULL) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   233
        return SDL_SetError("Could not allocate haptic storage");
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   234
    }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   235
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   236
    /* retain it as we are going to keep it around a while */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   237
    IOObjectRetain(device);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   238
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   239
    /* Set basic device data. */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   240
    HIDGetDeviceProduct(device, item->name);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   241
    item->dev = device;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   242
    item->haptic = NULL;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   243
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   244
    /* Set usage pages. */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   245
    hidProperties = 0;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   246
    refCF = 0;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   247
    result = IORegistryEntryCreateCFProperties(device,
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   248
                                               &hidProperties,
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   249
                                               kCFAllocatorDefault,
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   250
                                               kNilOptions);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   251
    if ((result == KERN_SUCCESS) && hidProperties) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   252
        refCF =
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   253
        CFDictionaryGetValue(hidProperties,
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   254
                             CFSTR(kIOHIDPrimaryUsagePageKey));
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   255
        if (refCF) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   256
            if (!CFNumberGetValue(refCF, kCFNumberLongType,
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   257
                                  &item->usagePage))
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   258
                SDL_SetError
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   259
                ("Haptic: Recieving device's usage page.");
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   260
            refCF =
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   261
            CFDictionaryGetValue(hidProperties,
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   262
                                 CFSTR(kIOHIDPrimaryUsageKey));
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   263
            if (refCF) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   264
                if (!CFNumberGetValue(refCF, kCFNumberLongType,
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   265
                                      &item->usage))
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   266
                    SDL_SetError("Haptic: Recieving device's usage.");
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   267
            }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   268
        }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   269
        CFRelease(hidProperties);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   270
    }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   271
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   272
    if (SDL_hapticlist_tail == NULL) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   273
        SDL_hapticlist = SDL_hapticlist_tail = item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   274
    } else {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   275
        SDL_hapticlist_tail->next = item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   276
        SDL_hapticlist_tail = item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   277
    }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   278
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   279
    /* Device has been added. */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   280
    ++numhaptics;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   281
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   282
    return numhaptics;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   283
}
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   284
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   285
int
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   286
PRIVATE_MaybeRemoveDevice( io_object_t device )
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   287
{
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   288
    SDL_hapticlist_item *item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   289
    SDL_hapticlist_item *prev = NULL;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   290
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   291
    for (item = SDL_hapticlist; item != NULL; item = item->next) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   292
        /* found it, remove it. */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   293
        if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   294
            const int retval = item->haptic ? item->haptic->index : -1;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   295
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   296
            if (prev != NULL) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   297
                prev->next = item->next;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   298
            } else {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   299
                SDL_assert(SDL_hapticlist == item);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   300
                SDL_hapticlist = item->next;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   301
            }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   302
            if (item == SDL_hapticlist_tail) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   303
                SDL_hapticlist_tail = prev;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   304
            }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   305
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   306
            /* Need to decrement the haptic count */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   307
            --numhaptics;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   308
            /* !!! TODO: Send a haptic remove event? */
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   309
            
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   310
            IOObjectRelease(item->dev);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   311
            SDL_free(item);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   312
            return retval;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   313
        }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   314
        prev = item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   315
    }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   316
    
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   317
    return -1;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   318
}
2713
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
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
 * 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
   322
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
const char *
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
SDL_SYS_HapticName(int index)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
{
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   326
    SDL_hapticlist_item *item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   327
    item = HapticByDevIndex(index);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   328
    return item->name;
2713
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
 * Gets the device's product name.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
static int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
HIDGetDeviceProduct(io_service_t dev, char *name)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    CFMutableDictionaryRef hidProperties, usbProperties;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
    io_registry_entry_t parent1, parent2;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    kern_return_t ret;
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
    hidProperties = usbProperties = 0;
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
    ret = IORegistryEntryCreateCFProperties(dev, &hidProperties,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
                                            kCFAllocatorDefault, kNilOptions);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
    if ((ret != KERN_SUCCESS) || !hidProperties) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   346
        return SDL_SetError("Haptic: Unable to create CFProperties.");
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
    /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
7132
1415923c2eab Corrected spelling in C source files.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
   350
     * get dictionary for USB properties: step up two levels and get CF dictionary for USB properties
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
     */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
    if ((KERN_SUCCESS ==
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
         IORegistryEntryGetParentEntry(dev, kIOServicePlane, &parent1))
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
        && (KERN_SUCCESS ==
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
            IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
        && (KERN_SUCCESS ==
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
            IORegistryEntryCreateCFProperties(parent2, &usbProperties,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
                                              kCFAllocatorDefault,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
                                              kNilOptions))) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
        if (usbProperties) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
            CFTypeRef refCF = 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
            /* get device info
7132
1415923c2eab Corrected spelling in C source files.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
   363
             * try hid dictionary first, if fail then go to USB dictionary
2713
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
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
            /* Get product name */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
            refCF =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
                CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
            if (!refCF)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
                refCF =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
                    CFDictionaryGetValue(usbProperties,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
                                         CFSTR("USB Product Name"));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
            if (refCF) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
                if (!CFStringGetCString(refCF, name, 256,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
                                        CFStringGetSystemEncoding())) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   377
                    return SDL_SetError
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
                        ("Haptic: CFStringGetCString error retrieving pDevice->product.");
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
            }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   381
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
            CFRelease(usbProperties);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
        } else {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   384
            return SDL_SetError
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
                ("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
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
        /* Release stuff. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
        if (kIOReturnSuccess != IOObjectRelease(parent2)) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
            SDL_SetError("Haptic: IOObjectRelease error with parent2.");
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
        if (kIOReturnSuccess != IOObjectRelease(parent1)) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
            SDL_SetError("Haptic: IOObjectRelease error with parent1.");
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
    } else {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   396
        return SDL_SetError("Haptic: Error getting registry entries.");
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
#define FF_TEST(ff, s) \
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
if (features.supportedEffects & (ff)) supported |= (s)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
 * Gets supported features.
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
static unsigned int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
GetSupportedFeatures(SDL_Haptic * haptic)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
    HRESULT ret;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
    FFDeviceObjectReference device;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
    FFCAPABILITIES features;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
    unsigned int supported;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    Uint32 val;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
    device = haptic->hwdata->device;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
    ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
    if (ret != FF_OK) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   421
        return SDL_SetError("Haptic: Unable to get device's supported features.");
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
    supported = 0;
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
    /* Get maximum effects. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
    haptic->neffects = features.storageCapacity;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
    haptic->nplaying = features.playbackCapacity;
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
    /* Test for effects. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
    FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
    FF_TEST(FFCAP_ET_RAMPFORCE, SDL_HAPTIC_RAMP);
7621
5caa5fb3deb6 Replaced SDL_HAPTIC_SQUARE with SDL_HAPTIC_LEFTRIGHT.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   433
    /* !!! FIXME: put this back when we have more bits in 2.1 */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   434
    /* FF_TEST(FFCAP_ET_SQUARE, SDL_HAPTIC_SQUARE); */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
    FF_TEST(FFCAP_ET_SINE, SDL_HAPTIC_SINE);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
    FF_TEST(FFCAP_ET_TRIANGLE, SDL_HAPTIC_TRIANGLE);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
    FF_TEST(FFCAP_ET_SAWTOOTHUP, SDL_HAPTIC_SAWTOOTHUP);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
    FF_TEST(FFCAP_ET_SAWTOOTHDOWN, SDL_HAPTIC_SAWTOOTHDOWN);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
    FF_TEST(FFCAP_ET_SPRING, SDL_HAPTIC_SPRING);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
    FF_TEST(FFCAP_ET_DAMPER, SDL_HAPTIC_DAMPER);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   441
    FF_TEST(FFCAP_ET_INERTIA, SDL_HAPTIC_INERTIA);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   442
    FF_TEST(FFCAP_ET_FRICTION, SDL_HAPTIC_FRICTION);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   443
    FF_TEST(FFCAP_ET_CUSTOMFORCE, SDL_HAPTIC_CUSTOM);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
    /* Check if supports gain. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
    ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
                                           &val, sizeof(val));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
    if (ret == FF_OK)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
        supported |= SDL_HAPTIC_GAIN;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
    else if (ret != FFERR_UNSUPPORTED) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   451
        return SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   452
                            FFStrError(ret));
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
    }
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
    /* Checks if supports autocenter. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
    ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
                                           &val, sizeof(val));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
    if (ret == FF_OK)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
        supported |= SDL_HAPTIC_AUTOCENTER;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   460
    else if (ret != FFERR_UNSUPPORTED) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   461
        return SDL_SetError
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
            ("Haptic: Unable to get if device supports autocenter: %s.",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
             FFStrError(ret));
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
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   466
    /* Check for axes, we have an artificial limit on axes */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   467
    haptic->naxes = ((features.numFfAxes) > 3) ? 3 : features.numFfAxes;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   468
    /* Actually store the axes we want to use */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   469
    SDL_memcpy(haptic->hwdata->axes, features.ffAxes,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   470
               haptic->naxes * sizeof(Uint8));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
    /* Always supported features. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
    supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
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
    haptic->supported = supported;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
    return 0;;
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
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
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
 * 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
   482
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
static int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
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
    HRESULT ret;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
    int ret2;
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
    /* Allocate the hwdata */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
    haptic->hwdata = (struct haptic_hwdata *)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
        SDL_malloc(sizeof(*haptic->hwdata));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   492
    if (haptic->hwdata == NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
        SDL_OutOfMemory();
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
        goto creat_err;
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
    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
   497
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
    /* Open the device */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
    ret = FFCreateDevice(service, &haptic->hwdata->device);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
    if (ret != FF_OK) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
        SDL_SetError("Haptic: Unable to create device from service: %s.",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
                     FFStrError(ret));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
        goto creat_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
    }
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
    /* Get supported features. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
    ret2 = GetSupportedFeatures(haptic);
6139
06710207a491 Check return value, not unsigned "supported" flags
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   508
    if (ret2 < 0) {
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
        goto open_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
    }
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
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
    /* Reset and then enable actuators. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
    ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
                                           FFSFFC_RESET);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
    if (ret != FF_OK) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
        SDL_SetError("Haptic: Unable to reset device: %s.", FFStrError(ret));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
        goto open_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   520
    ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
                                           FFSFFC_SETACTUATORSON);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
    if (ret != FF_OK) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
        SDL_SetError("Haptic: Unable to enable actuators: %s.",
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
                     FFStrError(ret));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
        goto open_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
    }
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
    /* Allocate effects memory. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   530
    haptic->effects = (struct haptic_effect *)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
        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
   532
    if (haptic->effects == NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
        SDL_OutOfMemory();
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
        goto open_err;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   536
    /* Clear the memory */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
    SDL_memset(haptic->effects, 0,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
               sizeof(struct haptic_effect) * haptic->neffects);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
    /* Error handling */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
  open_err:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
    FFReleaseDevice(haptic->hwdata->device);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
  creat_err:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
    if (haptic->hwdata != NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
        free(haptic->hwdata);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
        haptic->hwdata = NULL;
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
    return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
}
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
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
 * Opens a haptic device for usage.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   557
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
{
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   561
    SDL_hapticlist_item *item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   562
    item = HapticByDevIndex(haptic->index);
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   563
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   564
    return SDL_SYS_HapticOpenFromService(haptic, item->dev);
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
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
 * 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
   570
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
SDL_SYS_HapticMouse(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
{
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   574
    int device_index = 0;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   575
    SDL_hapticlist_item *item;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   577
    for (item = SDL_hapticlist; item; item = item->next) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   578
        if ((item->usagePage == kHIDPage_GenericDesktop) &&
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   579
            (item->usage == kHIDUsage_GD_Mouse))
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   580
            return device_index;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   581
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   582
        ++device_index;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
    return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
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
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
 * 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
   591
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
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
    if (joystick->hwdata->ffservice != 0)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
        return SDL_TRUE;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
    return SDL_FALSE;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
}
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
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
/*
7708
d5aa9910b1f7 Fixed comment typo.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   602
 * Checks to see if the haptic device and joystick are in reality the same.
2713
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
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
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
   606
{
5632
f2aeea007e85 Fixed compiler warning on 64-bit builds.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   607
    if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
                          joystick->hwdata->ffservice))
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
        return 1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
 * 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
   616
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
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
   619
{
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   620
    int device_index = 0;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   621
    SDL_hapticlist_item *item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   622
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   623
    for (item = SDL_hapticlist; item; item = item->next) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   624
        if (IOObjectIsEqualTo((io_object_t) item->dev,
5358
5b330ef7b8dd Untested fix for bug 946 (SDL_HapticIndex returns 0 for all devices)
Sam Lantinga <slouken@libsdl.org>
parents: 3048
diff changeset
   625
                             joystick->hwdata->ffservice)) {
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   626
           haptic->index = device_index;
5358
5b330ef7b8dd Untested fix for bug 946 (SDL_HapticIndex returns 0 for all devices)
Sam Lantinga <slouken@libsdl.org>
parents: 3048
diff changeset
   627
           break;
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   628
        }
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   629
        ++device_index;
5358
5b330ef7b8dd Untested fix for bug 946 (SDL_HapticIndex returns 0 for all devices)
Sam Lantinga <slouken@libsdl.org>
parents: 3048
diff changeset
   630
    }
5b330ef7b8dd Untested fix for bug 946 (SDL_HapticIndex returns 0 for all devices)
Sam Lantinga <slouken@libsdl.org>
parents: 3048
diff changeset
   631
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
    return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   634
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   637
 * Closes the haptic device.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   638
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   639
void
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   640
SDL_SYS_HapticClose(SDL_Haptic * haptic)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   641
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
    if (haptic->hwdata) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   643
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   644
        /* Free Effects. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   645
        SDL_free(haptic->effects);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
        haptic->effects = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   647
        haptic->neffects = 0;
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
        /* Clean up */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
        FFReleaseDevice(haptic->hwdata->device);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   651
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   652
        /* Free */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   653
        SDL_free(haptic->hwdata);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   654
        haptic->hwdata = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   655
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
}
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
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7132
diff changeset
   659
/*
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
 * 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
   661
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   662
void
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   663
SDL_SYS_HapticQuit(void)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
{
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   665
    SDL_hapticlist_item *item;
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   666
    SDL_hapticlist_item *next = NULL;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   667
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   668
    for (item = SDL_hapticlist; item; item = next) {
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   669
        next = item->next;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   670
        /* 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
   671
         * Close your haptic devices after usage. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   672
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   673
        /* Free the io_service_t */
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   674
        IOObjectRelease(item->dev);
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   675
    }
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   676
    numhaptics = 0;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   677
}
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
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   681
 * Converts an SDL trigger button to an FFEFFECT trigger button.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   683
static DWORD
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   684
FFGetTriggerButton(Uint16 button)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   686
    DWORD dwTriggerButton;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   687
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   688
    dwTriggerButton = FFEB_NOTRIGGER;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   689
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   690
    if (button != 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
        dwTriggerButton = FFJOFS_BUTTON(button - 1);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   692
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   693
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   694
    return dwTriggerButton;
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
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   698
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
 * Sets the direction.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   701
static int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   702
SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
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
    LONG *rglDir;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   705
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   706
    /* Handle no axes a part. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   707
    if (naxes == 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   708
        effect->dwFlags |= FFEFF_SPHERICAL;     /* Set as default. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   709
        effect->rglDirection = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   710
        return 0;
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
    /* Has axes. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   714
    rglDir = SDL_malloc(sizeof(LONG) * naxes);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   715
    if (rglDir == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   716
        return SDL_OutOfMemory();
2713
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
    SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   719
    effect->rglDirection = rglDir;
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
    switch (dir->type) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   722
    case SDL_HAPTIC_POLAR:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   723
        effect->dwFlags |= FFEFF_POLAR;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   724
        rglDir[0] = dir->dir[0];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   725
        return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   726
    case SDL_HAPTIC_CARTESIAN:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   727
        effect->dwFlags |= FFEFF_CARTESIAN;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   728
        rglDir[0] = dir->dir[0];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   729
        if (naxes > 1)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   730
            rglDir[1] = dir->dir[1];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   731
        if (naxes > 2)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   732
            rglDir[2] = dir->dir[2];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   733
        return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   734
    case SDL_HAPTIC_SPHERICAL:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   735
        effect->dwFlags |= FFEFF_SPHERICAL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   736
        rglDir[0] = dir->dir[0];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   737
        if (naxes > 1)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   738
            rglDir[1] = dir->dir[1];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   739
        if (naxes > 2)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   740
            rglDir[2] = dir->dir[2];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   741
        return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   742
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
    default:
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   744
        return SDL_SetError("Haptic: Unknown direction type.");
2713
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
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   747
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   748
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   749
/* Clamps and converts. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   750
#define CCONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   751
/* Just converts. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   752
#define CONVERT(x)    (((x)*10000) / 0x7FFF)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   753
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   754
 * Creates the FFEFFECT from a SDL_HapticEffect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
static int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   757
SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
                   SDL_HapticEffect * src)
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
    int i;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   761
    FFCONSTANTFORCE *constant;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   762
    FFPERIODIC *periodic;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   763
    FFCONDITION *condition;     /* Actually an array of conditions - one per axis. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   764
    FFRAMPFORCE *ramp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   765
    FFCUSTOMFORCE *custom;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   766
    FFENVELOPE *envelope;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   767
    SDL_HapticConstant *hap_constant;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   768
    SDL_HapticPeriodic *hap_periodic;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   769
    SDL_HapticCondition *hap_condition;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   770
    SDL_HapticRamp *hap_ramp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   771
    SDL_HapticCustom *hap_custom;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   772
    DWORD *axes;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   773
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   774
    /* Set global stuff. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   775
    SDL_memset(dest, 0, sizeof(FFEFFECT));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   776
    dest->dwSize = sizeof(FFEFFECT);    /* Set the structure size. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   777
    dest->dwSamplePeriod = 0;   /* Not used by us. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   778
    dest->dwGain = 10000;       /* Gain is set globally, not locally. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   779
    dest->dwFlags = FFEFF_OBJECTOFFSETS;        /* Seems obligatory. */
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
    /* Envelope. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   782
    envelope = SDL_malloc(sizeof(FFENVELOPE));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   783
    if (envelope == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   784
        return SDL_OutOfMemory();
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   786
    SDL_memset(envelope, 0, sizeof(FFENVELOPE));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   787
    dest->lpEnvelope = envelope;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   788
    envelope->dwSize = sizeof(FFENVELOPE);      /* Always should be this. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   789
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   790
    /* Axes. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   791
    dest->cAxes = haptic->naxes;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   792
    if (dest->cAxes > 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
        axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
        if (axes == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   795
            return SDL_OutOfMemory();
2713
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
        axes[0] = haptic->hwdata->axes[0];      /* Always at least one axis. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   798
        if (dest->cAxes > 1) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   799
            axes[1] = haptic->hwdata->axes[1];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   800
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   801
        if (dest->cAxes > 2) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   802
            axes[2] = haptic->hwdata->axes[2];
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   803
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
        dest->rgdwAxes = axes;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   805
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   806
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   807
7132
1415923c2eab Corrected spelling in C source files.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
   808
    /* The big type handling switch, even bigger then Linux's version. */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   809
    switch (src->type) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   810
    case SDL_HAPTIC_CONSTANT:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   811
        hap_constant = &src->constant;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   812
        constant = SDL_malloc(sizeof(FFCONSTANTFORCE));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   813
        if (constant == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   814
            return SDL_OutOfMemory();
2713
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
        SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
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
        /* Specifics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   819
        constant->lMagnitude = CONVERT(hap_constant->level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   820
        dest->cbTypeSpecificParams = sizeof(FFCONSTANTFORCE);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   821
        dest->lpvTypeSpecificParams = constant;
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
        /* Generics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   824
        dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   825
        dest->dwTriggerButton = FFGetTriggerButton(hap_constant->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   826
        dest->dwTriggerRepeatInterval = hap_constant->interval;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   827
        dest->dwStartDelay = hap_constant->delay * 1000;        /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   828
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   829
        /* Direction. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   830
        if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   831
            < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   832
            return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   833
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   834
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   835
        /* Envelope */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   836
        if ((hap_constant->attack_length == 0)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   837
            && (hap_constant->fade_length == 0)) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   838
            SDL_free(envelope);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   839
            dest->lpEnvelope = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   840
        } else {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   841
            envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   842
            envelope->dwAttackTime = hap_constant->attack_length * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   843
            envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   844
            envelope->dwFadeTime = hap_constant->fade_length * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   845
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   846
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   847
        break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   848
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   849
    case SDL_HAPTIC_SINE:
7621
5caa5fb3deb6 Replaced SDL_HAPTIC_SQUARE with SDL_HAPTIC_LEFTRIGHT.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   850
    /* !!! FIXME: put this back when we have more bits in 2.1 */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   851
    /* case SDL_HAPTIC_SQUARE: */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   852
    case SDL_HAPTIC_TRIANGLE:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   853
    case SDL_HAPTIC_SAWTOOTHUP:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   854
    case SDL_HAPTIC_SAWTOOTHDOWN:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   855
        hap_periodic = &src->periodic;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   856
        periodic = SDL_malloc(sizeof(FFPERIODIC));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   857
        if (periodic == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   858
            return SDL_OutOfMemory();
2713
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
        SDL_memset(periodic, 0, sizeof(FFPERIODIC));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   861
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   862
        /* Specifics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   863
        periodic->dwMagnitude = CONVERT(hap_periodic->magnitude);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   864
        periodic->lOffset = CONVERT(hap_periodic->offset);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   865
        periodic->dwPhase = hap_periodic->phase;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   866
        periodic->dwPeriod = hap_periodic->period * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   867
        dest->cbTypeSpecificParams = sizeof(FFPERIODIC);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   868
        dest->lpvTypeSpecificParams = periodic;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   869
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   870
        /* Generics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   871
        dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   872
        dest->dwTriggerButton = FFGetTriggerButton(hap_periodic->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   873
        dest->dwTriggerRepeatInterval = hap_periodic->interval;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   874
        dest->dwStartDelay = hap_periodic->delay * 1000;        /* In microseconds. */
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
        /* Direction. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   877
        if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   878
            < 0) {
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
        /* Envelope */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   883
        if ((hap_periodic->attack_length == 0)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   884
            && (hap_periodic->fade_length == 0)) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   885
            SDL_free(envelope);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   886
            dest->lpEnvelope = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   887
        } else {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   888
            envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   889
            envelope->dwAttackTime = hap_periodic->attack_length * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   890
            envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   891
            envelope->dwFadeTime = hap_periodic->fade_length * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   892
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   893
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   894
        break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   895
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   896
    case SDL_HAPTIC_SPRING:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   897
    case SDL_HAPTIC_DAMPER:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   898
    case SDL_HAPTIC_INERTIA:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   899
    case SDL_HAPTIC_FRICTION:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   900
        hap_condition = &src->condition;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   901
        condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   902
        if (condition == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   903
            return SDL_OutOfMemory();
2713
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
        SDL_memset(condition, 0, sizeof(FFCONDITION));
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
        /* Specifics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   908
        for (i = 0; i < dest->cAxes; i++) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   909
            condition[i].lOffset = CONVERT(hap_condition->center[i]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   910
            condition[i].lPositiveCoefficient =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   911
                CONVERT(hap_condition->right_coeff[i]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   912
            condition[i].lNegativeCoefficient =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   913
                CONVERT(hap_condition->left_coeff[i]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   914
            condition[i].dwPositiveSaturation =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   915
                CCONVERT(hap_condition->right_sat[i]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   916
            condition[i].dwNegativeSaturation =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   917
                CCONVERT(hap_condition->left_sat[i]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   918
            condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i]);
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
        dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   921
        dest->lpvTypeSpecificParams = condition;
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
        /* Generics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   924
        dest->dwDuration = hap_condition->length * 1000;        /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   925
        dest->dwTriggerButton = FFGetTriggerButton(hap_condition->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   926
        dest->dwTriggerRepeatInterval = hap_condition->interval;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   927
        dest->dwStartDelay = hap_condition->delay * 1000;       /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   928
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   929
        /* Direction. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   930
        if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   931
            < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   932
            return -1;
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
        /* Envelope - Not actually supported by most CONDITION implementations. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   936
        SDL_free(dest->lpEnvelope);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   937
        dest->lpEnvelope = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   938
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   939
        break;
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
    case SDL_HAPTIC_RAMP:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   942
        hap_ramp = &src->ramp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   943
        ramp = SDL_malloc(sizeof(FFRAMPFORCE));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   944
        if (ramp == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   945
            return SDL_OutOfMemory();
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   946
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   947
        SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   948
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   949
        /* Specifics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   950
        ramp->lStart = CONVERT(hap_ramp->start);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   951
        ramp->lEnd = CONVERT(hap_ramp->end);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   952
        dest->cbTypeSpecificParams = sizeof(FFRAMPFORCE);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   953
        dest->lpvTypeSpecificParams = ramp;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   954
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   955
        /* Generics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   956
        dest->dwDuration = hap_ramp->length * 1000;     /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   957
        dest->dwTriggerButton = FFGetTriggerButton(hap_ramp->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   958
        dest->dwTriggerRepeatInterval = hap_ramp->interval;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   959
        dest->dwStartDelay = hap_ramp->delay * 1000;    /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   960
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   961
        /* Direction. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   962
        if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   963
            return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   964
        }
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
        /* Envelope */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   967
        if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   968
            SDL_free(envelope);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   969
            dest->lpEnvelope = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   970
        } else {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   971
            envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   972
            envelope->dwAttackTime = hap_ramp->attack_length * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   973
            envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   974
            envelope->dwFadeTime = hap_ramp->fade_length * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   975
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   976
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   977
        break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   978
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   979
    case SDL_HAPTIC_CUSTOM:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   980
        hap_custom = &src->custom;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   981
        custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   982
        if (custom == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   983
            return SDL_OutOfMemory();
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   984
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   985
        SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   986
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   987
        /* Specifics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   988
        custom->cChannels = hap_custom->channels;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   989
        custom->dwSamplePeriod = hap_custom->period * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   990
        custom->cSamples = hap_custom->samples;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   991
        custom->rglForceData =
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   992
            SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   993
        for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) {      /* Copy data. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   994
            custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   995
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   996
        dest->cbTypeSpecificParams = sizeof(FFCUSTOMFORCE);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   997
        dest->lpvTypeSpecificParams = custom;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   998
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   999
        /* Generics */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1000
        dest->dwDuration = hap_custom->length * 1000;   /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1001
        dest->dwTriggerButton = FFGetTriggerButton(hap_custom->button);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1002
        dest->dwTriggerRepeatInterval = hap_custom->interval;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1003
        dest->dwStartDelay = hap_custom->delay * 1000;  /* In microseconds. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1004
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1005
        /* Direction. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1006
        if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) <
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1007
            0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1008
            return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1009
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1010
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1011
        /* Envelope */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1012
        if ((hap_custom->attack_length == 0)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1013
            && (hap_custom->fade_length == 0)) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1014
            SDL_free(envelope);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1015
            dest->lpEnvelope = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1016
        } else {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1017
            envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1018
            envelope->dwAttackTime = hap_custom->attack_length * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1019
            envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1020
            envelope->dwFadeTime = hap_custom->fade_length * 1000;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1021
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1022
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1023
        break;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1024
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1025
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1026
    default:
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1027
        return SDL_SetError("Haptic: Unknown effect type.");
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1028
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1029
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1030
    return 0;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1031
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1032
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1033
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1034
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1035
 * Frees an FFEFFECT allocated by SDL_SYS_ToFFEFFECT.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1036
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1037
static void
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1038
SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1039
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1040
    FFCUSTOMFORCE *custom;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1041
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7708
diff changeset
  1042
    SDL_free(effect->lpEnvelope);
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7708
diff changeset
  1043
    effect->lpEnvelope = NULL;
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7708
diff changeset
  1044
    SDL_free(effect->rgdwAxes);
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7708
diff changeset
  1045
    effect->rgdwAxes = NULL;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1046
    if (effect->lpvTypeSpecificParams != NULL) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1047
        if (type == SDL_HAPTIC_CUSTOM) {        /* Must free the custom data. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1048
            custom = (FFCUSTOMFORCE *) effect->lpvTypeSpecificParams;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1049
            SDL_free(custom->rglForceData);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1050
            custom->rglForceData = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1051
        }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1052
        SDL_free(effect->lpvTypeSpecificParams);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1053
        effect->lpvTypeSpecificParams = NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1054
    }
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7708
diff changeset
  1055
    SDL_free(effect->rglDirection);
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7708
diff changeset
  1056
    effect->rglDirection = NULL;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1057
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1058
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1059
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1060
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1061
 * Gets the effect type from the generic SDL haptic effect wrapper.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1062
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1063
CFUUIDRef
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1064
SDL_SYS_HapticEffectType(Uint16 type)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1065
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1066
    switch (type) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1067
    case SDL_HAPTIC_CONSTANT:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1068
        return kFFEffectType_ConstantForce_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1069
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1070
    case SDL_HAPTIC_RAMP:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1071
        return kFFEffectType_RampForce_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1072
7621
5caa5fb3deb6 Replaced SDL_HAPTIC_SQUARE with SDL_HAPTIC_LEFTRIGHT.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
  1073
    /* !!! FIXME: put this back when we have more bits in 2.1 */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
  1074
    /* case SDL_HAPTIC_SQUARE:
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7621
diff changeset
  1075
        return kFFEffectType_Square_ID; */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1076
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1077
    case SDL_HAPTIC_SINE:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1078
        return kFFEffectType_Sine_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1079
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1080
    case SDL_HAPTIC_TRIANGLE:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1081
        return kFFEffectType_Triangle_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1082
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1083
    case SDL_HAPTIC_SAWTOOTHUP:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1084
        return kFFEffectType_SawtoothUp_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1085
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1086
    case SDL_HAPTIC_SAWTOOTHDOWN:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1087
        return kFFEffectType_SawtoothDown_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1088
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1089
    case SDL_HAPTIC_SPRING:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1090
        return kFFEffectType_Spring_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1091
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1092
    case SDL_HAPTIC_DAMPER:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1093
        return kFFEffectType_Damper_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1094
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1095
    case SDL_HAPTIC_INERTIA:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1096
        return kFFEffectType_Inertia_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1097
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1098
    case SDL_HAPTIC_FRICTION:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1099
        return kFFEffectType_Friction_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1100
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1101
    case SDL_HAPTIC_CUSTOM:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1102
        return kFFEffectType_CustomForce_ID;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1103
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1104
    default:
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1105
        SDL_SetError("Haptic: Unknown effect type.");
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1106
        return NULL;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1107
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1108
}
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1109
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1110
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1111
/*
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1112
 * Creates a new haptic effect.
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1113
 */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1114
int
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1115
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
  1116
                        SDL_HapticEffect * base)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1117
{
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1118
    HRESULT ret;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1119
    CFUUIDRef type;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1120
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1121
    /* Alloc the effect. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1122
    effect->hweffect = (struct haptic_hweffect *)
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: