src/haptic/windows/SDL_dinputhaptic.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 07 Jul 2014 10:26:28 -0700
changeset 8976 1a5d959d7b32
parent 8972 dfc759d7486f
child 9070 8973a237f360
permissions -rw-r--r--
Fixed mingw64 build and warnings
slouken@8972
     1
/*
slouken@8972
     2
  Simple DirectMedia Layer
slouken@8972
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@8972
     4
slouken@8972
     5
  This software is provided 'as-is', without any express or implied
slouken@8972
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@8972
     7
  arising from the use of this software.
slouken@8972
     8
slouken@8972
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@8972
    10
  including commercial applications, and to alter it and redistribute it
slouken@8972
    11
  freely, subject to the following restrictions:
slouken@8972
    12
slouken@8972
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@8972
    14
     claim that you wrote the original software. If you use this software
slouken@8972
    15
     in a product, an acknowledgment in the product documentation would be
slouken@8972
    16
     appreciated but is not required.
slouken@8972
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@8972
    18
     misrepresented as being the original software.
slouken@8972
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@8972
    20
*/
slouken@8972
    21
#include "../../SDL_internal.h"
slouken@8972
    22
slouken@8972
    23
#include "SDL_error.h"
slouken@8972
    24
#include "SDL_haptic.h"
slouken@8972
    25
#include "SDL_timer.h"
slouken@8972
    26
#include "SDL_windowshaptic_c.h"
slouken@8972
    27
#include "SDL_dinputhaptic_c.h"
slouken@8972
    28
#include "../SDL_syshaptic.h"
slouken@8972
    29
#include "../../joystick/windows/SDL_windowsjoystick_c.h"
slouken@8972
    30
slouken@8972
    31
slouken@8972
    32
#if SDL_HAPTIC_DINPUT
slouken@8972
    33
slouken@8972
    34
/*
slouken@8972
    35
 * External stuff.
slouken@8972
    36
 */
slouken@8972
    37
extern HWND SDL_HelperWindow;
slouken@8972
    38
slouken@8972
    39
slouken@8972
    40
/*
slouken@8972
    41
 * Internal stuff.
slouken@8972
    42
 */
slouken@8972
    43
static SDL_bool coinitialized = SDL_FALSE;
slouken@8972
    44
static LPDIRECTINPUT8 dinput = NULL;
slouken@8972
    45
slouken@8972
    46
slouken@8972
    47
/*
slouken@8972
    48
 * Like SDL_SetError but for DX error codes.
slouken@8972
    49
 */
slouken@8972
    50
static int
slouken@8972
    51
DI_SetError(const char *str, HRESULT err)
slouken@8972
    52
{
slouken@8972
    53
    /*
slouken@8972
    54
       SDL_SetError("Haptic: %s - %s: %s", str,
slouken@8972
    55
       DXGetErrorString8A(err), DXGetErrorDescription8A(err));
slouken@8972
    56
     */
slouken@8972
    57
    return SDL_SetError("Haptic error %s", str);
slouken@8972
    58
}
slouken@8972
    59
slouken@8972
    60
/*
slouken@8972
    61
 * Checks to see if two GUID are the same.
slouken@8972
    62
 */
slouken@8972
    63
static int
slouken@8972
    64
DI_GUIDIsSame(const GUID * a, const GUID * b)
slouken@8972
    65
{
slouken@8972
    66
    return (SDL_memcmp(a, b, sizeof (GUID)) == 0);
slouken@8972
    67
}
slouken@8972
    68
slouken@8972
    69
/*
slouken@8972
    70
 * Callback to find the haptic devices.
slouken@8972
    71
 */
slouken@8972
    72
static BOOL CALLBACK
slouken@8972
    73
EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
slouken@8972
    74
{
slouken@8972
    75
    (void) pContext;
slouken@8972
    76
    SDL_DINPUT_MaybeAddDevice(pdidInstance);
slouken@8972
    77
    return DIENUM_CONTINUE;  /* continue enumerating */
slouken@8972
    78
}
slouken@8972
    79
slouken@8972
    80
int
slouken@8972
    81
SDL_DINPUT_HapticInit(void)
slouken@8972
    82
{
slouken@8972
    83
    HRESULT ret;
slouken@8972
    84
    HINSTANCE instance;
slouken@8972
    85
slouken@8972
    86
    if (dinput != NULL) {       /* Already open. */
slouken@8972
    87
        return SDL_SetError("Haptic: SubSystem already open.");
slouken@8972
    88
    }
slouken@8972
    89
slouken@8972
    90
    ret = WIN_CoInitialize();
slouken@8972
    91
    if (FAILED(ret)) {
slouken@8972
    92
        return DI_SetError("Coinitialize", ret);
slouken@8972
    93
    }
slouken@8972
    94
slouken@8972
    95
    coinitialized = SDL_TRUE;
slouken@8972
    96
slouken@8972
    97
    ret = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
slouken@8972
    98
        &IID_IDirectInput8, (LPVOID)& dinput);
slouken@8972
    99
    if (FAILED(ret)) {
slouken@8972
   100
        SDL_SYS_HapticQuit();
slouken@8972
   101
        return DI_SetError("CoCreateInstance", ret);
slouken@8972
   102
    }
slouken@8972
   103
slouken@8972
   104
    /* Because we used CoCreateInstance, we need to Initialize it, first. */
slouken@8972
   105
    instance = GetModuleHandle(NULL);
slouken@8972
   106
    if (instance == NULL) {
slouken@8972
   107
        SDL_SYS_HapticQuit();
slouken@8976
   108
        return SDL_SetError("GetModuleHandle() failed with error code %lu.",
slouken@8972
   109
            GetLastError());
slouken@8972
   110
    }
slouken@8972
   111
    ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
slouken@8972
   112
    if (FAILED(ret)) {
slouken@8972
   113
        SDL_SYS_HapticQuit();
slouken@8972
   114
        return DI_SetError("Initializing DirectInput device", ret);
slouken@8972
   115
    }
slouken@8972
   116
slouken@8972
   117
    /* Look for haptic devices. */
slouken@8972
   118
    ret = IDirectInput8_EnumDevices(dinput,
slouken@8972
   119
        0,
slouken@8972
   120
        EnumHapticsCallback,
slouken@8972
   121
        NULL,
slouken@8972
   122
        DIEDFL_FORCEFEEDBACK |
slouken@8972
   123
        DIEDFL_ATTACHEDONLY);
slouken@8972
   124
    if (FAILED(ret)) {
slouken@8972
   125
        SDL_SYS_HapticQuit();
slouken@8972
   126
        return DI_SetError("Enumerating DirectInput devices", ret);
slouken@8972
   127
    }
slouken@8972
   128
    return 0;
slouken@8972
   129
}
slouken@8972
   130
slouken@8972
   131
int
slouken@8972
   132
SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
slouken@8972
   133
{
slouken@8972
   134
    HRESULT ret;
slouken@8972
   135
    LPDIRECTINPUTDEVICE8 device;
slouken@8972
   136
    const DWORD needflags = DIDC_ATTACHED | DIDC_FORCEFEEDBACK;
slouken@8972
   137
    DIDEVCAPS capabilities;
slouken@8972
   138
    SDL_hapticlist_item *item = NULL;
slouken@8972
   139
slouken@8972
   140
    if (dinput == NULL) {
slouken@8972
   141
        return -1;  /* not initialized. We'll pick these up on enumeration if we init later. */
slouken@8972
   142
    }
slouken@8972
   143
slouken@8972
   144
    /* Make sure we don't already have it */
slouken@8972
   145
    for (item = SDL_hapticlist; item; item = item->next) {
slouken@8972
   146
        if ((!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0)) {
slouken@8972
   147
            return -1;  /* Already added */
slouken@8972
   148
        }
slouken@8972
   149
    }
slouken@8972
   150
slouken@8972
   151
    /* Open the device */
slouken@8972
   152
    ret = IDirectInput8_CreateDevice(dinput, &pdidInstance->guidInstance, &device, NULL);
slouken@8972
   153
    if (FAILED(ret)) {
slouken@8972
   154
        /* DI_SetError("Creating DirectInput device",ret); */
slouken@8972
   155
        return -1;
slouken@8972
   156
    }
slouken@8972
   157
slouken@8972
   158
    /* Get capabilities. */
slouken@8972
   159
    SDL_zero(capabilities);
slouken@8972
   160
    capabilities.dwSize = sizeof(DIDEVCAPS);
slouken@8972
   161
    ret = IDirectInputDevice8_GetCapabilities(device, &capabilities);
slouken@8972
   162
    IDirectInputDevice8_Release(device);
slouken@8972
   163
    if (FAILED(ret)) {
slouken@8972
   164
        /* DI_SetError("Getting device capabilities",ret); */
slouken@8972
   165
        return -1;
slouken@8972
   166
    }
slouken@8972
   167
slouken@8972
   168
    if ((capabilities.dwFlags & needflags) != needflags) {
slouken@8972
   169
        return -1;  /* not a device we can use. */
slouken@8972
   170
    }
slouken@8972
   171
slouken@8972
   172
    item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
slouken@8972
   173
    if (item == NULL) {
slouken@8972
   174
        return SDL_OutOfMemory();
slouken@8972
   175
    }
slouken@8972
   176
slouken@8972
   177
    item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
slouken@8972
   178
    if (!item->name) {
slouken@8972
   179
        SDL_free(item);
slouken@8972
   180
        return -1;
slouken@8972
   181
    }
slouken@8972
   182
slouken@8972
   183
    /* Copy the instance over, useful for creating devices. */
slouken@8972
   184
    SDL_memcpy(&item->instance, pdidInstance, sizeof(DIDEVICEINSTANCE));
slouken@8972
   185
    SDL_memcpy(&item->capabilities, &capabilities, sizeof(capabilities));
slouken@8972
   186
slouken@8972
   187
    return SDL_SYS_AddHapticDevice(item);
slouken@8972
   188
}
slouken@8972
   189
