src/haptic/darwin/SDL_syshaptic.c
author Edgar Simo <bobbens@gmail.com>
Sun, 24 Aug 2008 17:17:45 +0000
branchgsoc2008_force_feedback
changeset 2645 269ba4f28d0e
parent 2642 b04679da6627
child 2646 9408be170bff
permissions -rw-r--r--
Added support for pausing/unpausing haptic devices.
bobbens@2520
     1
/*
bobbens@2520
     2
    SDL - Simple DirectMedia Layer
bobbens@2520
     3
    Copyright (C) 2008 Edgar Simo
bobbens@2520
     4
bobbens@2520
     5
    This library is free software; you can redistribute it and/or
bobbens@2520
     6
    modify it under the terms of the GNU Lesser General Public
bobbens@2520
     7
    License as published by the Free Software Foundation; either
bobbens@2520
     8
    version 2.1 of the License, or (at your option) any later version.
bobbens@2520
     9
bobbens@2520
    10
    This library is distributed in the hope that it will be useful,
bobbens@2520
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
bobbens@2520
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bobbens@2520
    13
    Lesser General Public License for more details.
bobbens@2520
    14
bobbens@2520
    15
    You should have received a copy of the GNU Lesser General Public
bobbens@2520
    16
    License along with this library; if not, write to the Free Software
bobbens@2520
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
bobbens@2520
    18
bobbens@2520
    19
    Sam Lantinga
bobbens@2520
    20
    slouken@libsdl.org
bobbens@2520
    21
*/
bobbens@2520
    22
#include "SDL_config.h"
bobbens@2520
    23
bobbens@2520
    24
#ifdef SDL_HAPTIC_IOKIT
bobbens@2520
    25
bobbens@2520
    26
#include "SDL_haptic.h"
bobbens@2520
    27
#include "../SDL_syshaptic.h"
bobbens@2520
    28
#include "SDL_joystick.h"
bobbens@2520
    29
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
bobbens@2633
    30
#include "../../joystick/darwin/SDL_sysjoystick_c.h" /* For joystick hwdata */ 
bobbens@2520
    31
bobbens@2522
    32
#include <IOKit/IOKitLib.h>
bobbens@2522
    33
#include <IOKit/hid/IOHIDKeys.h>
bobbens@2520
    34
#include <ForceFeedback/ForceFeedback.h>
bobbens@2520
    35
#include <ForceFeedback/ForceFeedbackConstants.h>
bobbens@2520
    36
bobbens@2520
    37
bobbens@2520
    38
#define MAX_HAPTICS  32
bobbens@2520
    39
bobbens@2520
    40
bobbens@2520
    41
/*
bobbens@2520
    42
 * List of available haptic devices.
bobbens@2520
    43
 */
bobbens@2520
    44
static struct
bobbens@2520
    45
{
bobbens@2641
    46
   char name[256]; /* Name of the device. */
bobbens@2641
    47
bobbens@2641
    48
   io_service_t dev; /* Node we use to create the device. */
bobbens@2641
    49
   SDL_Haptic *haptic; /* Haptic currently assosciated with it. */
bobbens@2641
    50
   
bobbens@2641
    51
   /* Usage pages for determining if it's a mouse or not. */
bobbens@2641
    52
   long usage;
bobbens@2641
    53
   long usagePage;
bobbens@2520
    54
} SDL_hapticlist[MAX_HAPTICS];
bobbens@2520
    55
bobbens@2520
    56
bobbens@2520
    57
/*
bobbens@2520
    58
 * Haptic system hardware data.
bobbens@2520
    59
 */
bobbens@2520
    60
struct haptic_hwdata
bobbens@2520
    61
{
bobbens@2520
    62
   FFDeviceObjectReference device; /* Hardware device. */
bobbens@2627
    63
   UInt8 axes[3];
bobbens@2520
    64
};
bobbens@2520
    65
bobbens@2520
    66
bobbens@2520
    67
/*
bobbens@2520
    68
 * Haptic system effect data.
bobbens@2520
    69
 */
bobbens@2520
    70
struct haptic_hweffect
bobbens@2520
    71
{
bobbens@2520
    72
   FFEffectObjectReference ref; /* Reference. */
bobbens@2520
    73
   struct FFEFFECT effect; /* Hardware effect. */
bobbens@2520
    74
};
bobbens@2520
    75
bobbens@2531
    76
/*
bobbens@2531
    77
 * Prototypes.
bobbens@2531
    78
 */
bobbens@2537
    79
static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type);
bobbens@2537
    80
static int HIDGetDeviceProduct(io_service_t dev, char * name);
bobbens@2531
    81
bobbens@2520
    82
bobbens@2541
    83
/* 
bobbens@2541
    84
 * Like strerror but for force feedback errors.
bobbens@2541
    85
 */
bobbens@2541
    86
static const char *
bobbens@2541
    87
FFStrError(HRESULT err)
bobbens@2541
    88
{
bobbens@2541
    89
   switch (err) {
bobbens@2541
    90
      case FFERR_DEVICEFULL:
bobbens@2541
    91
         return "device full";
bobbens@2608
    92
      /* This should be valid, but for some reason isn't defined... */
bobbens@2543
    93
      /*case FFERR_DEVICENOTREG:
bobbens@2543
    94
         return "device not registered";*/
bobbens@2541
    95
      case FFERR_DEVICEPAUSED:
bobbens@2541
    96
         return "device paused";
bobbens@2541
    97
      case FFERR_DEVICERELEASED:
bobbens@2541
    98
         return "device released";
bobbens@2541
    99
      case FFERR_EFFECTPLAYING:
bobbens@2541
   100
         return "effect playing";
bobbens@2541
   101
      case FFERR_EFFECTTYPEMISMATCH:
bobbens@2541
   102
         return "effect type mismatch";
bobbens@2541
   103
      case FFERR_EFFECTTYPENOTSUPPORTED:
bobbens@2541
   104
         return "effect type not supported";
bobbens@2541
   105
      case FFERR_GENERIC:
bobbens@2541
   106
         return "undetermined error";
bobbens@2541
   107
      case FFERR_HASEFFECTS:
bobbens@2541
   108
         return "device has effects";
bobbens@2541
   109
      case FFERR_INCOMPLETEEFFECT:
bobbens@2541
   110
         return "incomplete effect";
bobbens@2541
   111
      case FFERR_INTERNAL:
bobbens@2541
   112
         return "internal fault";
bobbens@2541
   113
      case FFERR_INVALIDDOWNLOADID:
bobbens@2541
   114
         return "invalid download id";
bobbens@2541
   115
      case FFERR_INVALIDPARAM:
bobbens@2541
   116
         return "invalid parameter";
bobbens@2541
   117
      case FFERR_MOREDATA:
bobbens@2541
   118
         return "more data";
bobbens@2541
   119
      case FFERR_NOINTERFACE:
bobbens@2541
   120
         return "interface not supported";
bobbens@2541
   121
      case FFERR_NOTDOWNLOADED:
bobbens@2541
   122
         return "effect is not downloaded";
bobbens@2541
   123
      case FFERR_NOTINITIALIZED:
bobbens@2541
   124
         return "object has not been initialized";
bobbens@2541
   125
      case FFERR_OUTOFMEMORY:
bobbens@2541
   126
         return "out of memory";
bobbens@2541
   127
      case FFERR_UNPLUGGED:
bobbens@2541
   128
         return "device is unplugged";
bobbens@2541
   129
      case FFERR_UNSUPPORTED:
bobbens@2541
   130
         return "function call unsupported";
bobbens@2541
   131
      case FFERR_UNSUPPORTEDAXIS:
bobbens@2541
   132
         return "axis unsupported";
bobbens@2541
   133
bobbens@2541
   134
      default:
bobbens@2541
   135
         return "unknown error";
bobbens@2541
   136
   }
bobbens@2541
   137
}
bobbens@2541
   138
bobbens@2541
   139
bobbens@2520
   140
/*
bobbens@2520
   141
 * Initializes the haptic subsystem.
bobbens@2520
   142
 */
bobbens@2520
   143
int
bobbens@2520
   144
