Mercurial > sdl-ios-xcode
comparison src/haptic/darwin/SDL_syshaptic.c @ 2521:7aa91c21ce5f gsoc2008_force_feedback
Many typo and silly mistake fixes.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Tue, 15 Jul 2008 17:03:34 +0000 |
parents | 6aee9eb4fc6d |
children | 0877146be013 |
comparison
equal
deleted
inserted
replaced
2520:6aee9eb4fc6d | 2521:7aa91c21ce5f |
---|---|
27 #include "../SDL_syshaptic.h" | 27 #include "../SDL_syshaptic.h" |
28 #include "SDL_joystick.h" | 28 #include "SDL_joystick.h" |
29 #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ | 29 #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ |
30 /*#include "../../joystick/dawrin/SDL_sysjoystick_c.h"*/ /* For joystick hwdata */ | 30 /*#include "../../joystick/dawrin/SDL_sysjoystick_c.h"*/ /* For joystick hwdata */ |
31 | 31 |
32 #include <IOKit/IOTypes.h> | |
32 #include <ForceFeedback/ForceFeedback.h> | 33 #include <ForceFeedback/ForceFeedback.h> |
33 #include <ForceFeedback/ForceFeedbackConstants.h> | 34 #include <ForceFeedback/ForceFeedbackConstants.h> |
34 | 35 |
35 | 36 |
36 #define MAX_HAPTICS 32 | 37 #define MAX_HAPTICS 32 |
73 { | 74 { |
74 int numhaptics; | 75 int numhaptics; |
75 IOReturn result; | 76 IOReturn result; |
76 io_iterator_t iter; | 77 io_iterator_t iter; |
77 CFDictionaryRef match; | 78 CFDictionaryRef match; |
78 io_sercive_t device; | 79 io_service_t device; |
79 | 80 |
80 /* Get HID devices. */ | 81 /* Get HID devices. */ |
81 match = IOServiceMatching(kIOHIDDeviceKey); | 82 match = IOServiceMatching(kIOHIDDeviceKey); |
82 if (match == NULL) { | 83 if (match == NULL) { |
83 SDL_SetError("Haptic: Failed to get IOServiceMatching."); | 84 SDL_SetError("Haptic: Failed to get IOServiceMatching."); |
170 SDL_SetError("Haptic: Unable to get if device supports gain."); | 171 SDL_SetError("Haptic: Unable to get if device supports gain."); |
171 return 0; | 172 return 0; |
172 } | 173 } |
173 | 174 |
174 /* Checks if supports autocenter. */ | 175 /* Checks if supports autocenter. */ |
175 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFAUTOCENTER, | 176 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER, |
176 val, sizeof(val)); | 177 val, sizeof(val)); |
177 if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER; | 178 if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER; |
178 else if (ret != FFERR_UNSUPPORTED) { | 179 else if (ret != FFERR_UNSUPPORTED) { |
179 SDL_SetError("Haptic: Unable to get if device supports autocenter."); | 180 SDL_SetError("Haptic: Unable to get if device supports autocenter."); |
180 return 0; | 181 return 0; |
337 * Sets the direction. | 338 * Sets the direction. |
338 */ | 339 */ |
339 static int | 340 static int |
340 SDL_SYS_SetDirection( FFEFFECT * effect, SDL_HapticDirection *dir, int axes ) | 341 SDL_SYS_SetDirection( FFEFFECT * effect, SDL_HapticDirection *dir, int axes ) |
341 { | 342 { |
342 LONG *dir; | 343 LONG *rglDir; |
343 dir = SDL_malloc( sizeof(LONG) * axes ); | 344 dir = SDL_malloc( sizeof(LONG) * axes ); |
344 if (dir == NULL) { | 345 if (dir == NULL) { |
345 SDL_OutOfMemory(); | 346 SDL_OutOfMemory(); |
346 return -1; | 347 return -1; |
347 } | 348 } |
348 SDL_memset( dir, 0, sizeof(LONG) * axes ); | 349 SDL_memset( dir, 0, sizeof(LONG) * axes ); |
349 effect->rglDirection = dir; | 350 effect->rglDirection = rglDir; |
350 | 351 |
351 switch (dir->type) { | 352 switch (dir->type) { |
352 case SDL_HAPTIC_POLAR: | 353 case SDL_HAPTIC_POLAR: |
353 effect->dwFlags |= FFEFF_POLAR; | 354 effect->dwFlags |= FFEFF_POLAR; |
354 dir[0] = dir->dir[0]; | 355 rglDir[0] = dir->dir[0]; |
355 return 0; | 356 return 0; |
356 case SDL_HAPTIC_CARTESIAN: | 357 case SDL_HAPTIC_CARTESIAN: |
357 effects->dwFlags |= FFEFF_CARTESIAN; | 358 effects->dwFlags |= FFEFF_CARTESIAN; |
358 dir[0] = dir->dir[0]; | 359 rglDir[0] = dir->dir[0]; |
359 dir[1] = dir->dir[1]; | 360 rglDir[1] = dir->dir[1]; |
360 dir[2] = dir->dir[2]; | 361 rglDir[2] = dir->dir[2]; |
361 return 0; | 362 return 0; |
362 case SDL_HAPTIC_SHPERICAL: | 363 case SDL_HAPTIC_SPHERICAL: |
363 effects->dwFlags |= FFEFF_SPHERICAL; | 364 effects->dwFlags |= FFEFF_SPHERICAL; |
364 dir[0] = dir->dir[0]; | 365 rglDir[0] = dir->dir[0]; |
365 dir[1] = dir->dir[1]; | 366 rglDir[1] = dir->dir[1]; |
366 dir[2] = dir->dir[2]; | 367 rglDir[2] = dir->dir[2]; |
367 return 0; | 368 return 0; |
368 | 369 |
369 default: | 370 default: |
370 SDL_SetError("Haptic: Unknown direction type."); | 371 SDL_SetError("Haptic: Unknown direction type."); |
371 return -1; | 372 return -1; |
383 FFPERIODIC *periodic; | 384 FFPERIODIC *periodic; |
384 FFCONDITION *condition; | 385 FFCONDITION *condition; |
385 FFRAMPFORCE *ramp; | 386 FFRAMPFORCE *ramp; |
386 FFCUSTOMFORCE *custom; | 387 FFCUSTOMFORCE *custom; |
387 SDL_HapticConstant *hap_constant; | 388 SDL_HapticConstant *hap_constant; |
388 SDL_HapticPeriodic *hap-periodic; | 389 SDL_HapticPeriodic *hap_periodic; |
389 SDL_HapticCondition *hap_condition; | 390 SDL_HapticCondition *hap_condition; |
390 SDL_HapticRamp *hap_ramp; | 391 SDL_HapticRamp *hap_ramp; |
391 | 392 |
392 /* Set global stuff. */ | 393 /* Set global stuff. */ |
393 SDL_memset(dest, 0, sizeof(FFEFFECT)); | 394 SDL_memset(dest, 0, sizeof(FFEFFECT)); |
405 constant->lMagnitude = CONVERT(hap_constant->level); | 406 constant->lMagnitude = CONVERT(hap_constant->level); |
406 dest->cbTypeSpecificParams = sizeof(FFCONSTANTFORCE); | 407 dest->cbTypeSpecificParams = sizeof(FFCONSTANTFORCE); |
407 dest->lpvTypeSpecificParams = constant; | 408 dest->lpvTypeSpecificParams = constant; |
408 | 409 |
409 /* Generics */ | 410 /* Generics */ |
410 dest->dwDuration = src->length * 1000; /* In microseconds. */ | 411 dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */ |
411 dest->dwTriggerButton = FFJOFS_BUTTON(hap_constant->button); | 412 dest->dwTriggerButton = FFJOFS_BUTTON(hap_constant->button); |
412 dest->dwTriggerRepeatInterval = hap_constant->interval; | 413 dest->dwTriggerRepeatInterval = hap_constant->interval; |
413 dest->dwStartDelay = src->delay * 1000; /* In microseconds. */ | 414 dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */ |
414 | 415 |
415 /* Axes */ | 416 /* Axes */ |
416 dest->cAxes = 2; /* TODO handle */ | 417 dest->cAxes = 2; /* TODO handle */ |
417 dest->rgdwAxes = 0; | 418 dest->rgdwAxes = 0; |
418 | 419 |
466 /* | 467 /* |
467 * Gets the effect type from the generic SDL haptic effect wrapper. | 468 * Gets the effect type from the generic SDL haptic effect wrapper. |
468 */ | 469 */ |
469 CFUUIDRef SDL_SYS_HapticEffectType(struct haptic_effect * effect) | 470 CFUUIDRef SDL_SYS_HapticEffectType(struct haptic_effect * effect) |
470 { | 471 { |
471 switch (effect->effect->type) { | 472 switch (effect->effect.type) { |
472 case SDL_HAPTIC_CONSTANT: | 473 case SDL_HAPTIC_CONSTANT: |
473 return kFFEffectType_ConstantForce_ID; | 474 return kFFEffectType_ConstantForce_ID; |
474 | 475 |
475 case SDL_HAPTIC_RAMP: | 476 case SDL_HAPTIC_RAMP: |
476 return kFFEffectType_RampForce_ID; | 477 return kFFEffectType_RampForce_ID; |
479 return kFFEffectType_Square_ID; | 480 return kFFEffectType_Square_ID; |
480 | 481 |
481 case SDL_HAPTIC_SINE: | 482 case SDL_HAPTIC_SINE: |
482 return kFFEffectType_Sine_ID; | 483 return kFFEffectType_Sine_ID; |
483 | 484 |
484 case SDL_HAPTIC_TRIANGLE; | 485 case SDL_HAPTIC_TRIANGLE: |
485 return kFFEffectType_Triangle_ID; | 486 return kFFEffectType_Triangle_ID; |
486 | 487 |
487 case SDL_HAPTIC_SAWTOOTHUP: | 488 case SDL_HAPTIC_SAWTOOTHUP: |
488 return kFFEffectType_SawtoothUp_ID; | 489 return kFFEffectType_SawtoothUp_ID; |
489 | 490 |
537 effect->hweffect = NULL; | 538 effect->hweffect = NULL; |
538 return -1; | 539 return -1; |
539 } | 540 } |
540 | 541 |
541 /* Get the effect. */ | 542 /* Get the effect. */ |
542 if (SDL_SYS_ToFFEFFECT( &effect->hweffect->effect, &haptic_effect->effect ) < 0) { | 543 if (SDL_SYS_ToFFEFFECT( &effect->hweffect->effect, &effect->effect ) < 0) { |
543 /* TODO cleanup alloced stuff. */ | 544 /* TODO cleanup alloced stuff. */ |
544 return -1; | 545 return -1; |
545 } | 546 } |
546 | 547 |
547 ret = FFDeviceCreateEffect( haptic->hwdata->device, type, | 548 ret = FFDeviceCreateEffect( haptic->hwdata->device, type, |
570 HRESULT ret; | 571 HRESULT ret; |
571 Uint32 iter; | 572 Uint32 iter; |
572 | 573 |
573 /* Check if it's infinite. */ | 574 /* Check if it's infinite. */ |
574 if (iterations == SDL_HAPTIC_INFINITY) { | 575 if (iterations == SDL_HAPTIC_INFINITY) { |
575 iter = INFINITE; | 576 iter = FF_INFINITE; |
576 } | 577 } |
577 else | 578 else |
578 iter = iterations; | 579 iter = iterations; |
579 | 580 |
580 /* Run the effect. */ | 581 /* Run the effect. */ |
632 SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect) | 633 SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect) |
633 { | 634 { |
634 HRESULT ret; | 635 HRESULT ret; |
635 FFEffectStatusFlag status; | 636 FFEffectStatusFlag status; |
636 | 637 |
637 ret = FFEffectGetEffectStatus(effect->hweffect.ref, &status); | 638 ret = FFEffectGetEffectStatus(effect->hweffect->ref, &status); |
638 if (ret != FF_OK) { | 639 if (ret != FF_OK) { |
639 SDL_SetError("Haptic: Unable to get effect status."); | 640 SDL_SetError("Haptic: Unable to get effect status."); |
640 return -1; | 641 return -1; |
641 } | 642 } |
642 | 643 |
677 /* Mac OS X only has 0 (off) and 1 (on) */ | 678 /* Mac OS X only has 0 (off) and 1 (on) */ |
678 if (autocenter == 0) val = 0; | 679 if (autocenter == 0) val = 0; |
679 else val = 1; | 680 else val = 1; |
680 | 681 |
681 ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, | 682 ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, |
682 FFPROP_FFAUTOCENTER, &val); | 683 FFPROP_AUTOCENTER, &val); |
683 if (ret != FF_OK) { | 684 if (ret != FF_OK) { |
684 SDL_SetError("Haptic: Error setting autocenter."); | 685 SDL_SetError("Haptic: Error setting autocenter."); |
685 return -1; | 686 return -1; |
686 } | 687 } |
687 | 688 |