slouken@8972
   190
int
slouken@8972
   191
SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
slouken@8972
   192
{
slouken@8972
   193
    SDL_hapticlist_item *item;
slouken@8972
   194
    SDL_hapticlist_item *prev = NULL;
slouken@8972
   195
slouken@8972
   196
    if (dinput == NULL) {
slouken@8972
   197
        return -1;  /* not initialized, ignore this. */
slouken@8972
   198
    }
slouken@8972
   199
slouken@8972
   200
    for (item = SDL_hapticlist; item != NULL; item = item->next) {
slouken@8972
   201
        if (!item->bXInputHaptic && SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) {
slouken@8972
   202
            /* found it, remove it. */
slouken@8972
   203
            return SDL_SYS_RemoveHapticDevice(prev, item);
slouken@8972
   204
        }
slouken@8972
   205
        prev = item;
slouken@8972
   206
    }
slouken@8972
   207
    return -1;
slouken@8972
   208
}
slouken@8972
   209
slouken@8972
   210
/*
slouken@8972
   211
 * Callback to get supported axes.
slouken@8972
   212
 */
slouken@8972
   213
static BOOL CALLBACK
slouken@8972
   214
DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
slouken@8972
   215
{
slouken@8972
   216
    SDL_Haptic *haptic = (SDL_Haptic *) pvRef;
slouken@8972
   217
slouken@8972
   218
    if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) {
slouken@8972
   219
        const GUID *guid = &dev->guidType;
slouken@8972
   220
        DWORD offset = 0;
slouken@8972
   221
        if (DI_GUIDIsSame(guid, &GUID_XAxis)) {
slouken@8972
   222
            offset = DIJOFS_X;
slouken@8972
   223
        } else if (DI_GUIDIsSame(guid, &GUID_YAxis)) {
slouken@8972
   224
            offset = DIJOFS_Y;
slouken@8972
   225
        } else if (DI_GUIDIsSame(guid, &GUID_ZAxis)) {
slouken@8972
   226
            offset = DIJOFS_Z;
slouken@8972
   227
        } else if (DI_GUIDIsSame(guid, &GUID_RxAxis)) {
slouken@8972
   228
            offset = DIJOFS_RX;
slouken@8972
   229
        } else if (DI_GUIDIsSame(guid, &GUID_RyAxis)) {
slouken@8972
   230
            offset = DIJOFS_RY;
slouken@8972
   231
        } else if (DI_GUIDIsSame(guid, &GUID_RzAxis)) {
slouken@8972
   232
            offset = DIJOFS_RZ;
slouken@8972
   233
        } else {
slouken@8972
   234
            return DIENUM_CONTINUE;   /* can't use this, go on. */
slouken@8972
   235
        }
slouken@8972
   236
slouken@8972
   237
        haptic->hwdata->axes[haptic->naxes] = offset;
slouken@8972
   238
        haptic->naxes++;
slouken@8972
   239
slouken@8972
   240
        /* Currently using the artificial limit of 3 axes. */
slouken@8972
   241
        if (haptic->naxes >= 3) {
slouken@8972
   242
            return DIENUM_STOP;
slouken@8972
   243
        }
slouken@8972
   244
    }
slouken@8972
   245
slouken@8972
   246
    return DIENUM_CONTINUE;
slouken@8972
   247
}
slouken@8972
   248
slouken@8972
   249
/*
slouken@8972
   250
 * Callback to get all supported effects.
slouken@8972
   251
 */
slouken@8972
   252
#define EFFECT_TEST(e,s)               \
slouken@8972
   253
if (DI_GUIDIsSame(&pei->guid, &(e)))   \
slouken@8972
   254
   haptic->supported |= (s)
slouken@8972
   255
static BOOL CALLBACK
slouken@8972
   256
DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
slouken@8972
   257
{
slouken@8972
   258
    /* Prepare the haptic device. */
slouken@8972
   259
    SDL_Haptic *haptic = (SDL_Haptic *) pv;
slouken@8972
   260
slouken@8972
   261
    /* Get supported. */
slouken@8972
   262
    EFFECT_TEST(GUID_Spring, SDL_HAPTIC_SPRING);
slouken@8972
   263
    EFFECT_TEST(GUID_Damper, SDL_HAPTIC_DAMPER);
slouken@8972
   264
    EFFECT_TEST(GUID_Inertia, SDL_HAPTIC_INERTIA);
slouken@8972
   265
    EFFECT_TEST(GUID_Friction, SDL_HAPTIC_FRICTION);
slouken@8972
   266
    EFFECT_TEST(GUID_ConstantForce, SDL_HAPTIC_CONSTANT);
slouken@8972
   267
    EFFECT_TEST(GUID_CustomForce, SDL_HAPTIC_CUSTOM);
slouken@8972
   268
    EFFECT_TEST(GUID_Sine, SDL_HAPTIC_SINE);
slouken@8972
   269
    /* !!! FIXME: put this back when we have more bits in 2.1 */
slouken@8972
   270
    /* EFFECT_TEST(GUID_Square, SDL_HAPTIC_SQUARE); */
slouken@8972
   271
    EFFECT_TEST(GUID_Triangle, SDL_HAPTIC_TRIANGLE);
slouken@8972
   272
    EFFECT_TEST(GUID_SawtoothUp, SDL_HAPTIC_SAWTOOTHUP);
slouken@8972
   273
    EFFECT_TEST(GUID_SawtoothDown, SDL_HAPTIC_SAWTOOTHDOWN);
slouken@8972
   274
    EFFECT_TEST(GUID_RampForce, SDL_HAPTIC_RAMP);
slouken@8972
   275
slouken@8972
   276
    /* Check for more. */
slouken@8972
   277
    return DIENUM_CONTINUE;
slouken@8972
   278
}
slouken@8972
   279
slouken@8972
   280
/*
slouken@8972
   281
 * Opens the haptic device.
slouken@8972
   282
 *
slouken@8972
   283
 *    Steps:
slouken@8972
   284
 *       - Set cooperative level.
slouken@8972
   285
 *       - Set data format.
slouken@8972
   286
 *       - Acquire exclusiveness.
slouken@8972
   287
 *       - Reset actuators.
slouken@8972
   288
 *       - Get supported features.
slouken@8972
   289
 */
slouken@8972
   290
static int
slouken@8972
   291
SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device8, SDL_bool is_joystick)
slouken@8972
   292
{
slouken@8972
   293
    HRESULT ret;
slouken@8972
   294
    DIPROPDWORD dipdw;
slouken@8972
   295
slouken@8972
   296
    /* Allocate the hwdata */
slouken@8972
   297
    haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
slouken@8972
   298
    if (haptic->hwdata == NULL) {
slouken@8972
   299
        return SDL_OutOfMemory();
slouken@8972
   300
    }
slouken@8972
   301
    SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
slouken@8972
   302
slouken@8972
   303
    /* We'll use the device8 from now on. */
slouken@8972
   304
    haptic->hwdata->device = device8;
slouken@8972
   305
    haptic->hwdata->is_joystick = is_joystick;
slouken@8972
   306
slouken@8972
   307
    /* !!! FIXME: opening a haptic device here first will make an attempt to
slouken@8972
   308
       !!! FIXME:  SDL_JoystickOpen() that same device fail later, since we
slouken@8972
   309
       !!! FIXME:  have it open in exclusive mode. But this will allow
slouken@8972
   310
       !!! FIXME:  SDL_JoystickOpen() followed by SDL_HapticOpenFromJoystick()
slouken@8972
   311
       !!! FIXME:  to work, and that's probably the common case. Still,
slouken@8972
   312
       !!! FIXME:  ideally, We need to unify the opening code. */
slouken@8972
   313
slouken@8972
   314
    if (!is_joystick) {  /* if is_joystick, we already set this up elsewhere. */
slouken@8972
   315
        /* Grab it exclusively to use force feedback stuff. */
slouken@8972
   316
        ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
slouken@8972
   317
                                                      SDL_HelperWindow,
slouken@8972
   318
                                                      DISCL_EXCLUSIVE |
slouken@8972
   319
                                                      DISCL_BACKGROUND);
slouken@8972
   320
        if (FAILED(ret)) {
slouken@8972
   321
            DI_SetError("Setting cooperative level to exclusive", ret);
slouken@8972
   322
            goto acquire_err;
slouken@8972
   323
        }
slouken@8972
   324
slouken@8972
   325
        /* Set data format. */
slouken@8972
   326
        ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
slouken@8972
   327
                                                &c_dfDIJoystick2);
slouken@8972
   328
        if (FAILED(ret)) {
slouken@8972
   329
            DI_SetError("Setting data format", ret);
slouken@8972
   330
            goto acquire_err;
slouken@8972
   331
        }
slouken@8972
   332
slouken@8972
   333
        /* Get number of axes. */
slouken@8972
   334
        ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
slouken@8972
   335
                                              DI_DeviceObjectCallback,
slouken@8972
   336
                                              haptic, DIDFT_AXIS);
slouken@8972
   337
        if (FAILED(ret)) {
slouken@8972
   338
            DI_SetError("Getting device axes", ret);
slouken@8972
   339
            goto acquire_err;
slouken@8972
   340
        }
slouken@8972
   341
slouken@8972
   342
        /* Acquire the device. */
slouken@8972
   343
        ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
slouken@8972
   344
        if (FAILED(ret)) {
slouken@8972
   345
            DI_SetError("Acquiring DirectInput device", ret);
slouken@8972
   346
            goto acquire_err;
slouken@8972
   347
        }
slouken@8972
   348
    }
slouken@8972
   349
slouken@8972
   350
    /* Reset all actuators - just in case. */
slouken@8972
   351
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
   352
                                                       DISFFC_RESET);
slouken@8972
   353
    if (FAILED(ret)) {
slouken@8972
   354
        DI_SetError("Resetting device", ret);
slouken@8972
   355
        goto acquire_err;
slouken@8972
   356
    }
slouken@8972
   357
slouken@8972
   358
    /* Enabling actuators. */
slouken@8972
   359
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
   360
                                                       DISFFC_SETACTUATORSON);
slouken@8972
   361
    if (FAILED(ret)) {
slouken@8972
   362
        DI_SetError("Enabling actuators", ret);
slouken@8972
   363
        goto acquire_err;
slouken@8972
   364
    }
slouken@8972
   365
slouken@8972
   366
    /* Get supported effects. */
slouken@8972
   367
    ret = IDirectInputDevice8_EnumEffects(haptic->hwdata->device,
slouken@8972
   368
                                          DI_EffectCallback, haptic,
slouken@8972
   369
                                          DIEFT_ALL);
slouken@8972
   370
    if (FAILED(ret)) {
slouken@8972
   371
        DI_SetError("Enumerating supported effects", ret);
slouken@8972
   372
        goto acquire_err;
slouken@8972
   373
    }
slouken@8972
   374
    if (haptic->supported == 0) {       /* Error since device supports nothing. */
slouken@8972
   375
        SDL_SetError("Haptic: Internal error on finding supported effects.");
slouken@8972
   376
        goto acquire_err;
slouken@8972
   377
    }
slouken@8972
   378
slouken@8972
   379
    /* Check autogain and autocenter. */
slouken@8972
   380
    dipdw.diph.dwSize = sizeof(DIPROPDWORD);
slouken@8972
   381
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
slouken@8972
   382
    dipdw.diph.dwObj = 0;
slouken@8972
   383
    dipdw.diph.dwHow = DIPH_DEVICE;
slouken@8972
   384
    dipdw.dwData = 10000;
slouken@8972
   385
    ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
slouken@8972
   386
                                          DIPROP_FFGAIN, &dipdw.diph);
slouken@8972
   387
    if (!FAILED(ret)) {         /* Gain is supported. */
slouken@8972
   388
        haptic->supported |= SDL_HAPTIC_GAIN;
slouken@8972
   389
    }
slouken@8972
   390
    dipdw.diph.dwObj = 0;
slouken@8972
   391
    dipdw.diph.dwHow = DIPH_DEVICE;
slouken@8972
   392
    dipdw.dwData = DIPROPAUTOCENTER_OFF;
slouken@8972
   393
    ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
slouken@8972
   394
                                          DIPROP_AUTOCENTER, &dipdw.diph);
slouken@8972
   395
    if (!FAILED(ret)) {         /* Autocenter is supported. */
slouken@8972
   396
        haptic->supported |= SDL_HAPTIC_AUTOCENTER;
slouken@8972
   397
    }
slouken@8972
   398
slouken@8972
   399
    /* Status is always supported. */
slouken@8972
   400
    haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
slouken@8972
   401
slouken@8972
   402
    /* Check maximum effects. */
slouken@8972
   403
    haptic->neffects = 128;     /* This is not actually supported as thus under windows,
slouken@8972
   404
                                   there is no way to tell the number of EFFECTS that a
slouken@8972
   405
                                   device can hold, so we'll just use a "random" number
slouken@8972
   406
                                   instead and put warnings in SDL_haptic.h */
slouken@8972
   407
    haptic->nplaying = 128;     /* Even more impossible to get this then neffects. */
slouken@8972
   408
slouken@8972
   409
    /* Prepare effects memory. */
slouken@8972
   410
    haptic->effects = (struct haptic_effect *)
slouken@8972
   411
        SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
slouken@8972
   412
    if (haptic->effects == NULL) {
slouken@8972
   413
        SDL_OutOfMemory();
slouken@8972
   414
        goto acquire_err;
slouken@8972
   415
    }
slouken@8972
   416
    /* Clear the memory */
slouken@8972
   417
    SDL_memset(haptic->effects, 0,
slouken@8972
   418
               sizeof(struct haptic_effect) * haptic->neffects);
slouken@8972
   419
slouken@8972
   420
    return 0;
slouken@8972
   421
slouken@8972
   422
    /* Error handling */
slouken@8972
   423
  acquire_err:
slouken@8972
   424
    IDirectInputDevice8_Unacquire(haptic->hwdata->device);
slouken@8972
   425
    return -1;
slouken@8972
   426
}
slouken@8972
   427
slouken@8972
   428
int
slouken@8972
   429
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
slouken@8972
   430
{
slouken@8972
   431
    HRESULT ret;
slouken@8972
   432
    LPDIRECTINPUTDEVICE8 device;
slouken@8972
   433
    LPDIRECTINPUTDEVICE8 device8;
slouken@8972
   434
slouken@8972
   435
    /* Open the device */
slouken@8972
   436
    ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance,
slouken@8972
   437
        &device, NULL);
slouken@8972
   438
    if (FAILED(ret)) {
slouken@8972
   439
        DI_SetError("Creating DirectInput device", ret);
slouken@8972
   440
        return -1;
slouken@8972
   441
    }
slouken@8972
   442
slouken@8972
   443
    /* Now get the IDirectInputDevice8 interface, instead. */
slouken@8972
   444
    ret = IDirectInputDevice8_QueryInterface(device,
slouken@8972
   445
        &IID_IDirectInputDevice8,
slouken@8972
   446
        (LPVOID *)&device8);
slouken@8972
   447
    /* Done with the temporary one now. */
slouken@8972
   448
    IDirectInputDevice8_Release(device);
slouken@8972
   449
    if (FAILED(ret)) {
slouken@8972
   450
        DI_SetError("Querying DirectInput interface", ret);
slouken@8972
   451
        return -1;
slouken@8972
   452
    }
slouken@8972
   453
slouken@8972
   454
    if (SDL_DINPUT_HapticOpenFromDevice(haptic, device8, SDL_FALSE) < 0) {
slouken@8972
   455
        IDirectInputDevice8_Release(device8);
slouken@8972
   456
        return -1;
slouken@8972
   457
    }