SDL_SYS_HapticInit(void)
bobbens@2520
   145
{
bobbens@2520
   146
   int numhaptics;
bobbens@2520
   147
   IOReturn result;
bobbens@2520
   148
   io_iterator_t iter;
bobbens@2520
   149
   CFDictionaryRef match;
bobbens@2521
   150
   io_service_t device;
bobbens@2641
   151
   CFMutableDictionaryRef hidProperties;
bobbens@2641
   152
   CFTypeRef refCF;
bobbens@2520
   153
bobbens@2537
   154
   /* Clear all the memory. */
bobbens@2537
   155
   SDL_memset(SDL_hapticlist, 0, sizeof(SDL_hapticlist));
bobbens@2537
   156
bobbens@2520
   157
   /* Get HID devices. */
bobbens@2520
   158
   match = IOServiceMatching(kIOHIDDeviceKey);
bobbens@2520
   159
   if (match == NULL) {
bobbens@2520
   160
      SDL_SetError("Haptic: Failed to get IOServiceMatching.");
bobbens@2520
   161
      return -1;
bobbens@2520
   162
   }
bobbens@2520
   163
bobbens@2520
   164
   /* Now search I/O Registry for matching devices. */
bobbens@2520
   165
   result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
bobbens@2520
   166
   if (result != kIOReturnSuccess) {
bobbens@2520
   167
      SDL_SetError("Haptic: Couldn't create a HID object iterator.");
bobbens@2520
   168
      return -1;
bobbens@2520
   169
   }
bobbens@2520
   170
   /* IOServiceGetMatchingServices consumes dictionary. */
bobbens@2520
   171
bobbens@2641
   172
   if (!IOIteratorIsValid(iter)) { /* No iterator. */
bobbens@2639
   173
      numhaptics = 0;
bobbens@2639
   174
      return 0;
bobbens@2639
   175
   }
bobbens@2639
   176
bobbens@2520
   177
   numhaptics = 0;
bobbens@2520
   178
   while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) {
bobbens@2520
   179
bobbens@2520
   180
      /* Check for force feedback. */
bobbens@2520
   181
      if (FFIsForceFeedback(device) == FF_OK) {
bobbens@2641
   182
bobbens@2641
   183
         /* Set basic device data. */
bobbens@2537
   184
         HIDGetDeviceProduct(device, SDL_hapticlist[numhaptics].name);
bobbens@2520
   185
         SDL_hapticlist[numhaptics].dev = device;
bobbens@2520
   186
         SDL_hapticlist[numhaptics].haptic = NULL;
bobbens@2641
   187
bobbens@2641
   188
         /* Set usage pages. */
bobbens@2641
   189
         hidProperties = 0;
bobbens@2641
   190
         refCF = 0;
bobbens@2641
   191
         result = IORegistryEntryCreateCFProperties(device,
bobbens@2641
   192
               &hidProperties, kCFAllocatorDefault, kNilOptions);
bobbens@2641
   193
         if ((result == KERN_SUCCESS) && hidProperties) {
bobbens@2641
   194
            refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey));
bobbens@2641
   195
            if (refCF) {
bobbens@2641
   196
               if (!CFNumberGetValue(refCF, kCFNumberLongType,
bobbens@2641
   197
                     &SDL_hapticlist[numhaptics].usagePage))
bobbens@2642
   198
                  SDL_SetError("Haptic: Recieving device's usage page.");
bobbens@2641
   199
               refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey));
bobbens@2641
   200
               if (refCF) {
bobbens@2641
   201
                  if (!CFNumberGetValue(refCF, kCFNumberLongType,
bobbens@2641
   202
                        &SDL_hapticlist[numhaptics].usage))
bobbens@2642
   203
                     SDL_SetError("Haptic: Recieving device's usage.");
bobbens@2641
   204
               }
bobbens@2641
   205
            }
bobbens@2641
   206
            CFRelease(hidProperties);
bobbens@2641
   207
         }
bobbens@2641
   208
bobbens@2641
   209
         /* Device has been added. */
bobbens@2520
   210
         numhaptics++;
bobbens@2520
   211
      }
bobbens@2537
   212
      else { /* Free the unused device. */
bobbens@2537
   213
         IOObjectRelease(device);
bobbens@2537
   214
      }
bobbens@2520
   215
bobbens@2520
   216
      /* Reached haptic limit. */
bobbens@2520
   217
      if (numhaptics >= MAX_HAPTICS)
bobbens@2520
   218
         break;
bobbens@2520
   219
   }
bobbens@2520
   220
   IOObjectRelease(iter);
bobbens@2520
   221
bobbens@2520
   222
   return numhaptics;
bobbens@2520
   223
}
bobbens@2520
   224
bobbens@2520
   225
bobbens@2520
   226
/*
bobbens@2520
   227
 * Return the name of a haptic device, does not need to be opened.
bobbens@2520
   228
 */
bobbens@2520
   229
const char *
bobbens@2520
   230
SDL_SYS_HapticName(int index)
bobbens@2520
   231
{
bobbens@2537
   232
   return SDL_hapticlist[index].name;
bobbens@2537
   233
}
bobbens@2537
   234
bobbens@2537
   235
/*
bobbens@2537
   236
 * Gets the device's product name.
bobbens@2537
   237
 */
bobbens@2537
   238
static int
bobbens@2537
   239
HIDGetDeviceProduct(io_service_t dev, char *name)
bobbens@2537
   240
{
bobbens@2537
   241
   CFMutableDictionaryRef hidProperties, usbProperties;
bobbens@2537
   242
   io_registry_entry_t parent1, parent2;
bobbens@2546
   243
   kern_return_t ret;
bobbens@2537
   244
bobbens@2537
   245
   hidProperties = usbProperties = 0;
bobbens@2537
   246
bobbens@2547
   247
   ret = IORegistryEntryCreateCFProperties(dev, &hidProperties,
bobbens@2546
   248
                                           kCFAllocatorDefault,
bobbens@2546
   249
                                           kNilOptions);
bobbens@2546
   250
   if ((ret != KERN_SUCCESS) || !hidProperties) {
bobbens@2546
   251
      SDL_SetError("Haptic: Unable to create CFProperties.");
bobbens@2546
   252
      return -1;
bobbens@2546
   253
   }
bobbens@2546
   254
bobbens@2537
   255
   /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
bobbens@2537
   256
    * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties
bobbens@2537
   257
    */
bobbens@2537
   258
   if ((KERN_SUCCESS ==
bobbens@2537
   259
            IORegistryEntryGetParentEntry(dev, kIOServicePlane, &parent1))
bobbens@2537
   260
         && (KERN_SUCCESS ==
bobbens@2537
   261
            IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
bobbens@2537
   262
         && (KERN_SUCCESS ==
bobbens@2537
   263
            IORegistryEntryCreateCFProperties(parent2, &usbProperties,
bobbens@2546
   264
                                              kCFAllocatorDefault,
bobbens@2546
   265
                                              kNilOptions))) {
bobbens@2537
   266
      if (usbProperties) {
bobbens@2537
   267
         CFTypeRef refCF = 0;
bobbens@2537
   268
         /* get device info
bobbens@2537
   269
          * try hid dictionary first, if fail then go to usb dictionary
bobbens@2537
   270
          */
bobbens@2537
   271
bobbens@2537
   272
bobbens@2537
   273
         /* Get product name */
bobbens@2546
   274
         refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
bobbens@2537
   275
         if (!refCF)
bobbens@2537
   276
            refCF =
bobbens@2537
   277
               CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name"));
bobbens@2537
   278
         if (refCF) {
bobbens@2537
   279
            if (!CFStringGetCString(refCF, name, 256,
bobbens@2537
   280
                                    CFStringGetSystemEncoding())) {
bobbens@2641
   281
               SDL_SetError("Haptic: CFStringGetCString error retrieving pDevice->product.");
bobbens@2537
   282
               return -1;
bobbens@2537
   283
            }
bobbens@2537
   284
         }
bobbens@2537
   285
bobbens@2537
   286
         CFRelease(usbProperties);
bobbens@2537
   287
      }
bobbens@2537
   288
      else {
bobbens@2641
   289
         SDL_SetError("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
bobbens@2537
   290
         return -1;
bobbens@2537
   291
      }
bobbens@2537
   292
bobbens@2537
   293
      /* Release stuff. */
bobbens@2537
   294
      if (kIOReturnSuccess != IOObjectRelease(parent2)) {
bobbens@2641
   295
         SDL_SetError("Haptic: IOObjectRelease error with parent2.");
bobbens@2537
   296
      }
bobbens@2537
   297
      if (kIOReturnSuccess != IOObjectRelease(parent1))  {
bobbens@2641
   298
         SDL_SetError("Haptic: IOObjectRelease error with parent1.");
bobbens@2537
   299
      }
bobbens@2537
   300
   }
bobbens@2546
   301
   else {
bobbens@2546
   302
      SDL_SetError("Haptic: Error getting registry entries.");
bobbens@2546
   303
      return -1;
bobbens@2546
   304
   }
bobbens@2546
   305
bobbens@2537
   306
   return 0;
bobbens@2520
   307
}
bobbens@2520
   308
bobbens@2520
   309
bobbens@2520
   310
#define FF_TEST(ff, s) \
bobbens@2608
   311
if (features.supportedEffects & (ff)) supported |= (s)
bobbens@2520
   312
/*
bobbens@2520
   313
 * Gets supported features.
bobbens@2520
   314
 */
bobbens@2520
   315
static unsigned int
bobbens@2627
   316
GetSupportedFeatures(SDL_Haptic* haptic)
bobbens@2520
   317
{
bobbens@2520
   318
   HRESULT ret;
bobbens@2627
   319
   FFDeviceObjectReference device;
bobbens@2520
   320
   FFCAPABILITIES features;
bobbens@2520
   321
   unsigned int supported;
bobbens@2520
   322
   Uint32 val;
bobbens@2520
   323
bobbens@2627
   324
   device = haptic->hwdata->device;
bobbens@2627
   325
bobbens@2520
   326
   ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
bobbens@2520
   327
   if (ret != FF_OK) {
bobbens@2520
   328
      SDL_SetError("Haptic: Unable to get device's supported features.");
bobbens@2627
   329
      return -1;
bobbens@2520
   330
   }
bobbens@2520
   331
bobbens@2520
   332
   supported = 0;
bobbens@2520
   333
bobbens@2520
   334
   /* Get maximum effects. */
bobbens@2627
   335
   haptic->neffects = features.storageCapacity;
bobbens@2627
   336
   haptic->nplaying = features.playbackCapacity;
bobbens@2520
   337
bobbens@2520
   338
   /* Test for effects. */
bobbens@2520
   339
   FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT);
bobbens@2520
   340
   FF_TEST(FFCAP_ET_RAMPFORCE,     SDL_HAPTIC_RAMP);
bobbens@2520
   341
   FF_TEST(FFCAP_ET_SQUARE,        SDL_HAPTIC_SQUARE);
bobbens@2520
   342
   FF_TEST(FFCAP_ET_SINE,          SDL_HAPTIC_SINE);
bobbens@2520
   343
   FF_TEST(FFCAP_ET_TRIANGLE,      SDL_HAPTIC_TRIANGLE);
bobbens@2520
   344
   FF_TEST(FFCAP_ET_SAWTOOTHUP,    SDL_HAPTIC_SAWTOOTHUP);
bobbens@2520
   345
   FF_TEST(FFCAP_ET_SAWTOOTHDOWN,  SDL_HAPTIC_SAWTOOTHDOWN);
bobbens@2520
   346
   FF_TEST(FFCAP_ET_SPRING,        SDL_HAPTIC_SPRING);
bobbens@2520
   347
   FF_TEST(FFCAP_ET_DAMPER,        SDL_HAPTIC_DAMPER);
bobbens@2520
   348
   FF_TEST(FFCAP_ET_INERTIA,       SDL_HAPTIC_INERTIA);
bobbens@2520
   349
   FF_TEST(FFCAP_ET_FRICTION,      SDL_HAPTIC_FRICTION);
bobbens@2520
   350
   FF_TEST(FFCAP_ET_CUSTOMFORCE,   SDL_HAPTIC_CUSTOM);
bobbens@2520
   351
bobbens@2520
   352
   /* Check if supports gain. */
bobbens@2554
   353
   ret = FFDeviceGetForceFeedbackProperty( device, FFPROP_FFGAIN,
bobbens@2554
   354
                                           &val, sizeof(val));
bobbens@2520
   355
   if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN;
bobbens@2520
   356
   else if (ret != FFERR_UNSUPPORTED) {
bobbens@2541
   357
      SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
bobbens@2542
   358
                   FFStrError(ret));
bobbens@2627
   359
      return -1;
bobbens@2520
   360
   }
bobbens@2520
   361
bobbens@2520
   362
   /* Checks if supports autocenter. */
bobbens@2521
   363
   ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
bobbens@2522
   364
                                          &val, sizeof(val));
