comparison src/haptic/linux/SDL_syshaptic.c @ 2513:55fd9103a330 gsoc2008_force_feedback

Prefixed all haptic errors with "Haptic:" for easier readability.
author Edgar Simo <bobbens@gmail.com>
date Thu, 10 Jul 2008 11:39:28 +0000
parents ef147ee4896c
children 030fc4375e63
comparison
equal deleted inserted replaced
2512:ef147ee4896c 2513:55fd9103a330
92 unsigned long features[1 + FF_MAX/sizeof(unsigned long)]; 92 unsigned long features[1 + FF_MAX/sizeof(unsigned long)];
93 93
94 /* Ask device for what it has. */ 94 /* Ask device for what it has. */
95 ret = 0; 95 ret = 0;
96 if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) { 96 if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) {
97 SDL_SetError("Unable to get device's haptic abilities: %s", strerror(errno)); 97 SDL_SetError("Haptic: Unable to get device's features: %s", strerror(errno));
98 return -1; 98 return -1;
99 } 99 }
100 100
101 /* Convert supported features to SDL_HAPTIC platform-neutral features. */ 101 /* Convert supported features to SDL_HAPTIC platform-neutral features. */
102 EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT); 102 EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT);
255 haptic->hwdata->fd = fd; 255 haptic->hwdata->fd = fd;
256 haptic->supported = EV_IsHaptic(fd); 256 haptic->supported = EV_IsHaptic(fd);
257 257
258 /* Set the effects */ 258 /* Set the effects */
259 if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) { 259 if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
260 SDL_SetError("Unable to query haptic device memory: %s", strerror(errno)); 260 SDL_SetError("Haptic: Unable to query device memory: %s", strerror(errno));
261 goto open_err; 261 goto open_err;
262 } 262 }
263 haptic->effects = (struct haptic_effect *) 263 haptic->effects = (struct haptic_effect *)
264 SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); 264 SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
265 if (haptic->effects == NULL) { 265 if (haptic->effects == NULL) {
292 int fd; 292 int fd;
293 293
294 /* Open the character device */ 294 /* Open the character device */
295 fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0); 295 fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
296 if (fd < 0) { 296 if (fd < 0) {
297 SDL_SetError("Unable to open %s: %s", 297 SDL_SetError("Haptic: Unable to open %s: %s",
298 SDL_hapticlist[haptic->index], strerror(errno)); 298 SDL_hapticlist[haptic->index], strerror(errno));
299 return -1; 299 return -1;
300 } 300 }
301 301
302 return SDL_SYS_HapticOpenFromFD(haptic,fd); 302 return SDL_SYS_HapticOpenFromFD(haptic,fd);
315 for (i=0; i<SDL_numhaptics; i++) { 315 for (i=0; i<SDL_numhaptics; i++) {
316 316
317 /* Open the device. */ 317 /* Open the device. */
318 fd = open(SDL_hapticlist[i].fname, O_RDWR, 0); 318 fd = open(SDL_hapticlist[i].fname, O_RDWR, 0);
319 if (fd < 0) { 319 if (fd < 0) {
320 SDL_SetError("Unable to open %s: %s", 320 SDL_SetError("Haptic: Unable to open %s: %s",
321 SDL_hapticlist[i], strerror(errno)); 321 SDL_hapticlist[i], strerror(errno));
322 return -1; 322 return -1;
323 } 323 }
324 324
325 if (EV_IsMouse(fd)) { 325 if (EV_IsMouse(fd)) {
588 588
589 break; 589 break;
590 590
591 591
592 default: 592 default:
593 SDL_SetError("Unknown haptic effect type"); 593 SDL_SetError("Haptic: Unknown effect type.");
594 return -1; 594 return -1;
595 } 595 }
596 596
597 return 0; 597 return 0;
598 } 598 }
622 } 622 }
623 linux_effect->id = -1; /* Have the kernel give it an id */ 623 linux_effect->id = -1; /* Have the kernel give it an id */
624 624
625 /* Upload the effect */ 625 /* Upload the effect */
626 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) { 626 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
627 SDL_SetError("Error uploading effect to the haptic device: %s", strerror(errno)); 627 SDL_SetError("Haptic: Error uploading effect to the device: %s", strerror(errno));
628 goto new_effect_err; 628 goto new_effect_err;
629 } 629 }
630 630
631 return 0; 631 return 0;
632 632
654 } 654 }
655 linux_effect.id = effect->hweffect->effect.id; 655 linux_effect.id = effect->hweffect->effect.id;
656 656
657 /* See if it can be uploaded. */ 657 /* See if it can be uploaded. */
658 if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) { 658 if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
659 SDL_SetError("Error updating the haptic effect: %s", strerror(errno)); 659 SDL_SetError("Haptic: Error updating the effect: %s", strerror(errno));
660 return -1; 660 return -1;
661 } 661 }
662 662
663 /* Copy the new effect into memory. */ 663 /* Copy the new effect into memory. */
664 SDL_memcpy( &effect->hweffect->effect, &linux_effect, sizeof(struct ff_effect) ); 664 SDL_memcpy( &effect->hweffect->effect, &linux_effect, sizeof(struct ff_effect) );
679 run.type = EV_FF; 679 run.type = EV_FF;
680 run.code = effect->hweffect->effect.id; 680 run.code = effect->hweffect->effect.id;
681 run.value = 1; 681 run.value = 1;
682 682
683 if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) { 683 if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) {
684 SDL_SetError("Unable to run the haptic effect: %s", strerror(errno)); 684 SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
685 return -1; 685 return -1;
686 } 686 }
687 687
688 return 0; 688 return 0;
689 } 689 }
700 stop.type = EV_FF; 700 stop.type = EV_FF;
701 stop.code = effect->hweffect->effect.id; 701 stop.code = effect->hweffect->effect.id;
702 stop.value = 0; 702 stop.value = 0;
703 703
704 if (write(haptic->hwdata->fd, (const void*) &stop, sizeof(stop)) < 0) { 704 if (write(haptic->hwdata->fd, (const void*) &stop, sizeof(stop)) < 0) {
705 SDL_SetError("Unable to stop the haptic effect: %s", strerror(errno)); 705 SDL_SetError("Haptic: Unable to stop the effect: %s", strerror(errno));
706 return -1; 706 return -1;
707 } 707 }
708 708
709 return 0; 709 return 0;
710 } 710 }
715 */ 715 */
716 void 716 void
717 SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect) 717 SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
718 { 718 {
719 if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) { 719 if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) {
720 SDL_SetError("Error removing the effect from the haptic device: %s", 720 SDL_SetError("Haptic: Error removing the effect from the device: %s",
721 strerror(errno)); 721 strerror(errno));
722 } 722 }
723 SDL_free(effect->hweffect); 723 SDL_free(effect->hweffect);
724 effect->hweffect = NULL; 724 effect->hweffect = NULL;
725 } 725 }
737 ie.type = EV_FF; 737 ie.type = EV_FF;
738 ie.type = EV_FF_STATUS; 738 ie.type = EV_FF_STATUS;
739 ie.code = effect->hweffect->effect.id; 739 ie.code = effect->hweffect->effect.id;
740 740
741 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { 741 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
742 SDL_SetError("Error getting haptic device status."); 742 SDL_SetError("Haptic: Error getting device status.");
743 return -1; 743 return -1;
744 } 744 }
745 745
746 return 0; 746 return 0;
747 #endif 747 #endif
761 ie.type = EV_FF; 761 ie.type = EV_FF;
762 ie.code = FF_GAIN; 762 ie.code = FF_GAIN;
763 ie.value = (0xFFFFUL * gain) / 100; 763 ie.value = (0xFFFFUL * gain) / 100;
764 764
765 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { 765 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
766 SDL_SetError("Error setting gain: %s", strerror(errno)); 766 SDL_SetError("Haptic: Error setting gain: %s", strerror(errno));
767 return -1; 767 return -1;
768 } 768 }
769 769
770 return 0; 770 return 0;
771 } 771 }
782 ie.type = EV_FF; 782 ie.type = EV_FF;
783 ie.code = FF_AUTOCENTER; 783 ie.code = FF_AUTOCENTER;
784 ie.value = (0xFFFFUL * autocenter) / 100; 784 ie.value = (0xFFFFUL * autocenter) / 100;
785 785
786 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { 786 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
787 SDL_SetError("Error setting autocenter: %s", strerror(errno)); 787 SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno));
788 return -1; 788 return -1;
789 } 789 }
790 790
791 return 0; 791 return 0;
792 } 792 }