comparison src/haptic/linux/SDL_syshaptic.c @ 2483:9d52368ebcf5 gsoc2008_force_feedback

Setting effects memory to 0. Added SDL_HapticSetGain().
author Edgar Simo <bobbens@gmail.com>
date Tue, 01 Jul 2008 14:09:53 +0000
parents b51ad78812d5
children 666472fd4cb0
comparison
equal deleted inserted replaced
2482:b51ad78812d5 2483:9d52368ebcf5
33 #include <sys/types.h> 33 #include <sys/types.h>
34 #include <sys/stat.h> 34 #include <sys/stat.h>
35 #include <fcntl.h> 35 #include <fcntl.h>
36 #include <linux/limits.h> 36 #include <linux/limits.h>
37 #include <string.h> 37 #include <string.h>
38 #include <errno.h>
39 38
40 39
41 #define MAX_HAPTICS 32 40 #define MAX_HAPTICS 32
42 41
43 42
220 SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); 219 SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
221 if (haptic->effects == NULL) { 220 if (haptic->effects == NULL) {
222 SDL_OutOfMemory(); 221 SDL_OutOfMemory();
223 goto open_err; 222 goto open_err;
224 } 223 }
224 /* Clear the memory */
225 SDL_memset(haptic->effects, 0,
226 sizeof(struct haptic_effect) * haptic->neffects);
225 227
226 return 0; 228 return 0;
227 229
228 /* Error handling */ 230 /* Error handling */
229 open_err: 231 open_err:
433 } 435 }
434 436
435 return 0; 437 return 0;
436 } 438 }
437 439
440
438 /* 441 /*
439 * Creates a new haptic effect. 442 * Creates a new haptic effect.
440 */ 443 */
441 int 444 int
442 SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect, 445 SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect,
459 } 462 }
460 linux_effect->id = -1; /* Have the kernel give it an id */ 463 linux_effect->id = -1; /* Have the kernel give it an id */
461 464
462 /* Upload the effect */ 465 /* Upload the effect */
463 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) { 466 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
464 SDL_SetError("Error uploading effect to the haptic device: %s", 467 SDL_SetError("Error uploading effect to the haptic device.");
465 strerror(errno));
466 return -1; 468 return -1;
467 } 469 }
468 470
469 return 0; 471 return 0;
470 } 472 }
504 SDL_free(effect->hweffect); 506 SDL_free(effect->hweffect);
505 effect->hweffect = NULL; 507 effect->hweffect = NULL;
506 } 508 }
507 509
508 510
511 /*
512 * Sets the gain.
513 */
514 int
515 SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
516 {
517 struct input_event ie;
518
519 ie.type = EV_FF;
520 ie.code = FF_GAIN;
521 ie.value = (0xFFFFUL * gain) / 100;
522 printf("%d\n",ie.value);
523
524 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) == -1) {
525 SDL_SetError("Error setting gain.");
526 }
527
528 }
529
530
509 #endif /* SDL_HAPTIC_LINUX */ 531 #endif /* SDL_HAPTIC_LINUX */