comparison src/haptic/darwin/SDL_syshaptic.c @ 2627:265ced2079bd gsoc2008_force_feedback

Proper axes support for darwin haptic.
author Edgar Simo <bobbens@gmail.com>
date Wed, 06 Aug 2008 10:26:47 +0000
parents 71a835ee438a
children bfbda6c656e5
comparison
equal deleted inserted replaced
2626:53dd30491c71 2627:265ced2079bd
53 * Haptic system hardware data. 53 * Haptic system hardware data.
54 */ 54 */
55 struct haptic_hwdata 55 struct haptic_hwdata
56 { 56 {
57 FFDeviceObjectReference device; /* Hardware device. */ 57 FFDeviceObjectReference device; /* Hardware device. */
58 UInt8 axes[3];
58 }; 59 };
59 60
60 61
61 /* 62 /*
62 * Haptic system effect data. 63 * Haptic system effect data.
273 if (features.supportedEffects & (ff)) supported |= (s) 274 if (features.supportedEffects & (ff)) supported |= (s)
274 /* 275 /*
275 * Gets supported features. 276 * Gets supported features.
276 */ 277 */
277 static unsigned int 278 static unsigned int
278 GetSupportedFeatures(FFDeviceObjectReference device, 279 GetSupportedFeatures(SDL_Haptic* haptic)
279 int *neffects, int *nplaying, int *naxes)
280 { 280 {
281 HRESULT ret; 281 HRESULT ret;
282 FFDeviceObjectReference device;
282 FFCAPABILITIES features; 283 FFCAPABILITIES features;
283 unsigned int supported; 284 unsigned int supported;
284 Uint32 val; 285 Uint32 val;
285 286
287 device = haptic->hwdata->device;
288
286 ret = FFDeviceGetForceFeedbackCapabilities(device, &features); 289 ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
287 if (ret != FF_OK) { 290 if (ret != FF_OK) {
288 SDL_SetError("Haptic: Unable to get device's supported features."); 291 SDL_SetError("Haptic: Unable to get device's supported features.");
289 return 0; 292 return -1;
290 } 293 }
291 294
292 supported = 0; 295 supported = 0;
293 296
294 /* Get maximum effects. */ 297 /* Get maximum effects. */
295 *neffects = features.storageCapacity; 298 haptic->neffects = features.storageCapacity;
296 *nplaying = features.playbackCapacity; 299 haptic->nplaying = features.playbackCapacity;
297 300
298 /* Test for effects. */ 301 /* Test for effects. */
299 FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT); 302 FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT);
300 FF_TEST(FFCAP_ET_RAMPFORCE, SDL_HAPTIC_RAMP); 303 FF_TEST(FFCAP_ET_RAMPFORCE, SDL_HAPTIC_RAMP);
301 FF_TEST(FFCAP_ET_SQUARE, SDL_HAPTIC_SQUARE); 304 FF_TEST(FFCAP_ET_SQUARE, SDL_HAPTIC_SQUARE);
314 &val, sizeof(val)); 317 &val, sizeof(val));
315 if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN; 318 if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN;
316 else if (ret != FFERR_UNSUPPORTED) { 319 else if (ret != FFERR_UNSUPPORTED) {
317 SDL_SetError("Haptic: Unable to get if device supports gain: %s.", 320 SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
318 FFStrError(ret)); 321 FFStrError(ret));
319 return 0; 322 return -1;
320 } 323 }
321 324
322 /* Checks if supports autocenter. */ 325 /* Checks if supports autocenter. */
323 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER, 326 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
324 &val, sizeof(val)); 327 &val, sizeof(val));
325 if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER; 328 if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER;
326 else if (ret != FFERR_UNSUPPORTED) { 329 else if (ret != FFERR_UNSUPPORTED) {
327 SDL_SetError("Haptic: Unable to get if device supports autocenter: %s.", 330 SDL_SetError("Haptic: Unable to get if device supports autocenter: %s.",
328 FFStrError(ret)); 331 FFStrError(ret));
329 return 0; 332 return -1;
330 } 333 }
331 334
332 /* Check for axes, we have an artificial limit on axes */ 335 /* Check for axes, we have an artificial limit on axes */
333 *naxes = ((features.numFfAxes) > 3) ? 336 haptic->naxes = ((features.numFfAxes) > 3) ?
334 3 : features.numFfAxes; 337 3 : features.numFfAxes;
338 /* Actually store the axes we want to use */
339 SDL_memcpy( haptic->hwdata->axes, features.ffAxes, haptic->naxes * sizeof(Uint8));
335 340
336 /* Always supported features. */ 341 /* Always supported features. */
337 supported |= SDL_HAPTIC_STATUS; 342 supported |= SDL_HAPTIC_STATUS;
338 return supported; 343
344 haptic->supported = supported;
345 return 0;;
339 } 346 }
340 347
341 348
342 /* 349 /*
343 * Opens the haptic device from the file descriptor. 350 * Opens the haptic device from the file descriptor.
344 */ 351 */
345 static int 352 static int
346 SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service) 353 SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
347 { 354 {
348 HRESULT ret; 355 HRESULT ret;
356 int ret2;
349 357
350 /* Allocate the hwdata */ 358 /* Allocate the hwdata */
351 haptic->hwdata = (struct haptic_hwdata *) 359 haptic->hwdata = (struct haptic_hwdata *)
352 SDL_malloc(sizeof(*haptic->hwdata)); 360 SDL_malloc(sizeof(*haptic->hwdata));
353 if (haptic->hwdata == NULL) { 361 if (haptic->hwdata == NULL) {
363 FFStrError(ret)); 371 FFStrError(ret));
364 goto creat_err; 372 goto creat_err;
365 } 373 }
366 374
367 /* Get supported features. */ 375 /* Get supported features. */
368 haptic->supported = GetSupportedFeatures( haptic->hwdata->device, 376 ret2 = GetSupportedFeatures( haptic );
369 &haptic->neffects, &haptic->nplaying, 377 if (haptic->supported < 0) {
370 &haptic->naxes );
371 if (haptic->supported == 0) { /* Error since device supports nothing. */
372 goto open_err; 378 goto open_err;
373 } 379 }
374 380
375 381
376 /* Reset and then enable actuators. */ 382 /* Reset and then enable actuators. */
620 axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); 626 axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
621 if (axes == NULL) { 627 if (axes == NULL) {
622 SDL_OutOfMemory(); 628 SDL_OutOfMemory();
623 return -1; 629 return -1;
624 } 630 }
625 axes[0] = FFJOFS_X; /* Always at least one axis. */ 631 axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
626 if (dest->cAxes > 1) { 632 if (dest->cAxes > 1) {
627 axes[1] = FFJOFS_Y; 633 axes[1] = haptic->hwdata->axes[1];
628 } 634 }
629 if (dest->cAxes > 2) { 635 if (dest->cAxes > 2) {
630 axes[2] = FFJOFS_Z; 636 axes[2] = haptic->hwdata->axes[2];
631 } 637 }
632 dest->rgdwAxes = axes; 638 dest->rgdwAxes = axes;
633 } 639 }
634 640
635 641