bobbens@2520
   365
   if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER;
bobbens@2520
   366
   else if (ret != FFERR_UNSUPPORTED) {
bobbens@2541
   367
      SDL_SetError("Haptic: Unable to get if device supports autocenter: %s.",
bobbens@2541
   368
                   FFStrError(ret));
bobbens@2627
   369
      return -1;
bobbens@2520
   370
   }
bobbens@2520
   371
bobbens@2527
   372
   /* Check for axes, we have an artificial limit on axes */
bobbens@2627
   373
   haptic->naxes = ((features.numFfAxes) > 3) ?
bobbens@2527
   374
         3 : features.numFfAxes;
bobbens@2627
   375
   /* Actually store the axes we want to use */
bobbens@2627
   376
   SDL_memcpy( haptic->hwdata->axes, features.ffAxes, haptic->naxes * sizeof(Uint8));
bobbens@2527
   377
bobbens@2520
   378
   /* Always supported features. */
bobbens@2645
   379
   supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
bobbens@2627
   380
bobbens@2627
   381
   haptic->supported = supported;
bobbens@2627
   382
   return 0;;
bobbens@2520
   383
}
bobbens@2520
   384
bobbens@2520
   385
bobbens@2520
   386
/*
bobbens@2520
   387
 * Opens the haptic device from the file descriptor.
bobbens@2520
   388
 */
bobbens@2520
   389
static int
bobbens@2520
   390
SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
bobbens@2520
   391
{
bobbens@2541
   392
   HRESULT ret;
bobbens@2627
   393
   int ret2;
bobbens@2541
   394
bobbens@2520
   395
   /* Allocate the hwdata */
bobbens@2520
   396
   haptic->hwdata = (struct haptic_hwdata *)
bobbens@2520
   397
         SDL_malloc(sizeof(*haptic->hwdata));
bobbens@2520
   398
   if (haptic->hwdata == NULL) {
bobbens@2520
   399
      SDL_OutOfMemory();
bobbens@2520
   400
      goto creat_err;
bobbens@2520
   401
   }
bobbens@2520
   402
   SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
bobbens@2520
   403
  
bobbens@2520
   404
   /* Open the device */
bobbens@2541
   405
   ret = FFCreateDevice( service, &haptic->hwdata->device);
bobbens@2541
   406
   if (ret != FF_OK) {
bobbens@2541
   407
      SDL_SetError("Haptic: Unable to create device from service: %s.",
bobbens@2541
   408
                   FFStrError(ret));
bobbens@2520
   409
      goto creat_err;
bobbens@2520
   410
   }
bobbens@2520
   411
bobbens@2520
   412
   /* Get supported features. */
bobbens@2627
   413
   ret2 = GetSupportedFeatures( haptic );
bobbens@2627
   414
   if (haptic->supported < 0) {
bobbens@2520
   415
      goto open_err;
bobbens@2520
   416
   }
bobbens@2550
   417
bobbens@2550
   418
bobbens@2550
   419
   /* Reset and then enable actuators. */
bobbens@2550
   420
   ret = FFDeviceSendForceFeedbackCommand( haptic->hwdata->device,
bobbens@2550
   421
                                           FFSFFC_RESET );
bobbens@2550
   422
   if (ret != FF_OK) {
bobbens@2550
   423
      SDL_SetError("Haptic: Unable to reset device: %s.", FFStrError(ret));
bobbens@2550
   424
      goto open_err;
bobbens@2550
   425
   }
bobbens@2550
   426
   ret = FFDeviceSendForceFeedbackCommand( haptic->hwdata->device,
bobbens@2550
   427
                                           FFSFFC_SETACTUATORSON  );
bobbens@2550
   428
   if (ret != FF_OK) {
bobbens@2550
   429
      SDL_SetError("Haptic: Unable to enable actuators: %s.", FFStrError(ret));
bobbens@2550
   430
      goto open_err;
bobbens@2550
   431
   }
bobbens@2550
   432
bobbens@2550
   433
bobbens@2550
   434
   /* Allocate effects memory. */
bobbens@2520
   435
   haptic->effects = (struct haptic_effect *)
bobbens@2520
   436
         SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
bobbens@2520
   437
   if (haptic->effects == NULL) {
bobbens@2520
   438
      SDL_OutOfMemory();
bobbens@2520
   439
      goto open_err;
bobbens@2520
   440
   }
bobbens@2520
   441
   /* Clear the memory */
bobbens@2520
   442
   SDL_memset(haptic->effects, 0,
bobbens@2520
   443
         sizeof(struct haptic_effect) * haptic->neffects);
bobbens@2520
   444
   
bobbens@2520
   445
   return 0;
bobbens@2520
   446
   
bobbens@2520
   447
   /* Error handling */
bobbens@2520
   448
open_err:
bobbens@2520
   449
   FFReleaseDevice(haptic->hwdata->device);
bobbens@2520
   450
creat_err:
bobbens@2520
   451
   if (haptic->hwdata != NULL) {
bobbens@2520
   452
      free(haptic->hwdata);
bobbens@2520
   453
      haptic->hwdata = NULL;                                              
bobbens@2520
   454
   }
bobbens@2520
   455
   return -1;
bobbens@2520
   456
bobbens@2520
   457
}
bobbens@2520
   458
bobbens@2520
   459
bobbens@2520
   460