slouken@8972
   458
    return 0;
slouken@8972
   459
}
slouken@8972
   460
slouken@8972
   461
int
slouken@8972
   462
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
slouken@8972
   463
{
slouken@8972
   464
    HRESULT ret;
slouken@8972
   465
    DIDEVICEINSTANCE hap_instance, joy_instance;
slouken@8972
   466
slouken@8972
   467
    hap_instance.dwSize = sizeof(DIDEVICEINSTANCE);
slouken@8972
   468
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
slouken@8972
   469
slouken@8972
   470
    /* Get the device instances. */
slouken@8972
   471
    ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
slouken@8972
   472
        &hap_instance);
slouken@8972
   473
    if (FAILED(ret)) {
slouken@8972
   474
        return 0;
slouken@8972
   475
    }
slouken@8972
   476
    ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
slouken@8972
   477
        &joy_instance);
slouken@8972
   478
    if (FAILED(ret)) {
slouken@8972
   479
        return 0;
slouken@8972
   480
    }
slouken@8972
   481
slouken@8972
   482
    return DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance);
slouken@8972
   483
}
slouken@8972
   484
slouken@8972
   485
int
slouken@8972
   486
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
slouken@8972
   487
{
slouken@8972
   488
    SDL_hapticlist_item *item;
slouken@8972
   489
    int index = 0;
slouken@8972
   490
    HRESULT ret;
slouken@8972
   491
    DIDEVICEINSTANCE joy_instance;
slouken@8972
   492
slouken@8972
   493
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
slouken@8972
   494
    ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance);
slouken@8972
   495
    if (FAILED(ret)) {
slouken@8972
   496
        return -1;
slouken@8972
   497
    }
slouken@8972
   498
slouken@8972
   499
    /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
slouken@8972
   500
    for (item = SDL_hapticlist; item != NULL; item = item->next) {
slouken@8972
   501
        if (!item->bXInputHaptic && DI_GUIDIsSame(&item->instance.guidInstance, &joy_instance.guidInstance)) {
slouken@8972
   502
            haptic->index = index;
slouken@8972
   503
            return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
slouken@8972
   504
        }
slouken@8972
   505
        ++index;
slouken@8972
   506
    }
slouken@8972
   507
slouken@8972
   508
    SDL_SetError("Couldn't find joystick in haptic device list");
slouken@8972
   509
    return -1;
slouken@8972
   510
}
slouken@8972
   511
slouken@8972
   512
void
slouken@8972
   513
SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
slouken@8972
   514
{
slouken@8972
   515
    IDirectInputDevice8_Unacquire(haptic->hwdata->device);
slouken@8972
   516
slouken@8972
   517
    /* Only release if isn't grabbed by a joystick. */
slouken@8972
   518
    if (haptic->hwdata->is_joystick == 0) {
slouken@8972
   519
        IDirectInputDevice8_Release(haptic->hwdata->device);
slouken@8972
   520
    }
slouken@8972
   521
}
slouken@8972
   522
slouken@8972
   523
void
slouken@8972
   524
SDL_DINPUT_HapticQuit(void)
slouken@8972
   525
{
slouken@8972
   526
    if (dinput != NULL) {
slouken@8972
   527
        IDirectInput8_Release(dinput);
slouken@8972
   528
        dinput = NULL;
slouken@8972
   529
    }
slouken@8972
   530
slouken@8972
   531
    if (coinitialized) {
slouken@8972
   532
        WIN_CoUninitialize();
slouken@8972
   533
        coinitialized = SDL_FALSE;
slouken@8972
   534
    }
slouken@8972
   535
}
slouken@8972
   536
slouken@8972
   537
/*
slouken@8972
   538
 * Converts an SDL trigger button to an DIEFFECT trigger button.
slouken@8972
   539
 */
slouken@8972
   540
static DWORD
slouken@8972
   541
DIGetTriggerButton(Uint16 button)
slouken@8972
   542
{
slouken@8972
   543
    DWORD dwTriggerButton;
slouken@8972
   544
slouken@8972
   545
    dwTriggerButton = DIEB_NOTRIGGER;
slouken@8972
   546
slouken@8972
   547
    if (button != 0) {
slouken@8972
   548
        dwTriggerButton = DIJOFS_BUTTON(button - 1);
slouken@8972
   549
    }
slouken@8972
   550
slouken@8972
   551
    return dwTriggerButton;
slouken@8972
   552
}
slouken@8972
   553
slouken@8972
   554
slouken@8972
   555
/*
slouken@8972
   556
 * Sets the direction.
slouken@8972
   557
 */
slouken@8972
   558
static int
slouken@8972
   559
SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
slouken@8972
   560
{
slouken@8972
   561
    LONG *rglDir;
slouken@8972
   562
slouken@8972
   563
    /* Handle no axes a part. */
slouken@8972
   564
    if (naxes == 0) {
slouken@8972
   565
        effect->dwFlags |= DIEFF_SPHERICAL;     /* Set as default. */
slouken@8972
   566
        effect->rglDirection = NULL;
slouken@8972
   567
        return 0;
slouken@8972
   568
    }
slouken@8972
   569
slouken@8972
   570
    /* Has axes. */
slouken@8972
   571
    rglDir = SDL_malloc(sizeof(LONG) * naxes);
slouken@8972
   572
    if (rglDir == NULL) {
slouken@8972
   573
        return SDL_OutOfMemory();
slouken@8972
   574
    }
slouken@8972
   575
    SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
slouken@8972
   576
    effect->rglDirection = rglDir;
slouken@8972
   577
slouken@8972
   578
    switch (dir->type) {
slouken@8972
   579
    case SDL_HAPTIC_POLAR:
slouken@8972
   580
        effect->dwFlags |= DIEFF_POLAR;
slouken@8972
   581
        rglDir[0] = dir->dir[0];
slouken@8972
   582
        return 0;
slouken@8972
   583
    case SDL_HAPTIC_CARTESIAN:
slouken@8972
   584
        effect->dwFlags |= DIEFF_CARTESIAN;
slouken@8972
   585
        rglDir[0] = dir->dir[0];
slouken@8972
   586
        if (naxes > 1)
slouken@8972
   587
            rglDir[1] = dir->dir[1];
slouken@8972
   588
        if (naxes > 2)
slouken@8972
   589
            rglDir[2] = dir->dir[2];
slouken@8972
   590
        return 0;
slouken@8972
   591
    case SDL_HAPTIC_SPHERICAL:
slouken@8972
   592
        effect->dwFlags |= DIEFF_SPHERICAL;
slouken@8972
   593
        rglDir[0] = dir->dir[0];
slouken@8972
   594
        if (naxes > 1)
slouken@8972
   595
            rglDir[1] = dir->dir[1];
slouken@8972
   596
        if (naxes > 2)
slouken@8972
   597
            rglDir[2] = dir->dir[2];
slouken@8972
   598
        return 0;
slouken@8972
   599
slouken@8972
   600
    default:
slouken@8972
   601
        return SDL_SetError("Haptic: Unknown direction type.");
slouken@8972
   602
    }
slouken@8972
   603
}
slouken@8972
   604
slouken@8972
   605
#define CONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
slouken@8972
   606
/*
slouken@8972
   607
 * Creates the DIEFFECT from a SDL_HapticEffect.
slouken@8972
   608
 */
slouken@8972
   609
static int
slouken@8972
   610
SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
slouken@8972
   611
                   SDL_HapticEffect * src)
