comparison src/haptic/SDL_haptic.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 840e1b6325c0
comparison
equal deleted inserted replaced
2512:ef147ee4896c 2513:55fd9103a330
65 ValidHaptic(SDL_Haptic ** haptic) 65 ValidHaptic(SDL_Haptic ** haptic)
66 { 66 {
67 int valid; 67 int valid;
68 68
69 if (*haptic == NULL) { 69 if (*haptic == NULL) {
70 SDL_SetError("Haptic device hasn't been opened yet"); 70 SDL_SetError("Haptic: Device hasn't been opened yet");
71 valid = 0; 71 valid = 0;
72 } else { 72 } else {
73 valid = 1; 73 valid = 1;
74 } 74 }
75 return valid; 75 return valid;
91 */ 91 */
92 const char * 92 const char *
93 SDL_HapticName(int device_index) 93 SDL_HapticName(int device_index)
94 { 94 {
95 if ((device_index < 0) || (device_index >= SDL_numhaptics)) { 95 if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
96 SDL_SetError("There are %d haptic devices available", SDL_numhaptics); 96 SDL_SetError("Haptic: There are %d haptic devices available", SDL_numhaptics);
97 return NULL; 97 return NULL;
98 } 98 }
99 return SDL_SYS_HapticName(device_index); 99 return SDL_SYS_HapticName(device_index);
100 } 100 }
101 101
108 { 108 {
109 int i; 109 int i;
110 SDL_Haptic *haptic; 110 SDL_Haptic *haptic;
111 111
112 if ((device_index < 0) || (device_index >= SDL_numhaptics)) { 112 if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
113 SDL_SetError("There are %d haptic devices available", SDL_numhaptics); 113 SDL_SetError("Haptic: There are %d haptic devices available", SDL_numhaptics);
114 return NULL; 114 return NULL;
115 } 115 }
116 116
117 /* If the haptic is already open, return it */ 117 /* If the haptic is already open, return it */
118 for (i=0; SDL_haptics[i]; i++) { 118 for (i=0; SDL_haptics[i]; i++) {
208 int device_index; 208 int device_index;
209 209
210 device_index = SDL_SYS_HapticMouse(); 210 device_index = SDL_SYS_HapticMouse();
211 211
212 if (device_index < 0) { 212 if (device_index < 0) {
213 SDL_SetError("Mouse isn't a haptic device."); 213 SDL_SetError("Haptic: Mouse isn't a haptic device.");
214 return NULL; 214 return NULL;
215 } 215 }
216 216
217 return SDL_HapticOpen(device_index); 217 return SDL_HapticOpen(device_index);
218 } 218 }
399 return -1; 399 return -1;
400 } 400 }
401 401
402 /* Check to see if effect is supported */ 402 /* Check to see if effect is supported */
403 if (SDL_HapticEffectSupported(haptic,effect)==SDL_FALSE) { 403 if (SDL_HapticEffectSupported(haptic,effect)==SDL_FALSE) {
404 SDL_SetError("Haptic effect not supported by haptic device."); 404 SDL_SetError("Haptic: Effect not supported by haptic device.");
405 return -1; 405 return -1;
406 } 406 }
407 407
408 /* See if there's a free slot */ 408 /* See if there's a free slot */
409 for (i=0; i<haptic->neffects; i++) { 409 for (i=0; i<haptic->neffects; i++) {
415 } 415 }
416 return i; 416 return i;
417 } 417 }
418 } 418 }
419 419
420 SDL_SetError("Haptic device has no free space left."); 420 SDL_SetError("Haptic: Device has no free space left.");
421 return -1; 421 return -1;
422 } 422 }
423 423
424 /* 424 /*
425 * Checks to see if an effect is valid. 425 * Checks to see if an effect is valid.
426 */ 426 */
427 static int 427 static int
428 ValidEffect(SDL_Haptic * haptic, int effect) 428 ValidEffect(SDL_Haptic * haptic, int effect)
429 { 429 {
430 if ((effect < 0) || (effect >= haptic->neffects)) { 430 if ((effect < 0) || (effect >= haptic->neffects)) {
431 SDL_SetError("Invalid haptic effect identifier."); 431 SDL_SetError("Haptic: Invalid effect identifier.");
432 return 0; 432 return 0;
433 } 433 }
434 return 1; 434 return 1;
435 } 435 }
436 436
516 if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) { 516 if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
517 return -1; 517 return -1;
518 } 518 }
519 519
520 if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) { 520 if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
521 SDL_SetError("Haptic device does not support status queries."); 521 SDL_SetError("Haptic: Device does not support status queries.");
522 return -1; 522 return -1;
523 } 523 }
524 524
525 return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]); 525 return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
526 } 526 }
537 if (!ValidHaptic(&haptic)) { 537 if (!ValidHaptic(&haptic)) {
538 return -1; 538 return -1;
539 } 539 }
540 540
541 if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) { 541 if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
542 SDL_SetError("Haptic device does not support setting gain."); 542 SDL_SetError("Haptic: Device does not support setting gain.");
543 return -1; 543 return -1;
544 } 544 }
545 545
546 if ((gain < 0) || (gain > 100)) { 546 if ((gain < 0) || (gain > 100)) {
547 SDL_SetError("Haptic gain must be between 0 and 100."); 547 SDL_SetError("Haptic: Gain must be between 0 and 100.");
548 return -1; 548 return -1;
549 } 549 }
550 550
551 /* We use the envvar to get the maximum gain. */ 551 /* We use the envvar to get the maximum gain. */
552 env = SDL_getenv("SDL_HAPTIC_GAIN_MAX"); 552 env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
580 if (!ValidHaptic(&haptic)) { 580 if (!ValidHaptic(&haptic)) {
581 return -1; 581 return -1;
582 } 582 }
583 583
584 if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) { 584 if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
585 SDL_SetError("Haptic device does not support setting autocenter."); 585 SDL_SetError("Haptic: Device does not support setting autocenter.");
586 return -1; 586 return -1;
587 } 587 }
588 588
589 if ((autocenter < 0) || (autocenter > 100)) { 589 if ((autocenter < 0) || (autocenter > 100)) {
590 SDL_SetError("Haptic autocenter must be between 0 and 100."); 590 SDL_SetError("Haptic: Autocenter must be between 0 and 100.");
591 return -1; 591 return -1;
592 } 592 }
593 593
594 if (SDL_SYS_HapticSetAutocenter(haptic,autocenter) < 0) { 594 if (SDL_SYS_HapticSetAutocenter(haptic,autocenter) < 0) {
595 return -1; 595 return -1;