/*
bobbens@2520
   461
 * Opens a haptic device for usage.
bobbens@2520
   462
 */
bobbens@2520
   463
int
bobbens@2520
   464
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
bobbens@2520
   465
{
bobbens@2520
   466
   return SDL_SYS_HapticOpenFromService(haptic,
bobbens@2522
   467
                SDL_hapticlist[haptic->index].dev);
bobbens@2520
   468
}
bobbens@2520
   469
bobbens@2520
   470
bobbens@2520
   471
/*
bobbens@2520
   472
 * Opens a haptic device from first mouse it finds for usage.
bobbens@2520
   473
 */
bobbens@2520
   474
int
bobbens@2520
   475
SDL_SYS_HapticMouse(void)
bobbens@2520
   476
{
bobbens@2641
   477
   int i;
bobbens@2641
   478
bobbens@2641
   479
   for (i=0; i<SDL_numhaptics; i++) {
bobbens@2641
   480
      if ((SDL_hapticlist[i].usagePage == kHIDPage_GenericDesktop) &&
bobbens@2641
   481
            (SDL_hapticlist[i].usage == kHIDUsage_GD_Mouse))
bobbens@2641
   482
         return i;
bobbens@2641
   483
   }
bobbens@2641
   484
bobbens@2520
   485
   return -1;
bobbens@2520
   486
}
bobbens@2520
   487
bobbens@2520
   488
bobbens@2520
   489
/*
bobbens@2520
   490
 * Checks to see if a joystick has haptic features.
bobbens@2520
   491
 */
bobbens@2520
   492
int
bobbens@2520
   493
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
bobbens@2520
   494
{
bobbens@2637
   495
   if (joystick->hwdata->ffservice != 0)
bobbens@2637
   496
      return SDL_TRUE;
bobbens@2520
   497
   return SDL_FALSE;
bobbens@2520
   498
}
bobbens@2520
   499
bobbens@2520
   500
bobbens@2520
   501
/*
bobbens@2520
   502
 * Checks to see if the haptic device and joystick and in reality the same.
bobbens@2520
   503
 */
bobbens@2520
   504
int
bobbens@2520
   505
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
bobbens@2520
   506
{
bobbens@2639
   507
   if (IOObjectIsEqualTo((io_object_t) haptic->hwdata->device,
bobbens@2639
   508
                                       joystick->hwdata->ffservice))
bobbens@2637
   509
      return 1;
bobbens@2520
   510
   return 0;
bobbens@2520
   511
}
bobbens@2520
   512
bobbens@2520
   513
bobbens@2520
   514
/*
bobbens@2520
   515
 * Opens a SDL_Haptic from a SDL_Joystick.
bobbens@2520
   516
 */
bobbens@2520
   517
int
bobbens@2520
   518
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
bobbens@2520
   519
{
bobbens@2637
   520
   return SDL_SYS_HapticOpenFromService(haptic,
bobbens@2637
   521
                joystick->hwdata->ffservice);
bobbens@2520
   522
}
bobbens@2520
   523
bobbens@2520
   524
bobbens@2520
   525
/*
bobbens@2520
   526
 * Closes the haptic device.
bobbens@2520
   527
 */
bobbens@2520
   528
void
bobbens@2520
   529
SDL_SYS_HapticClose(SDL_Haptic * haptic)
bobbens@2520
   530
{
bobbens@2520
   531
   if (haptic->hwdata) {
bobbens@2520
   532
bobbens@2561
   533
      /* Free Effects. */
bobbens@2530
   534
      SDL_free(haptic->effects);
bobbens@2561
   535
      haptic->effects = NULL;
bobbens@2530
   536
      haptic->neffects = 0;
bobbens@2530
   537
bobbens@2520
   538
      /* Clean up */
bobbens@2520
   539
      FFReleaseDevice(haptic->hwdata->device);
bobbens@2520
   540
bobbens@2520
   541
      /* Free */
bobbens@2520
   542
      SDL_free(haptic->hwdata);
bobbens@2520
   543
      haptic->hwdata = NULL;
bobbens@2520
   544
   }
bobbens@2520
   545
}
bobbens@2520
   546
bobbens@2520
   547
bobbens@2520
   548
/* 
bobbens@2520
   549
 * Clean up after system specific haptic stuff
bobbens@2520
   550
 */
bobbens@2520
   551
void
bobbens@2520
   552
SDL_SYS_HapticQuit(void)
bobbens@2520
   553
{
bobbens@2520
   554
   int i;
bobbens@2520
   555
bobbens@2520
   556
   for (i=0; i < SDL_numhaptics; i++) {
bobbens@2530
   557
      /* Opened and not closed haptics are leaked, this is on purpose.
bobbens@2530
   558
       * Close your haptic devices after usage. */
bobbens@2530
   559
bobbens@2530
   560
      /* Free the io_service_t */
bobbens@2520
   561
      IOObjectRelease(SDL_hapticlist[i].dev);
bobbens@2520
   562
   }
bobbens@2520
   563
}
bobbens@2520
   564
bobbens@2520
   565
bobbens@2520
   566
/*
bobbens@2554
   567
 * Converts an SDL trigger button to an FFEFFECT trigger button.
bobbens@2554
   568
 */
bobbens@2554
   569
static DWORD
bobbens@2554
   570
FFGetTriggerButton( Uint16 button )
bobbens@2554
   571
{
bobbens@2554
   572
   DWORD dwTriggerButton;
bobbens@2554
   573
bobbens@2554
   574
   dwTriggerButton = FFEB_NOTRIGGER;
bobbens@2554
   575
bobbens@2555
   576
   if (button != 0) {
bobbens@2556
   577
      dwTriggerButton = FFJOFS_BUTTON(button - 1);
bobbens@2555
   578
   }
bobbens@2554
   579
bobbens@2554
   580
   return dwTriggerButton;
bobbens@2554
   581
}
bobbens@2554
   582
bobbens@2554
   583
bobbens@2554
   584
/*
bobbens@2520
   585
 * Sets the direction.
bobbens@2520
   586
 */
bobbens@2520
   587
static int
bobbens@2529
   588
SDL_SYS_SetDirection( FFEFFECT * effect, SDL_HapticDirection *dir, int naxes )
bobbens@2520
   589
{
bobbens@2521
   590
   LONG *rglDir;
bobbens@2527
   591
bobbens@2527
   592
   /* Handle no axes a part. */
bobbens@2528
   593
   if (naxes == 0) {
bobbens@2559
   594
      effect->dwFlags |= FFEFF_SPHERICAL; /* Set as default. */
bobbens@2527
   595
      effect->rglDirection = NULL;
bobbens@2527
   596
      return 0;
bobbens@2527
   597
   }
bobbens@2527
   598
bobbens@2527
   599
   /* Has axes. */
bobbens@2529
   600
   rglDir = SDL_malloc( sizeof(LONG) * naxes );
bobbens@2527
   601
   if (rglDir == NULL) {
bobbens@2520
   602
      SDL_OutOfMemory();
bobbens@2520
   603
      return -1;
bobbens@2520
   604
   }
bobbens@2529
   605
   SDL_memset( rglDir, 0, sizeof(LONG) * naxes );
bobbens@2521
   606
   effect->rglDirection = rglDir;
bobbens@2520
   607
bobbens@2520
   608
   switch (dir->type) {
bobbens@2520
   609
      case SDL_HAPTIC_POLAR:
bobbens@2520
   610
         effect->dwFlags |= FFEFF_POLAR;
bobbens@2521
   611
         rglDir[0] = dir->dir[0];
bobbens@2520
   612
         return 0;
bobbens@2520
   613
      case SDL_HAPTIC_CARTESIAN:
bobbens@2522
   614
         effect->dwFlags |= FFEFF_CARTESIAN;
bobbens@2521
   615
         rglDir[0] = dir->dir[0];
bobbens@2604
   616
         if (naxes > 1)
bobbens@2604
   617
            rglDir[1] = dir->dir[1];
bobbens@2604
   618
         if (naxes > 2)
bobbens@2604
   619
            rglDir[2] = dir->dir[2];
bobbens@2520
   620
         return 0;
bobbens@2521
   621
      case SDL_HAPTIC_SPHERICAL:
bobbens@2522
   622
         effect->dwFlags |= FFEFF_SPHERICAL;
bobbens@2521
   623
         rglDir[0] = dir->dir[0];
bobbens@2604
   624
         if (naxes > 1)
bobbens@2604
   625
            rglDir[1] = dir->dir[1];
bobbens@2604
   626
         if (naxes > 2)
bobbens@2604
   627
            rglDir[2] = dir->dir[2];
bobbens@2520
   628
         return 0;
bobbens@2520
   629
bobbens@2520
   630
      default:
bobbens@2520
   631
         SDL_SetError("Haptic: Unknown direction type.");
bobbens@2520
   632
         return -1;
bobbens@2520
   633
   }
bobbens@2520
   634
}
bobbens@2520
   635