slouken@8972
   612
{
slouken@8972
   613
    int i;
slouken@8972
   614
    DICONSTANTFORCE *constant;
slouken@8972
   615
    DIPERIODIC *periodic;
slouken@8972
   616
    DICONDITION *condition;     /* Actually an array of conditions - one per axis. */
slouken@8972
   617
    DIRAMPFORCE *ramp;
slouken@8972
   618
    DICUSTOMFORCE *custom;
slouken@8972
   619
    DIENVELOPE *envelope;
slouken@8972
   620
    SDL_HapticConstant *hap_constant;
slouken@8972
   621
    SDL_HapticPeriodic *hap_periodic;
slouken@8972
   622
    SDL_HapticCondition *hap_condition;
slouken@8972
   623
    SDL_HapticRamp *hap_ramp;
slouken@8972
   624
    SDL_HapticCustom *hap_custom;
slouken@8972
   625
    DWORD *axes;
slouken@8972
   626
slouken@8972
   627
    /* Set global stuff. */
slouken@8972
   628
    SDL_memset(dest, 0, sizeof(DIEFFECT));
slouken@8972
   629
    dest->dwSize = sizeof(DIEFFECT);    /* Set the structure size. */
slouken@8972
   630
    dest->dwSamplePeriod = 0;   /* Not used by us. */
slouken@8972
   631
    dest->dwGain = 10000;       /* Gain is set globally, not locally. */
slouken@8972
   632
    dest->dwFlags = DIEFF_OBJECTOFFSETS;        /* Seems obligatory. */
slouken@8972
   633
slouken@8972
   634
    /* Envelope. */
slouken@8972
   635
    envelope = SDL_malloc(sizeof(DIENVELOPE));
slouken@8972
   636
    if (envelope == NULL) {
slouken@8972
   637
        return SDL_OutOfMemory();
slouken@8972
   638
    }
slouken@8972
   639
    SDL_memset(envelope, 0, sizeof(DIENVELOPE));
slouken@8972
   640
    dest->lpEnvelope = envelope;
slouken@8972
   641
    envelope->dwSize = sizeof(DIENVELOPE);      /* Always should be this. */
slouken@8972
   642
slouken@8972
   643
    /* Axes. */
slouken@8972
   644
    dest->cAxes = haptic->naxes;
slouken@8972
   645
    if (dest->cAxes > 0) {
slouken@8972
   646
        axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
slouken@8972
   647
        if (axes == NULL) {
slouken@8972
   648
            return SDL_OutOfMemory();
slouken@8972
   649
        }
slouken@8972
   650
        axes[0] = haptic->hwdata->axes[0];      /* Always at least one axis. */
slouken@8972
   651
        if (dest->cAxes > 1) {
slouken@8972
   652
            axes[1] = haptic->hwdata->axes[1];
slouken@8972
   653
        }
slouken@8972
   654
        if (dest->cAxes > 2) {
slouken@8972
   655
            axes[2] = haptic->hwdata->axes[2];
slouken@8972
   656
        }
slouken@8972
   657
        dest->rgdwAxes = axes;
slouken@8972
   658
    }
slouken@8972
   659
slouken@8972
   660
    /* The big type handling switch, even bigger than Linux's version. */
slouken@8972
   661
    switch (src->type) {
slouken@8972
   662
    case SDL_HAPTIC_CONSTANT:
slouken@8972
   663
        hap_constant = &src->constant;
slouken@8972
   664
        constant = SDL_malloc(sizeof(DICONSTANTFORCE));
slouken@8972
   665
        if (constant == NULL) {
slouken@8972
   666
            return SDL_OutOfMemory();
slouken@8972
   667
        }
slouken@8972
   668
        SDL_memset(constant, 0, sizeof(DICONSTANTFORCE));
slouken@8972
   669
slouken@8972
   670
        /* Specifics */
slouken@8972
   671
        constant->lMagnitude = CONVERT(hap_constant->level);
slouken@8972
   672
        dest->cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
slouken@8972
   673
        dest->lpvTypeSpecificParams = constant;
slouken@8972
   674
slouken@8972
   675
        /* Generics */
slouken@8972
   676
        dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
slouken@8972
   677
        dest->dwTriggerButton = DIGetTriggerButton(hap_constant->button);
slouken@8972
   678
        dest->dwTriggerRepeatInterval = hap_constant->interval;
slouken@8972
   679
        dest->dwStartDelay = hap_constant->delay * 1000;        /* In microseconds. */
slouken@8972
   680
slouken@8972
   681
        /* Direction. */
slouken@8972
   682
        if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
slouken@8972
   683
            return -1;
slouken@8972
   684
        }
slouken@8972
   685
slouken@8972
   686
        /* Envelope */
slouken@8972
   687
        if ((hap_constant->attack_length == 0)
slouken@8972
   688
            && (hap_constant->fade_length == 0)) {
slouken@8972
   689
            SDL_free(dest->lpEnvelope);
slouken@8972
   690
            dest->lpEnvelope = NULL;
slouken@8972
   691
        } else {
slouken@8972
   692
            envelope->dwAttackLevel = CONVERT(hap_constant->attack_level);
slouken@8972
   693
            envelope->dwAttackTime = hap_constant->attack_length * 1000;
slouken@8972
   694
            envelope->dwFadeLevel = CONVERT(hap_constant->fade_level);
slouken@8972
   695
            envelope->dwFadeTime = hap_constant->fade_length * 1000;
slouken@8972
   696
        }
slouken@8972
   697
slouken@8972
   698
        break;
slouken@8972
   699
slouken@8972
   700
    case SDL_HAPTIC_SINE:
slouken@8972
   701
    /* !!! FIXME: put this back when we have more bits in 2.1 */
slouken@8972
   702
    /* case SDL_HAPTIC_SQUARE: */
slouken@8972
   703
    case SDL_HAPTIC_TRIANGLE:
slouken@8972
   704
    case SDL_HAPTIC_SAWTOOTHUP:
slouken@8972
   705
    case SDL_HAPTIC_SAWTOOTHDOWN:
slouken@8972
   706
        hap_periodic = &src->periodic;
slouken@8972
   707
        periodic = SDL_malloc(sizeof(DIPERIODIC));
slouken@8972
   708
        if (periodic == NULL) {
slouken@8972
   709
            return SDL_OutOfMemory();
slouken@8972
   710
        }
slouken@8972
   711
        SDL_memset(periodic, 0, sizeof(DIPERIODIC));
slouken@8972
   712
slouken@8972
   713
        /* Specifics */
slouken@8972
   714
        periodic->dwMagnitude = CONVERT(hap_periodic->magnitude);
slouken@8972
   715
        periodic->lOffset = CONVERT(hap_periodic->offset);
slouken@8972
   716
        periodic->dwPhase = hap_periodic->phase;
slouken@8972
   717
        periodic->dwPeriod = hap_periodic->period * 1000;
slouken@8972
   718
        dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
slouken@8972
   719
        dest->lpvTypeSpecificParams = periodic;
slouken@8972
   720
slouken@8972
   721
        /* Generics */
slouken@8972
   722
        dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
slouken@8972
   723
        dest->dwTriggerButton = DIGetTriggerButton(hap_periodic->button);
slouken@8972
   724
        dest->dwTriggerRepeatInterval = hap_periodic->interval;
slouken@8972
   725
        dest->dwStartDelay = hap_periodic->delay * 1000;        /* In microseconds. */
slouken@8972
   726
slouken@8972
   727
        /* Direction. */
slouken@8972
   728
        if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)
slouken@8972
   729
            < 0) {
slouken@8972
   730
            return -1;
slouken@8972
   731
        }
slouken@8972
   732
slouken@8972
   733
        /* Envelope */
slouken@8972
   734
        if ((hap_periodic->attack_length == 0)
slouken@8972
   735
            && (hap_periodic->fade_length == 0)) {
slouken@8972
   736
            SDL_free(dest->lpEnvelope);
slouken@8972
   737
            dest->lpEnvelope = NULL;
slouken@8972
   738
        } else {
slouken@8972
   739
            envelope->dwAttackLevel = CONVERT(hap_periodic->attack_level);
slouken@8972
   740
            envelope->dwAttackTime = hap_periodic->attack_length * 1000;
slouken@8972
   741
            envelope->dwFadeLevel = CONVERT(hap_periodic->fade_level);
slouken@8972
   742
            envelope->dwFadeTime = hap_periodic->fade_length * 1000;
slouken@8972
   743
        }
slouken@8972
   744
slouken@8972
   745
        break;
slouken@8972
   746
slouken@8972
   747
    case SDL_HAPTIC_SPRING:
slouken@8972
   748
    case SDL_HAPTIC_DAMPER:
slouken@8972
   749
    case SDL_HAPTIC_INERTIA:
slouken@8972
   750
    case SDL_HAPTIC_FRICTION:
slouken@8972
   751
        hap_condition = &src->condition;
slouken@8972
   752
        condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes);
slouken@8972
   753
        if (condition == NULL) {
slouken@8972
   754
            return SDL_OutOfMemory();
slouken@8972
   755
        }
slouken@8972
   756
        SDL_memset(condition, 0, sizeof(DICONDITION));
slouken@8972
   757
slouken@8972
   758
        /* Specifics */
