Mercurial > sdl-ios-xcode
comparison src/haptic/linux/SDL_syshaptic.c @ 2488:8e2bdbccf7ff gsoc2008_force_feedback
Added SDL_HapticUpdateEffect().
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Tue, 01 Jul 2008 18:35:05 +0000 |
parents | 4c8e25ef2d97 |
children | 96adc8025331 |
comparison
equal
deleted
inserted
replaced
2487:4c8e25ef2d97 | 2488:8e2bdbccf7ff |
---|---|
454 } | 454 } |
455 | 455 |
456 /* Prepare the ff_effect */ | 456 /* Prepare the ff_effect */ |
457 linux_effect = &effect->hweffect->effect; | 457 linux_effect = &effect->hweffect->effect; |
458 if (SDL_SYS_ToFFEffect( linux_effect, base ) != 0) { | 458 if (SDL_SYS_ToFFEffect( linux_effect, base ) != 0) { |
459 return -1; | 459 goto new_effect_err; |
460 } | 460 } |
461 linux_effect->id = -1; /* Have the kernel give it an id */ | 461 linux_effect->id = -1; /* Have the kernel give it an id */ |
462 | 462 |
463 /* Upload the effect */ | 463 /* Upload the effect */ |
464 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) { | 464 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) { |
465 SDL_SetError("Error uploading effect to the haptic device."); | 465 SDL_SetError("Error uploading effect to the haptic device."); |
466 return -1; | 466 goto new_effect_err; |
467 } | 467 } |
468 | 468 |
469 return 0; | 469 return 0; |
470 | |
471 new_effect_err: | |
472 free(effect->hweffect); | |
473 effect->hweffect = NULL; | |
474 return -1; | |
475 } | |
476 | |
477 | |
478 /* | |
479 * Updates an effect. | |
480 * | |
481 * Note: Dynamically updating the direction can in some cases force | |
482 * the effect to restart and run once. | |
483 */ | |
484 int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, | |
485 struct haptic_effect * effect, SDL_HapticEffect * data) | |
486 { | |
487 struct ff_effect linux_effect; | |
488 | |
489 /* Create the new effect */ | |
490 if (SDL_SYS_ToFFEffect( &linux_effect, data ) != 0) { | |
491 return -1; | |
492 } | |
493 linux_effect.id = effect->hweffect->effect.id; | |
494 | |
495 /* See if it can be uploaded. */ | |
496 if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) { | |
497 SDL_SetError("Error updating the haptic effect."); | |
498 return -1; | |
499 } | |
500 | |
501 /* Copy the new effect into memory. */ | |
502 SDL_memcpy( &effect->hweffect->effect, &linux_effect, sizeof(struct ff_effect) ); | |
503 | |
504 return effect->hweffect->effect.id; | |
470 } | 505 } |
471 | 506 |
472 | 507 |
473 /* | 508 /* |
474 * Runs an effect. | 509 * Runs an effect. |