bobbens@2628
   636
bobbens@2628
   637
/* Clamps and converts. */
bobbens@2628
   638
#define CCONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
bobbens@2628
   639
/* Just converts. */
bobbens@2628
   640
#define CONVERT(x)    (((x)*10000) / 0x7FFF)
bobbens@2520
   641
/*
bobbens@2527
   642
 * Creates the FFEFFECT from a SDL_HapticEffect.
bobbens@2520
   643
 */
bobbens@2520
   644
static int
bobbens@2527
   645
SDL_SYS_ToFFEFFECT( SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src )
bobbens@2520
   646
{
bobbens@2530
   647
   int i;
bobbens@2520
   648
   FFCONSTANTFORCE *constant;
bobbens@2520
   649
   FFPERIODIC *periodic;
bobbens@2530
   650
   FFCONDITION *condition; /* Actually an array of conditions - one per axis. */
bobbens@2520
   651
   FFRAMPFORCE *ramp;
bobbens@2520
   652
   FFCUSTOMFORCE *custom;
bobbens@2522
   653
   FFENVELOPE *envelope;
bobbens@2520
   654
   SDL_HapticConstant *hap_constant;
bobbens@2521
   655
   SDL_HapticPeriodic *hap_periodic;
bobbens@2520
   656
   SDL_HapticCondition *hap_condition;
bobbens@2520
   657
   SDL_HapticRamp *hap_ramp;
bobbens@2535
   658
   SDL_HapticCustom *hap_custom;
bobbens@2527
   659
   DWORD *axes;
bobbens@2520
   660
bobbens@2520
   661
   /* Set global stuff. */
bobbens@2520
   662
   SDL_memset(dest, 0, sizeof(FFEFFECT));
bobbens@2520
   663
   dest->dwSize = sizeof(FFEFFECT); /* Set the structure size. */
bobbens@2520
   664
   dest->dwSamplePeriod = 0; /* Not used by us. */
bobbens@2520
   665
   dest->dwGain = 10000; /* Gain is set globally, not locally. */
bobbens@2610
   666
   dest->dwFlags = FFEFF_OBJECTOFFSETS; /* Seems obligatory. */
bobbens@2522
   667
bobbens@2522
   668
   /* Envelope. */
bobbens@2522
   669
   envelope = SDL_malloc( sizeof(FFENVELOPE) );
bobbens@2522
   670
   if (envelope == NULL) {
bobbens@2522
   671
      SDL_OutOfMemory();
bobbens@2522
   672
      return -1;
bobbens@2522
   673
   }
bobbens@2522
   674
   SDL_memset(envelope, 0, sizeof(FFENVELOPE));
bobbens@2522
   675
   dest->lpEnvelope = envelope;
bobbens@2522
   676
   envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */
bobbens@2520
   677
bobbens@2527
   678
   /* Axes. */
bobbens@2527
   679
   dest->cAxes = haptic->naxes;
bobbens@2527
   680
   if (dest->cAxes > 0) {
bobbens@2527
   681
      axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
bobbens@2527
   682
      if (axes == NULL) {
bobbens@2527
   683
         SDL_OutOfMemory();
bobbens@2527
   684
         return -1;
bobbens@2527
   685
      }
bobbens@2627
   686
      axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
bobbens@2527
   687
      if (dest->cAxes > 1) {
bobbens@2627
   688
         axes[1] = haptic->hwdata->axes[1];
bobbens@2527
   689
      }
bobbens@2527
   690
      if (dest->cAxes > 2) {
bobbens@2627
   691
         axes[2] = haptic->hwdata->axes[2];
bobbens@2527
   692
      }
bobbens@2527
   693
      dest->rgdwAxes = axes;
bobbens@2527
   694
   }
bobbens@2527
   695
bobbens@2527
   696
bobbens@2530
   697
   /* The big type handling switch, even bigger then linux's version. */
bobbens@2520
   698
   switch (src->type) {
bobbens@2520
   699
      case SDL_HAPTIC_CONSTANT:
bobbens@2520
   700
         hap_constant = &src->constant;
bobbens@2520
   701
         constant = SDL_malloc( sizeof(FFCONSTANTFORCE) );
bobbens@2527
   702
         if (constant == NULL) {
bobbens@2527
   703
            SDL_OutOfMemory();
bobbens@2527
   704
            return -1;
bobbens@2527
   705
         }
bobbens@2535
   706
         SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
bobbens@2520
   707
bobbens@2520
   708
         /* Specifics */
bobbens@2520
   709
         constant->lMagnitude = CONVERT(hap_constant->level);
bobbens@2520
   710
         dest->cbTypeSpecificParams = sizeof(FFCONSTANTFORCE); 
bobbens@2520
   711
         dest->lpvTypeSpecificParams = constant;
bobbens@2520
   712
bobbens@2520
   713
         /* Generics */
bobbens@2521
   714
         dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
bobbens@2554
   715
         dest->dwTriggerButton = FFGetTriggerButton(hap_constant->button);
bobbens@2520
   716
         dest->dwTriggerRepeatInterval = hap_constant->interval;
bobbens@2521
   717
         dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
bobbens@2520
   718
bobbens@2520
   719
         /* Direction. */
bobbens@2522
   720
         if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
bobbens@2520
   721
            return -1;
bobbens@2520
   722
         }
bobbens@2520
   723
         
bobbens@2520
   724
         /* Envelope */
bobbens@2565
   725
         if ((hap_constant->attack_length==0) && (hap_constant->fade_length==0)) {
bobbens@2563
   726
            SDL_free(envelope);
bobbens@2563
   727
            dest->lpEnvelope = NULL;
bobbens@2557
   728
         }
bobbens@2557
   729
         else {
bobbens@2628
   730
            envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
bobbens@2557
   731
            envelope->dwAttackTime = hap_constant->attack_length * 1000;
bobbens@2628
   732
            envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
bobbens@2557
   733
            envelope->dwFadeTime = hap_constant->fade_length * 1000;
bobbens@2557
   734
         }
bobbens@2520
   735
bobbens@2520
   736
         break;
bobbens@2520
   737
bobbens@2520
   738
      case SDL_HAPTIC_SINE:
bobbens@2520
   739
      case SDL_HAPTIC_SQUARE:
bobbens@2520
   740
      case SDL_HAPTIC_TRIANGLE:
bobbens@2520
   741
      case SDL_HAPTIC_SAWTOOTHUP:
bobbens@2520
   742
      case SDL_HAPTIC_SAWTOOTHDOWN:
bobbens@2522
   743
         hap_periodic = &src->periodic;
bobbens@2527
   744
         periodic = SDL_malloc(sizeof(FFPERIODIC));
bobbens@2527
   745
         if (periodic == NULL) {
bobbens@2527
   746
            SDL_OutOfMemory();
bobbens@2527
   747
            return -1;
bobbens@2527
   748
         }
bobbens@2535
   749
         SDL_memset(periodic, 0, sizeof(FFPERIODIC));
bobbens@2527
   750
bobbens@2527
   751
         /* Specifics */
bobbens@2527
   752
         periodic->dwMagnitude = CONVERT(hap_periodic->magnitude);
bobbens@2527
   753
         periodic->lOffset = CONVERT(hap_periodic->offset);
bobbens@2527
   754
         periodic->dwPhase = hap_periodic->phase;
bobbens@2527
   755
         periodic->dwPeriod = hap_periodic->period * 1000;
bobbens@2527
   756
         dest->cbTypeSpecificParams = sizeof(FFPERIODIC);
bobbens@2527
   757
         dest->lpvTypeSpecificParams = periodic;
bobbens@2527
   758
bobbens@2527
   759
         /* Generics */
bobbens@2527
   760
         dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
bobbens@2554
   761
         dest->dwTriggerButton = FFGetTriggerButton(hap_periodic->button);
bobbens@2527
   762
         dest->dwTriggerRepeatInterval = hap_periodic->interval;
bobbens@2527
   763
         dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
bobbens@2527
   764
         
bobbens@2527
   765
         /* Direction. */
bobbens@2527
   766
         if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) {
bobbens@2527
   767
            return -1;
bobbens@2527
   768
         }
bobbens@2527
   769
         
bobbens@2527
   770
         /* Envelope */
bobbens@2565
   771
         if ((hap_periodic->attack_length==0) && (hap_periodic->fade_length==0)) {
bobbens@2563
   772
            SDL_free(envelope);
bobbens@2563
   773
            dest->lpEnvelope = NULL;
bobbens@2557
   774
         }