slouken@8972
   759
        for (i = 0; i < (int) dest->cAxes; i++) {
slouken@8972
   760
            condition[i].lOffset = CONVERT(hap_condition->center[i]);
slouken@8972
   761
            condition[i].lPositiveCoefficient =
slouken@8972
   762
                CONVERT(hap_condition->right_coeff[i]);
slouken@8972
   763
            condition[i].lNegativeCoefficient =
slouken@8972
   764
                CONVERT(hap_condition->left_coeff[i]);
slouken@8972
   765
            condition[i].dwPositiveSaturation =
slouken@8972
   766
                CONVERT(hap_condition->right_sat[i]);
slouken@8972
   767
            condition[i].dwNegativeSaturation =
slouken@8972
   768
                CONVERT(hap_condition->left_sat[i]);
slouken@8972
   769
            condition[i].lDeadBand = CONVERT(hap_condition->deadband[i]);
slouken@8972
   770
        }
slouken@8972
   771
        dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes;
slouken@8972
   772
        dest->lpvTypeSpecificParams = condition;
slouken@8972
   773
slouken@8972
   774
        /* Generics */
slouken@8972
   775
        dest->dwDuration = hap_condition->length * 1000;        /* In microseconds. */
slouken@8972
   776
        dest->dwTriggerButton = DIGetTriggerButton(hap_condition->button);
slouken@8972
   777
        dest->dwTriggerRepeatInterval = hap_condition->interval;
slouken@8972
   778
        dest->dwStartDelay = hap_condition->delay * 1000;       /* In microseconds. */
slouken@8972
   779
slouken@8972
   780
        /* Direction. */
slouken@8972
   781
        if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)
slouken@8972
   782
            < 0) {
slouken@8972
   783
            return -1;
slouken@8972
   784
        }
slouken@8972
   785
slouken@8972
   786
        /* Envelope - Not actually supported by most CONDITION implementations. */
slouken@8972
   787
        SDL_free(dest->lpEnvelope);
slouken@8972
   788
        dest->lpEnvelope = NULL;
slouken@8972
   789
slouken@8972
   790
        break;
slouken@8972
   791
slouken@8972
   792
    case SDL_HAPTIC_RAMP:
slouken@8972
   793
        hap_ramp = &src->ramp;
slouken@8972
   794
        ramp = SDL_malloc(sizeof(DIRAMPFORCE));
slouken@8972
   795
        if (ramp == NULL) {
slouken@8972
   796
            return SDL_OutOfMemory();
slouken@8972
   797
        }
slouken@8972
   798
        SDL_memset(ramp, 0, sizeof(DIRAMPFORCE));
slouken@8972
   799
slouken@8972
   800
        /* Specifics */
slouken@8972
   801
        ramp->lStart = CONVERT(hap_ramp->start);
slouken@8972
   802
        ramp->lEnd = CONVERT(hap_ramp->end);
slouken@8972
   803
        dest->cbTypeSpecificParams = sizeof(DIRAMPFORCE);
slouken@8972
   804
        dest->lpvTypeSpecificParams = ramp;
slouken@8972
   805
slouken@8972
   806
        /* Generics */
slouken@8972
   807
        dest->dwDuration = hap_ramp->length * 1000;     /* In microseconds. */
slouken@8972
   808
        dest->dwTriggerButton = DIGetTriggerButton(hap_ramp->button);
slouken@8972
   809
        dest->dwTriggerRepeatInterval = hap_ramp->interval;
slouken@8972
   810
        dest->dwStartDelay = hap_ramp->delay * 1000;    /* In microseconds. */
slouken@8972
   811
slouken@8972
   812
        /* Direction. */
slouken@8972
   813
        if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
slouken@8972
   814
            return -1;
slouken@8972
   815
        }
slouken@8972
   816
slouken@8972
   817
        /* Envelope */
slouken@8972
   818
        if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
slouken@8972
   819
            SDL_free(dest->lpEnvelope);
slouken@8972
   820
            dest->lpEnvelope = NULL;
slouken@8972
   821
        } else {
slouken@8972
   822
            envelope->dwAttackLevel = CONVERT(hap_ramp->attack_level);
slouken@8972
   823
            envelope->dwAttackTime = hap_ramp->attack_length * 1000;
slouken@8972
   824
            envelope->dwFadeLevel = CONVERT(hap_ramp->fade_level);
slouken@8972
   825
            envelope->dwFadeTime = hap_ramp->fade_length * 1000;
slouken@8972
   826
        }
slouken@8972
   827
slouken@8972
   828
        break;
slouken@8972
   829
slouken@8972
   830
    case SDL_HAPTIC_CUSTOM:
slouken@8972
   831
        hap_custom = &src->custom;
slouken@8972
   832
        custom = SDL_malloc(sizeof(DICUSTOMFORCE));
slouken@8972
   833
        if (custom == NULL) {
slouken@8972
   834
            return SDL_OutOfMemory();
slouken@8972
   835
        }
slouken@8972
   836
        SDL_memset(custom, 0, sizeof(DICUSTOMFORCE));
slouken@8972
   837
slouken@8972
   838
        /* Specifics */
slouken@8972
   839
        custom->cChannels = hap_custom->channels;
slouken@8972
   840
        custom->dwSamplePeriod = hap_custom->period * 1000;
slouken@8972
   841
        custom->cSamples = hap_custom->samples;
slouken@8972
   842
        custom->rglForceData =
slouken@8972
   843
            SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
slouken@8972
   844
        for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) {      /* Copy data. */
slouken@8972
   845
            custom->rglForceData[i] = CONVERT(hap_custom->data[i]);
slouken@8972
   846
        }
slouken@8972
   847
        dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
slouken@8972
   848
        dest->lpvTypeSpecificParams = custom;
slouken@8972
   849
slouken@8972
   850
        /* Generics */
slouken@8972
   851
        dest->dwDuration = hap_custom->length * 1000;   /* In microseconds. */
slouken@8972
   852
        dest->dwTriggerButton = DIGetTriggerButton(hap_custom->button);
slouken@8972
   853
        dest->dwTriggerRepeatInterval = hap_custom->interval;
slouken@8972
   854
        dest->dwStartDelay = hap_custom->delay * 1000;  /* In microseconds. */
slouken@8972
   855
slouken@8972
   856
        /* Direction. */
slouken@8972
   857
        if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
slouken@8972
   858
            return -1;
slouken@8972
   859
        }
slouken@8972
   860
slouken@8972
   861
        /* Envelope */
slouken@8972
   862
        if ((hap_custom->attack_length == 0)
slouken@8972
   863
            && (hap_custom->fade_length == 0)) {
slouken@8972
   864
            SDL_free(dest->lpEnvelope);
slouken@8972
   865
            dest->lpEnvelope = NULL;
slouken@8972
   866
        } else {
slouken@8972
   867
            envelope->dwAttackLevel = CONVERT(hap_custom->attack_level);
slouken@8972
   868
            envelope->dwAttackTime = hap_custom->attack_length * 1000;
slouken@8972
   869
            envelope->dwFadeLevel = CONVERT(hap_custom->fade_level);
slouken@8972
   870
            envelope->dwFadeTime = hap_custom->fade_length * 1000;
slouken@8972
   871
        }
slouken@8972
   872
slouken@8972
   873
        break;
slouken@8972
   874
slouken@8972
   875
    default:
slouken@8972
   876
        return SDL_SetError("Haptic: Unknown effect type.");
slouken@8972
   877
    }
slouken@8972
   878
slouken@8972
   879
    return 0;
slouken@8972
   880
}
slouken@8972
   881
slouken@8972
   882
slouken@8972
   883
/*
slouken@8972
   884
 * Frees an DIEFFECT allocated by SDL_SYS_ToDIEFFECT.
slouken@8972
   885
 */
slouken@8972
   886
static void
slouken@8972
   887
SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
slouken@8972
   888
{
slouken@8972
   889
    DICUSTOMFORCE *custom;
slouken@8972
   890
slouken@8972
   891
    SDL_free(effect->lpEnvelope);
slouken@8972
   892
    effect->lpEnvelope = NULL;
slouken@8972
   893
    SDL_free(effect->rgdwAxes);
slouken@8972
   894
    effect->rgdwAxes = NULL;
slouken@8972
   895
    if (effect->lpvTypeSpecificParams != NULL) {
slouken@8972
   896
        if (type == SDL_HAPTIC_CUSTOM) {        /* Must free the custom data. */
slouken@8972
   897
            custom = (DICUSTOMFORCE *) effect->lpvTypeSpecificParams;
slouken@8972
   898
            SDL_free(custom->rglForceData);
slouken@8972
   899
            custom->rglForceData = NULL;
slouken@8972
   900
        }
slouken@8972
   901
        SDL_free(effect->lpvTypeSpecificParams);
slouken@8972
   902
        effect->lpvTypeSpecificParams = NULL;
slouken@8972
   903
    }
slouken@8972
   904
    SDL_free(effect->rglDirection);
slouken@8972
   905
    effect->rglDirection = NULL;
slouken@8972
   906
}
slouken@8972
   907