bobbens@2557
   775
         else {
bobbens@2628
   776
            envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
bobbens@2557
   777
            envelope->dwAttackTime = hap_periodic->attack_length * 1000;
bobbens@2628
   778
            envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
bobbens@2557
   779
            envelope->dwFadeTime = hap_periodic->fade_length * 1000;
bobbens@2557
   780
         }
bobbens@2520
   781
bobbens@2520
   782
         break;
bobbens@2520
   783
bobbens@2520
   784
      case SDL_HAPTIC_SPRING:
bobbens@2520
   785
      case SDL_HAPTIC_DAMPER:
bobbens@2520
   786
      case SDL_HAPTIC_INERTIA:
bobbens@2520
   787
      case SDL_HAPTIC_FRICTION:
bobbens@2522
   788
         hap_condition = &src->condition;
bobbens@2530
   789
         condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
bobbens@2530
   790
         if (condition == NULL) {
bobbens@2530
   791
            SDL_OutOfMemory();
bobbens@2530
   792
            return -1;
bobbens@2530
   793
         }
bobbens@2535
   794
         SDL_memset(condition, 0, sizeof(FFCONDITION));
bobbens@2530
   795
bobbens@2530
   796
         /* Specifics */
bobbens@2530
   797
         for (i=0; i<dest->cAxes; i++) {
bobbens@2531
   798
            condition[i].lOffset = CONVERT(hap_condition->center[i]);
bobbens@2531
   799
            condition[i].lPositiveCoefficient = CONVERT(hap_condition->right_coeff[i]);
bobbens@2531
   800
            condition[i].lNegativeCoefficient = CONVERT(hap_condition->left_coeff[i]);
bobbens@2628
   801
            condition[i].dwPositiveSaturation = CCONVERT(hap_condition->right_sat[i]);
bobbens@2628
   802
            condition[i].dwNegativeSaturation = CCONVERT(hap_condition->left_sat[i]);
bobbens@2628
   803
            condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i]);
bobbens@2530
   804
         }
bobbens@2530
   805
         dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
bobbens@2530
   806
         dest->lpvTypeSpecificParams = condition;
bobbens@2530
   807
bobbens@2530
   808
         /* Generics */
bobbens@2531
   809
         dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
bobbens@2554
   810
         dest->dwTriggerButton = FFGetTriggerButton(hap_condition->button);
bobbens@2531
   811
         dest->dwTriggerRepeatInterval = hap_condition->interval;
bobbens@2531
   812
         dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
bobbens@2530
   813
bobbens@2530
   814
         /* Direction. */
bobbens@2531
   815
         if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) {
bobbens@2530
   816
            return -1;                
bobbens@2530
   817
         }                            
bobbens@2530
   818
                                      
bobbens@2629
   819
         /* Envelope - Not actually supported by most CONDITION implementations. */
bobbens@2557
   820
         SDL_free(dest->lpEnvelope);
bobbens@2557
   821
         dest->lpEnvelope = NULL;
bobbens@2520
   822
bobbens@2520
   823
         break;
bobbens@2520
   824
bobbens@2520
   825
      case SDL_HAPTIC_RAMP:
bobbens@2522
   826
         hap_ramp = &src->ramp;
bobbens@2533
   827
         ramp = SDL_malloc(sizeof(FFRAMPFORCE));
bobbens@2533
   828
         if (ramp == NULL) {
bobbens@2533
   829
            SDL_OutOfMemory();
bobbens@2533
   830
            return -1;
bobbens@2533
   831
         }
bobbens@2535
   832
         SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
bobbens@2533
   833
bobbens@2533
   834
         /* Specifics */
bobbens@2534
   835
         ramp->lStart = CONVERT(hap_ramp->start);
bobbens@2533
   836
         ramp->lEnd = CONVERT(hap_ramp->end);
bobbens@2535
   837
         dest->cbTypeSpecificParams = sizeof(FFRAMPFORCE);
bobbens@2535
   838
         dest->lpvTypeSpecificParams = ramp;
bobbens@2533
   839
bobbens@2533
   840
         /* Generics */
bobbens@2533
   841
         dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
bobbens@2554
   842
         dest->dwTriggerButton = FFGetTriggerButton(hap_ramp->button);
bobbens@2533
   843
         dest->dwTriggerRepeatInterval = hap_ramp->interval;
bobbens@2533
   844
         dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
bobbens@2533
   845
bobbens@2533
   846
         /* Direction. */
bobbens@2533
   847
         if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
bobbens@2533
   848
            return -1;
bobbens@2533
   849
         }
bobbens@2533
   850
bobbens@2533
   851
         /* Envelope */
bobbens@2565
   852
         if ((hap_ramp->attack_length==0) && (hap_ramp->fade_length==0)) {
bobbens@2563
   853
            SDL_free(envelope);
bobbens@2563
   854
            dest->lpEnvelope = NULL;
bobbens@2564
   855
         }
bobbens@2557
   856
         else {
bobbens@2628
   857
            envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
bobbens@2557
   858
            envelope->dwAttackTime = hap_ramp->attack_length * 1000;
bobbens@2628
   859
            envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
bobbens@2557
   860
            envelope->dwFadeTime = hap_ramp->fade_length * 1000;
bobbens@2557
   861
         }
bobbens@2520
   862
bobbens@2520
   863
         break;
bobbens@2520
   864
bobbens@2535
   865
      case SDL_HAPTIC_CUSTOM:
bobbens@2535
   866
         hap_custom = &src->custom;
bobbens@2535
   867
         custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
bobbens@2535
   868
         if (custom == NULL) {
bobbens@2535
   869
            SDL_OutOfMemory();
bobbens@2535
   870
            return -1;
bobbens@2535
   871
         }
bobbens@2535
   872
         SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
bobbens@2535
   873
bobbens@2535
   874
         /* Specifics */
bobbens@2535
   875
         custom->cChannels = hap_custom->channels;
bobbens@2535
   876
         custom->dwSamplePeriod = hap_custom->period * 1000;
bobbens@2535
   877
         custom->cSamples = hap_custom->samples;
bobbens@2535
   878
         custom->rglForceData = SDL_malloc(sizeof(LONG)*custom->cSamples*custom->cChannels);
bobbens@2535
   879
         for (i=0; i<hap_custom->samples*hap_custom->channels; i++) { /* Copy data. */
bobbens@2628
   880
            custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
bobbens@2535
   881
         }
bobbens@2535
   882
         dest->cbTypeSpecificParams = sizeof(FFCUSTOMFORCE);
bobbens@2535
   883
         dest->lpvTypeSpecificParams = custom;
bobbens@2535
   884
bobbens@2535
   885
         /* Generics */
bobbens@2535
   886
         dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
bobbens@2554
   887
         dest->dwTriggerButton = FFGetTriggerButton(hap_custom->button);
bobbens@2535
   888
         dest->dwTriggerRepeatInterval = hap_custom->interval;
bobbens@2535
   889
         dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
bobbens@2535
   890
bobbens@2535
   891
         /* Direction. */
bobbens@2535
   892
         if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
bobbens@2535
   893
            return -1;
bobbens@2535
   894
         }
bobbens@2535
   895
         
bobbens@2535
   896
         /* Envelope */
bobbens@2565
   897
         if ((hap_custom->attack_length==0) && (hap_custom->fade_length==0)) {
bobbens@2563
   898
            SDL_free(envelope);
bobbens@2563
   899
            dest->lpEnvelope = NULL;
bobbens@2557
   900
         }
bobbens@2557
   901
         else {
bobbens@2628
   902
            envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
bobbens@2557
   903
            envelope->dwAttackTime = hap_custom->attack_length * 1000;
bobbens@2628
   904
            envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
bobbens@2557
   905
            envelope->dwFadeTime = hap_custom->fade_length * 1000;
bobbens@2557
   906
         }
bobbens@2535
   907
bobbens@2535
   908
         break;
bobbens@2535
   909
bobbens@2520
   910
bobbens@2520
   911
      default:
bobbens@2520
   912
         SDL_SetError("Haptic: Unknown effect type.");
bobbens@2520
   913
         return -1;
bobbens@2520
   914
   }
bobbens@2520
   915
bobbens@2520
   916
   return 0;
bobbens@2520
   917
}
bobbens@2520
   918
bobbens@2520
   919
bobbens@2520
   920
/*
bobbens@2527
   921
 * Frees an FFEFFECT allocated by SDL_SYS_ToFFEFFECT.
bobbens@2527
   922
 */
bobbens@2531
   923
static void
bobbens@2535
   924
SDL_SYS_HapticFreeFFEFFECT( FFEFFECT * effect, int type )
bobbens@2527
   925
{
bobbens@2535
   926
   FFCUSTOMFORCE *custom;
bobbens@2535
   927
bobbens@2527
   928
   if (effect->lpEnvelope != NULL) {
bobbens@2527
   929
      SDL_free(effect->lpEnvelope);
bobbens@2527
   930
      effect->lpEnvelope = NULL;
bobbens@2527
   931
   }
bobbens@2527
   932
   if (effect->rgdwAxes != NULL) {
bobbens@2527
   933
      SDL_free(effect->rgdwAxes);
bobbens@2527
   934
      effect->rgdwAxes = NULL;
bobbens@2527
   935
   }
bobbens@2527
   936
   if (effect->lpvTypeSpecificParams != NULL) {
bobbens@2535
   937
      if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
bobbens@2535
   938
         custom = (FFCUSTOMFORCE*) effect->lpvTypeSpecificParams;
bobbens@2535
   939
         SDL_free(custom->rglForceData);
bobbens@2535
   940
         custom->rglForceData = NULL;
bobbens@2535
   941
      }
bobbens@2527
   942
      SDL_free(effect->lpvTypeSpecificParams);
bobbens@2527
   943
      effect->lpvTypeSpecificParams = NULL;
bobbens@2527
   944
   }
bobbens@2527
   945
   if (effect->rglDirection != NULL) {
bobbens@2527
   946
      SDL_free(effect->rglDirection);
bobbens@2527
   947
      effect->rglDirection = NULL;
bobbens@2527
   948
   }
bobbens@2527
   949
}
bobbens@2527
   950
bobbens@2527
   951
bobbens@2527
   952
/*
bobbens@2520
   953
 * Gets the effect type from the generic SDL haptic effect wrapper.
bobbens@2520
   954
 */
bobbens@2531
   955
CFUUIDRef
bobbens@2552
   956
SDL_SYS_HapticEffectType( Uint16 type )
bobbens@2520
   957
{
bobbens@2552
   958
   switch (type) {
bobbens@2520
   959
      case SDL_HAPTIC_CONSTANT:
bobbens@2520
   960
         return kFFEffectType_ConstantForce_ID;
bobbens@2520
   961
bobbens@2520
   962
      case SDL_HAPTIC_RAMP:
bobbens@2520
   963
         return kFFEffectType_RampForce_ID;
bobbens@2520
   964
bobbens@2520
   965
      case SDL_HAPTIC_SQUARE:
bobbens@2520
   966
         return kFFEffectType_Square_ID;
bobbens@2520
   967
bobbens@2520
   968
      case SDL_HAPTIC_SINE:
bobbens@2520
   969
         return kFFEffectType_Sine_ID;
bobbens@2520
   970
bobbens@2521
   971
      case SDL_HAPTIC_TRIANGLE:
bobbens@2520
   972
         return kFFEffectType_Triangle_ID;
bobbens@2520
   973
bobbens@2520
   974
      case SDL_HAPTIC_SAWTOOTHUP:
bobbens@2520
   975
         return kFFEffectType_SawtoothUp_ID;
bobbens@2520
   976
bobbens@2520
   977
      case SDL_HAPTIC_SAWTOOTHDOWN:
bobbens@2520
   978
         return kFFEffectType_SawtoothDown_ID;
bobbens@2520
   979
bobbens@2520
   980
      case SDL_HAPTIC_SPRING:
bobbens@2520
   981
         return kFFEffectType_Spring_ID;
bobbens@2520
   982
bobbens@2520
   983
      case SDL_HAPTIC_DAMPER:
bobbens@2520
   984
         return kFFEffectType_Damper_ID;
bobbens@2520
   985
bobbens@2520
   986
      case SDL_HAPTIC_INERTIA:
bobbens@2520
   987
         return kFFEffectType_Inertia_ID;
bobbens@2520
   988
bobbens@2520
   989
      case SDL_HAPTIC_FRICTION:
bobbens@2520
   990
         return kFFEffectType_Friction_ID;
bobbens@2520
   991
bobbens@2520
   992
      case SDL_HAPTIC_CUSTOM:
bobbens@2520
   993
         return kFFEffectType_CustomForce_ID;
bobbens@2520
   994
bobbens@2520
   995
      default:
bobbens@2520
   996
         SDL_SetError("Haptic: Unknown effect type.");
bobbens@2520
   997
         return NULL;
bobbens@2520
   998
   }
bobbens@2520
   999
}
bobbens@2520
  1000
bobbens@2520
  1001
bobbens@2520
  1002
/*
bobbens@2520
  1003
 * Creates a new haptic effect.
bobbens@2520
  1004
 */
bobbens@2520
  1005
int
bobbens@2520
  1006
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect,
bobbens@2520
  1007
      SDL_HapticEffect * base)
bobbens@2520
  1008
{
bobbens@2520
  1009
   HRESULT ret;
bobbens@2520
  1010
   CFUUIDRef type;
bobbens@2520
  1011
bobbens@2520
  1012
   /* Alloc the effect. */
bobbens@2520
  1013
   effect->hweffect = (struct haptic_hweffect *)
bobbens@2520
  1014
         SDL_malloc(sizeof(struct haptic_hweffect));
bobbens@2520
  1015
   if (effect->hweffect == NULL) {
bobbens@2520
  1016
      SDL_OutOfMemory();
bobbens@2527
  1017
      goto err_hweffect;
bobbens@2520
  1018
   }
bobbens@2520
  1019
bobbens@2520
  1020
   /* Get the type. */
bobbens@2553
  1021
   type = SDL_SYS_HapticEffectType(base->type);
bobbens@2520
  1022
   if (type == NULL) {
bobbens@2527
  1023
      goto err_hweffect;
bobbens@2520
  1024
   }
bobbens@2520
  1025
bobbens@2520
  1026
   /* Get the effect. */
bobbens@2538
  1027
   if (SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
bobbens@2527
  1028
      goto err_effectdone;
bobbens@2520
  1029
   }
bobbens@2520
  1030
bobbens@2527
  1031
   /* Create the actual effect. */
bobbens@2538
  1032
   ret = FFDeviceCreateEffect(haptic->hwdata->device, type,
bobbens@2538
  1033
         &effect->hweffect->effect, &effect->hweffect->ref);
bobbens@2527
  1034
   if (ret != FF_OK) {
bobbens@2541
  1035
      SDL_SetError("Haptic: Unable to create effect: %s.", FFStrError(ret));
bobbens@2527
  1036
      goto err_effectdone;
bobbens@2527
  1037
   }
bobbens@2527
  1038
bobbens@2527
  1039
   return 0;
bobbens@2527
  1040
bobbens@2527
  1041
err_effectdone:
bobbens@2538
  1042
   SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, base->type);
bobbens@2527
  1043
err_hweffect:
bobbens@2527
  1044
   if (effect->hweffect != NULL) {
bobbens@2527
  1045
      SDL_free(effect->hweffect);
bobbens@2527
  1046
      effect->hweffect = NULL;
bobbens@2527
  1047
   }
bobbens@2527
  1048
   return -1;
bobbens@2520
  1049
}
bobbens@2520
  1050
bobbens@2520
  1051
bobbens@2520
  1052
/*
bobbens@2520
  1053
 * Updates an effect.
bobbens@2520
  1054
 */
bobbens@2531
  1055
int
bobbens@2531
  1056
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
bobbens@2520
  1057
      struct haptic_effect * effect, SDL_HapticEffect * data)
bobbens@2520
  1058
{
bobbens@2538
  1059
   HRESULT ret;
bobbens@2538
  1060
   FFEffectParameterFlag flags;
bobbens@2538
  1061
   FFEFFECT temp;
bobbens@2538
  1062
bobbens@2538
  1063
   /* Get the effect. */
bobbens@2538
  1064
   SDL_memset(&temp, 0, sizeof(FFEFFECT));
bobbens@2538
  1065
   if (SDL_SYS_ToFFEFFECT(haptic, &temp, data) < 0) {
bobbens@2538
  1066
      goto err_update;
bobbens@2538
  1067
   }
bobbens@2538
  1068
bobbens@2538
  1069
   /* Set the flags.  Might be worthwhile to diff temp with loaded effect and
bobbens@2538
  1070
    *  only change those parameters. */
bobbens@2608
  1071
   flags = FFEP_DIRECTION |
bobbens@2608
  1072
           FFEP_DURATION |
bobbens@2608
  1073
           FFEP_ENVELOPE |
bobbens@2608
  1074
           FFEP_STARTDELAY |
bobbens@2608
  1075
           FFEP_TRIGGERBUTTON |
bobbens@2608
  1076
           FFEP_TRIGGERREPEATINTERVAL |
bobbens@2608
  1077
           FFEP_TYPESPECIFICPARAMS;
bobbens@2538
  1078
bobbens@2538
  1079
   /* Create the actual effect. */
bobbens@2542
  1080
   ret = FFEffectSetParameters(effect->hweffect->ref, &temp, flags);
bobbens@2538
  1081
   if (ret != FF_OK) {
bobbens@2541
  1082
      SDL_SetError("Haptic: Unable to update effect: %s.", FFStrError(ret));
bobbens@2538
  1083
      goto err_update;
bobbens@2538
  1084
   }
bobbens@2538
  1085
bobbens@2538
  1086
   /* Copy it over. */
bobbens@2538
  1087
   SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, data->type);