slouken@8972
   908
/*
slouken@8972
   909
 * Gets the effect type from the generic SDL haptic effect wrapper.
slouken@8972
   910
 */
slouken@8972
   911
static REFGUID
slouken@8972
   912
SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
slouken@8972
   913
{
slouken@8972
   914
    switch (effect->type) {
slouken@8972
   915
    case SDL_HAPTIC_CONSTANT:
slouken@8972
   916
        return &GUID_ConstantForce;
slouken@8972
   917
slouken@8972
   918
    case SDL_HAPTIC_RAMP:
slouken@8972
   919
        return &GUID_RampForce;
slouken@8972
   920
slouken@8972
   921
    /* !!! FIXME: put this back when we have more bits in 2.1 */
slouken@8972
   922
    /* case SDL_HAPTIC_SQUARE:
slouken@8972
   923
        return &GUID_Square; */
slouken@8972
   924
slouken@8972
   925
    case SDL_HAPTIC_SINE:
slouken@8972
   926
        return &GUID_Sine;
slouken@8972
   927
slouken@8972
   928
    case SDL_HAPTIC_TRIANGLE:
slouken@8972
   929
        return &GUID_Triangle;
slouken@8972
   930
slouken@8972
   931
    case SDL_HAPTIC_SAWTOOTHUP:
slouken@8972
   932
        return &GUID_SawtoothUp;
slouken@8972
   933
slouken@8972
   934
    case SDL_HAPTIC_SAWTOOTHDOWN:
slouken@8972
   935
        return &GUID_SawtoothDown;
slouken@8972
   936
slouken@8972
   937
    case SDL_HAPTIC_SPRING:
slouken@8972
   938
        return &GUID_Spring;
slouken@8972
   939
slouken@8972
   940
    case SDL_HAPTIC_DAMPER:
slouken@8972
   941
        return &GUID_Damper;
slouken@8972
   942
slouken@8972
   943
    case SDL_HAPTIC_INERTIA:
slouken@8972
   944
        return &GUID_Inertia;
slouken@8972
   945
slouken@8972
   946
    case SDL_HAPTIC_FRICTION:
slouken@8972
   947
        return &GUID_Friction;
slouken@8972
   948
slouken@8972
   949
    case SDL_HAPTIC_CUSTOM:
slouken@8972
   950
        return &GUID_CustomForce;
slouken@8972
   951
slouken@8972
   952
    default:
slouken@8972
   953
        return NULL;
slouken@8972
   954
    }
slouken@8972
   955
}
slouken@8972
   956
int
slouken@8972
   957
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
slouken@8972
   958
{
slouken@8972
   959
    HRESULT ret;
slouken@8972
   960
    REFGUID type = SDL_SYS_HapticEffectType(base);
slouken@8972
   961
slouken@8972
   962
    if (type == NULL) {
slouken@8972
   963
        SDL_SetError("Haptic: Unknown effect type.");
slouken@8972
   964
        return -1;
slouken@8972
   965
    }
slouken@8972
   966
slouken@8972
   967
    /* Get the effect. */
slouken@8972
   968
    if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
slouken@8972
   969
        goto err_effectdone;
slouken@8972
   970
    }
slouken@8972
   971
slouken@8972
   972
    /* Create the actual effect. */
slouken@8972
   973
    ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
slouken@8972
   974
        &effect->hweffect->effect,
slouken@8972
   975
        &effect->hweffect->ref, NULL);
slouken@8972
   976
    if (FAILED(ret)) {
slouken@8972
   977
        DI_SetError("Unable to create effect", ret);
slouken@8972
   978
        goto err_effectdone;
slouken@8972
   979
    }
slouken@8972
   980
slouken@8972
   981
    return 0;
slouken@8972
   982
slouken@8972
   983
err_effectdone:
slouken@8972
   984
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type);
slouken@8972
   985
    return -1;
slouken@8972
   986
}
slouken@8972
   987
slouken@8972
   988
int
slouken@8972
   989
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
slouken@8972
   990
{
slouken@8972
   991
    HRESULT ret;
slouken@8972
   992
    DWORD flags;
slouken@8972
   993
    DIEFFECT temp;
slouken@8972
   994
slouken@8972
   995
    /* Get the effect. */
slouken@8972
   996
    SDL_memset(&temp, 0, sizeof(DIEFFECT));
slouken@8972
   997
    if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) {
slouken@8972
   998
        goto err_update;
slouken@8972
   999
    }
slouken@8972
  1000
slouken@8972
  1001
    /* Set the flags.  Might be worthwhile to diff temp with loaded effect and
slouken@8972
  1002
    *  only change those parameters. */
slouken@8972
  1003
    flags = DIEP_DIRECTION |
slouken@8972
  1004
        DIEP_DURATION |
slouken@8972
  1005
        DIEP_ENVELOPE |
slouken@8972
  1006
        DIEP_STARTDELAY |
slouken@8972
  1007
        DIEP_TRIGGERBUTTON |
slouken@8972
  1008
        DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
slouken@8972
  1009
slouken@8972
  1010
    /* Create the actual effect. */
slouken@8972
  1011
    ret =
slouken@8972
  1012
        IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
slouken@8972
  1013
    if (FAILED(ret)) {
slouken@8972
  1014
        DI_SetError("Unable to update effect", ret);
slouken@8972
  1015
        goto err_update;
slouken@8972
  1016
    }
slouken@8972
  1017
slouken@8972
  1018
    /* Copy it over. */
slouken@8972
  1019
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type);
slouken@8972
  1020
    SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT));
slouken@8972
  1021
slouken@8972
  1022
    return 0;
slouken@8972
  1023
slouken@8972
  1024
err_update:
slouken@8972
  1025
    SDL_SYS_HapticFreeDIEFFECT(&temp, data->type);
slouken@8972
  1026
    return -1;
slouken@8972
  1027
}
slouken@8972
  1028
slouken@8972
  1029
int
slouken@8972
  1030
SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
slouken@8972
  1031
{
slouken@8972
  1032
    HRESULT ret;
slouken@8972
  1033
    DWORD iter;
slouken@8972
  1034
slouken@8972
  1035
    /* Check if it's infinite. */
slouken@8972
  1036
    if (iterations == SDL_HAPTIC_INFINITY) {
slouken@8972
  1037
        iter = INFINITE;
slouken@8972
  1038
    } else {
slouken@8972
  1039
        iter = iterations;
slouken@8972
  1040
    }
slouken@8972
  1041
slouken@8972
  1042
    /* Run the effect. */
slouken@8972
  1043
    ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0);
slouken@8972
  1044
    if (FAILED(ret)) {
slouken@8972
  1045
        return DI_SetError("Running the effect", ret);
slouken@8972
  1046
    }
slouken@8972
  1047
    return 0;
slouken@8972
  1048
}
slouken@8972
  1049
slouken@8972
  1050
int
slouken@8972
  1051
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1052
{
slouken@8972
  1053
    HRESULT ret;
slouken@8972
  1054
slouken@8972
  1055
    ret = IDirectInputEffect_Stop(effect->hweffect->ref);
slouken@8972
  1056
    if (FAILED(ret)) {
slouken@8972
  1057
        return DI_SetError("Unable to stop effect", ret);
slouken@8972
  1058
    }
slouken@8972
  1059
    return 0;
slouken@8972
  1060
}
slouken@8972
  1061
slouken@8972
  1062
void
slouken@8972
  1063
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1064
{
slouken@8972
  1065
    HRESULT ret;
slouken@8972
  1066
slouken@8972
  1067
    ret = IDirectInputEffect_Unload(effect->hweffect->ref);
slouken@8972
  1068
    if (FAILED(ret)) {
slouken@8972
  1069
        DI_SetError("Removing effect from the device", ret);
slouken@8972
  1070
    }
slouken@8972
  1071
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, effect->effect.type);
slouken@8972
  1072
}
slouken@8972
  1073
slouken@8972
  1074
int
slouken@8972
  1075
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1076
{
slouken@8972
  1077
    HRESULT ret;
slouken@8972
  1078
    DWORD status;
slouken@8972
  1079
slouken@8972
  1080
    ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status);
slouken@8972
  1081
    if (FAILED(ret)) {
slouken@8972
  1082
        return DI_SetError("Getting effect status", ret);
slouken@8972
  1083
    }
slouken@8972
  1084
slouken@8972
  1085
    if (status == 0)
slouken@8972
  1086
        return SDL_FALSE;