bobbens@2538
  1088
   SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(FFEFFECT));
bobbens@2538
  1089
bobbens@2538
  1090
   return 0;
bobbens@2538
  1091
bobbens@2538
  1092
err_update:
bobbens@2538
  1093
   SDL_SYS_HapticFreeFFEFFECT(&temp, data->type);
bobbens@2520
  1094
   return -1;
bobbens@2520
  1095
}
bobbens@2520
  1096
bobbens@2520
  1097
bobbens@2520
  1098
/*
bobbens@2520
  1099
 * Runs an effect.
bobbens@2520
  1100
 */
bobbens@2520
  1101
int
bobbens@2520
  1102
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect,
bobbens@2520
  1103
                        Uint32 iterations)
bobbens@2520
  1104
{
bobbens@2520
  1105
   HRESULT ret;
bobbens@2520
  1106
   Uint32 iter;
bobbens@2520
  1107
bobbens@2520
  1108
   /* Check if it's infinite. */
bobbens@2520
  1109
   if (iterations == SDL_HAPTIC_INFINITY) {
bobbens@2521
  1110
      iter = FF_INFINITE;
bobbens@2520
  1111
   }
bobbens@2520
  1112
   else
bobbens@2520
  1113
      iter = iterations;
bobbens@2520
  1114
bobbens@2520
  1115
   /* Run the effect. */
bobbens@2520
  1116
   ret = FFEffectStart(effect->hweffect->ref, iter, 0);
bobbens@2520
  1117
   if (ret != FF_OK) {
bobbens@2541
  1118
      SDL_SetError("Haptic: Unable to run the effect: %s.", FFStrError(ret));
bobbens@2520
  1119
      return -1;
bobbens@2520
  1120
   }
bobbens@2520
  1121
bobbens@2520
  1122
   return 0;
bobbens@2520
  1123
}
bobbens@2520
  1124
bobbens@2520
  1125
bobbens@2520
  1126
/*
bobbens@2520
  1127
 * Stops an effect.
bobbens@2520
  1128
 */
bobbens@2520
  1129
int
bobbens@2520
  1130
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
bobbens@2520
  1131
{
bobbens@2520
  1132
   HRESULT ret;
bobbens@2520
  1133
bobbens@2520
  1134
   ret = FFEffectStop(effect->hweffect->ref);
bobbens@2520
  1135
   if (ret != FF_OK) {
bobbens@2541
  1136
      SDL_SetError("Haptic: Unable to stop the effect: %s.", FFStrError(ret));
bobbens@2520
  1137
      return -1;
bobbens@2520
  1138
   }
bobbens@2520
  1139
bobbens@2520
  1140
   return 0;
bobbens@2520
  1141
}
bobbens@2520
  1142
bobbens@2520
  1143
bobbens@2520
  1144
/*
bobbens@2520
  1145
 * Frees the effect.
bobbens@2520
  1146
 */
bobbens@2520
  1147
void
bobbens@2520
  1148
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
bobbens@2520
  1149
{
bobbens@2520
  1150
   HRESULT ret;
bobbens@2520
  1151
bobbens@2520
  1152
   ret = FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref);
bobbens@2520
  1153
   if (ret != FF_OK) {
bobbens@2541
  1154
      SDL_SetError("Haptic: Error removing the effect from the device: %s.",
bobbens@2541
  1155
                   FFStrError(ret));
bobbens@2520
  1156
   }
bobbens@2562
  1157
   SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, effect->effect.type);
bobbens@2520
  1158
   SDL_free(effect->hweffect);
bobbens@2520
  1159
   effect->hweffect = NULL;
bobbens@2520
  1160
}
bobbens@2520
  1161
bobbens@2520
  1162
bobbens@2520
  1163
/*
bobbens@2520
  1164
 * Gets the status of a haptic effect.
bobbens@2520
  1165
 */
bobbens@2520
  1166
int
bobbens@2520
  1167
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect)
bobbens@2520
  1168
{
bobbens@2520
  1169
   HRESULT ret;
bobbens@2520
  1170
   FFEffectStatusFlag status;
bobbens@2520
  1171
bobbens@2521
  1172
   ret = FFEffectGetEffectStatus(effect->hweffect->ref, &status);
bobbens@2520
  1173
   if (ret != FF_OK) {
bobbens@2541
  1174
      SDL_SetError("Haptic: Unable to get effect status: %s.", FFStrError(ret));
bobbens@2520
  1175
      return -1;
bobbens@2520
  1176
   }
bobbens@2520
  1177
bobbens@2520
  1178
   if (status == 0) return SDL_FALSE;
bobbens@2520
  1179
   return SDL_TRUE; /* Assume it's playing or emulated. */
bobbens@2520
  1180
}
bobbens@2520
  1181
bobbens@2520
  1182
bobbens@2520
  1183
/*
bobbens@2520
  1184
 * Sets the gain.
bobbens@2520
  1185
 */
bobbens@2520
  1186
int
bobbens@2520
  1187
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
bobbens@2520
  1188
{
bobbens@2520
  1189
   HRESULT ret;
bobbens@2520
  1190
   Uint32 val;
bobbens@2520
  1191
bobbens@2520
  1192
   val = gain * 100; /* Mac OS X uses 0 to 10,000 */
bobbens@2520
  1193
   ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, FFPROP_FFGAIN, &val);
bobbens@2520
  1194
   if (ret != FF_OK) {
bobbens@2541
  1195
      SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
bobbens@2520
  1196
      return -1;
bobbens@2520
  1197
   }
bobbens@2520
  1198
bobbens@2520
  1199
   return 0;
bobbens@2520
  1200
}
bobbens@2520
  1201
bobbens@2520
  1202
bobbens@2520
  1203
/*
bobbens@2520
  1204
 * Sets the autocentering.
bobbens@2520
  1205
 */
bobbens@2520
  1206
int
bobbens@2520
  1207
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
bobbens@2520
  1208
{
bobbens@2520
  1209
   HRESULT ret;
bobbens@2520
  1210
   Uint32 val;
bobbens@2520
  1211
bobbens@2520
  1212
   /* Mac OS X only has 0 (off) and 1 (on) */
bobbens@2520
  1213
   if (autocenter == 0) val = 0;
bobbens@2520
  1214
   else val = 1;
bobbens@2520
  1215
bobbens@2520
  1216
   ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
bobbens@2521
  1217
               FFPROP_AUTOCENTER, &val);
bobbens@2520
  1218
   if (ret != FF_OK) {
bobbens@2541
  1219
      SDL_SetError("Haptic: Error setting autocenter: %s.", FFStrError(ret));
bobbens@2520
  1220
      return -1;
bobbens@2520
  1221
   }
bobbens@2520
  1222
  
bobbens@2520
  1223
   return 0;
bobbens@2520
  1224
}
bobbens@2520
  1225
bobbens@2520
  1226
bobbens@2645
  1227
/*
bobbens@2645
  1228
 * Pauses the device.
bobbens@2645
  1229
 */
bobbens@2645
  1230
int
bobbens@2645
  1231
SDL_SYS_HapticPause(SDL_Haptic * haptic)
bobbens@2645
  1232
{
bobbens@2645
  1233
   HRESULT ret;
bobbens@2645
  1234
bobbens@2645
  1235
   ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
bobbens@2645
  1236
         FFSFFC_PAUSE);
bobbens@2645
  1237
   if (ret != FF_OK) {
bobbens@2645
  1238
      SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
bobbens@2645
  1239
      return -1;
bobbens@2645
  1240
   }
bobbens@2645
  1241
bobbens@2645
  1242
   return 0;
bobbens@2645
  1243
}
bobbens@2645
  1244
bobbens@2645
  1245
bobbens@2645
  1246
/*
bobbens@2645
  1247
 * Unpauses the device.
bobbens@2645
  1248
 */
bobbens@2645
  1249
int
bobbens@2645
  1250
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
bobbens@2645
  1251
{
bobbens@2645
  1252
   HRESULT ret;
bobbens@2645
  1253
bobbens@2645
  1254
   ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
bobbens@2645
  1255
         FFSFFC_CONTINUE);
bobbens@2645
  1256
   if (ret != FF_OK) {
bobbens@2645
  1257
      SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
bobbens@2645
  1258
      return -1;
bobbens@2645
  1259
   }
bobbens@2645
  1260
bobbens@2645
  1261
   return 0;
bobbens@2645
  1262
}
bobbens@2645
  1263
bobbens@2645
  1264
bobbens@2541
  1265
#endif /* SDL_HAPTIC_IOKIT */