slouken@8972
  1087
    return SDL_TRUE;
slouken@8972
  1088
}
slouken@8972
  1089
slouken@8972
  1090
int
slouken@8972
  1091
SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
slouken@8972
  1092
{
slouken@8972
  1093
    HRESULT ret;
slouken@8972
  1094
    DIPROPDWORD dipdw;
slouken@8972
  1095
slouken@8972
  1096
    /* Create the weird structure thingy. */
slouken@8972
  1097
    dipdw.diph.dwSize = sizeof(DIPROPDWORD);
slouken@8972
  1098
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
slouken@8972
  1099
    dipdw.diph.dwObj = 0;
slouken@8972
  1100
    dipdw.diph.dwHow = DIPH_DEVICE;
slouken@8972
  1101
    dipdw.dwData = gain * 100;  /* 0 to 10,000 */
slouken@8972
  1102
slouken@8972
  1103
    /* Try to set the autocenter. */
slouken@8972
  1104
    ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
slouken@8972
  1105
        DIPROP_FFGAIN, &dipdw.diph);
slouken@8972
  1106
    if (FAILED(ret)) {
slouken@8972
  1107
        return DI_SetError("Setting gain", ret);
slouken@8972
  1108
    }
slouken@8972
  1109
    return 0;
slouken@8972
  1110
}
slouken@8972
  1111
slouken@8972
  1112
int
slouken@8972
  1113
SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
slouken@8972
  1114
{
slouken@8972
  1115
    HRESULT ret;
slouken@8972
  1116
    DIPROPDWORD dipdw;
slouken@8972
  1117
slouken@8972
  1118
    /* Create the weird structure thingy. */
slouken@8972
  1119
    dipdw.diph.dwSize = sizeof(DIPROPDWORD);
slouken@8972
  1120
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
slouken@8972
  1121
    dipdw.diph.dwObj = 0;
slouken@8972
  1122
    dipdw.diph.dwHow = DIPH_DEVICE;
slouken@8972
  1123
    dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF :
slouken@8972
  1124
        DIPROPAUTOCENTER_ON;
slouken@8972
  1125
slouken@8972
  1126
    /* Try to set the autocenter. */
slouken@8972
  1127
    ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
slouken@8972
  1128
        DIPROP_AUTOCENTER, &dipdw.diph);
slouken@8972
  1129
    if (FAILED(ret)) {
slouken@8972
  1130
        return DI_SetError("Setting autocenter", ret);
slouken@8972
  1131
    }
slouken@8972
  1132
    return 0;
slouken@8972
  1133
}
slouken@8972
  1134
slouken@8972
  1135
int
slouken@8972
  1136
SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
slouken@8972
  1137
{
slouken@8972
  1138
    HRESULT ret;
slouken@8972
  1139
slouken@8972
  1140
    /* Pause the device. */
slouken@8972
  1141
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
  1142
        DISFFC_PAUSE);
slouken@8972
  1143
    if (FAILED(ret)) {
slouken@8972
  1144
        return DI_SetError("Pausing the device", ret);
slouken@8972
  1145
    }
slouken@8972
  1146
    return 0;
slouken@8972
  1147
}
slouken@8972
  1148
slouken@8972
  1149
int
slouken@8972
  1150
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
slouken@8972
  1151
{
slouken@8972
  1152
    HRESULT ret;
slouken@8972
  1153
slouken@8972
  1154
    /* Unpause the device. */
slouken@8972
  1155
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
  1156
        DISFFC_CONTINUE);
slouken@8972
  1157
    if (FAILED(ret)) {
slouken@8972
  1158
        return DI_SetError("Pausing the device", ret);
slouken@8972
  1159
    }
slouken@8972
  1160
    return 0;
slouken@8972
  1161
}
slouken@8972
  1162
slouken@8972
  1163
int
slouken@8972
  1164
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
slouken@8972
  1165
{
slouken@8972
  1166
    HRESULT ret;
slouken@8972
  1167
slouken@8972
  1168
    /* Try to stop the effects. */
slouken@8972
  1169
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
  1170
        DISFFC_STOPALL);
slouken@8972
  1171
    if (FAILED(ret)) {
slouken@8972
  1172
        return DI_SetError("Stopping the device", ret);
slouken@8972
  1173
    }
slouken@8972
  1174
    return 0;
slouken@8972
  1175
}
slouken@8972
  1176
slouken@8972
  1177
#else /* !SDL_HAPTIC_DINPUT */
slouken@8972
  1178
slouken@8972
  1179
slouken@8972
  1180
int
slouken@8972
  1181
SDL_DINPUT_HapticInit(void)
slouken@8972
  1182
{
slouken@8972
  1183
    return 0;
slouken@8972
  1184
}
slouken@8972
  1185
slouken@8972
  1186
int
slouken@8972
  1187
SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
slouken@8972
  1188
{
slouken@8972
  1189
    return SDL_Unsupported();
slouken@8972
  1190
}
slouken@8972
  1191
slouken@8972
  1192
int
slouken@8972
  1193
SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
slouken@8972
  1194
{
slouken@8972
  1195
    return SDL_Unsupported();
slouken@8972
  1196
}
slouken@8972
  1197
slouken@8972
  1198
int
slouken@8972
  1199
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
slouken@8972
  1200
{
slouken@8972
  1201
    return SDL_Unsupported();
slouken@8972
  1202
}
slouken@8972
  1203
slouken@8972
  1204
int
slouken@8972
  1205
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
slouken@8972
  1206
{
slouken@8972
  1207
    return SDL_Unsupported();
slouken@8972
  1208
}
slouken@8972
  1209
slouken@8972
  1210
int
slouken@8972
  1211
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
slouken@8972
  1212
{
slouken@8972
  1213
    return SDL_Unsupported();
slouken@8972
  1214
}
slouken@8972
  1215
slouken@8972
  1216
void
slouken@8972
  1217
SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
slouken@8972
  1218
{
slouken@8972
  1219
}
slouken@8972
  1220
slouken@8972
  1221
void
slouken@8972
  1222
SDL_DINPUT_HapticQuit(void)
slouken@8972
  1223
{
slouken@8972
  1224
}
slouken@8972
  1225
slouken@8972
  1226
int
slouken@8972
  1227
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
slouken@8972
  1228
{
slouken@8972
  1229
    return SDL_Unsupported();
slouken@8972
  1230
}
slouken@8972
  1231
slouken@8972
  1232
int
slouken@8972
  1233
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
slouken@8972
  1234
{
slouken@8972
  1235
    return SDL_Unsupported();
slouken@8972
  1236
}
slouken@8972
  1237
slouken@8972
  1238
int
slouken@8972
  1239
SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
slouken@8972
  1240
{
slouken@8972
  1241
    return SDL_Unsupported();
slouken@8972
  1242
}
slouken@8972
  1243
slouken@8972
  1244
int
slouken@8972
  1245
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1246
{
slouken@8972
  1247
    return SDL_Unsupported();
slouken@8972
  1248
}
slouken@8972
  1249
slouken@8972
  1250
void
slouken@8972
  1251
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1252
{
slouken@8972
  1253
}
slouken@8972
  1254
slouken@8972
  1255
int
slouken@8972
  1256
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1257
{
slouken@8972
  1258
    return SDL_Unsupported();
slouken@8972
  1259
}
slouken@8972
  1260
slouken@8972
  1261
int
slouken@8972
  1262
SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
slouken@8972
  1263
{
slouken@8972
  1264
    return SDL_Unsupported();
slouken@8972
  1265
}
slouken@8972
  1266
slouken@8972
  1267
int
slouken@8972
  1268
SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
slouken@8972
  1269
{
slouken@8972
  1270
    return SDL_Unsupported();
slouken@8972
  1271
}
slouken@8972
  1272
slouken@8972
  1273
int
slouken@8972
  1274
SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
slouken@8972
  1275
{
slouken@8972
  1276
    return SDL_Unsupported();
slouken@8972
  1277
}
slouken@8972
  1278
slouken@8972
  1279
int
slouken@8972
  1280
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
slouken@8972
  1281
{
slouken@8972
  1282
    return SDL_Unsupported();
slouken@8972
  1283
}
slouken@8972
  1284
slouken@8972
  1285
int
slouken@8972
  1286
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
slouken@8972
  1287
{
slouken@8972
  1288
    return SDL_Unsupported();
slouken@8972
  1289
}
slouken@8972
  1290
slouken@8972
  1291
#endif /* SDL_HAPTIC_DINPUT */
slouken@8972
  1292
slouken@8972
  1293
/* vi: set ts=4 sw=4 expandtab: */