Mercurial > sdl-ios-xcode
comparison src/haptic/linux/SDL_syshaptic.c @ 2523:366d84fdf8d1 gsoc2008_force_feedback
Haptic subsystem handles haptic axes now.
Support for SDL_HAPTIC_SPHERICAL on linux.
More error checking.
Improved documentation.
Added missing SDLCALLs to SDL_haptic.h.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Thu, 17 Jul 2008 11:47:48 +0000 |
parents | af9df9662807 |
children | 1a55848ce198 |
comparison
equal
deleted
inserted
replaced
2522:0877146be013 | 2523:366d84fdf8d1 |
---|---|
253 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); | 253 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); |
254 | 254 |
255 /* Set the data */ | 255 /* Set the data */ |
256 haptic->hwdata->fd = fd; | 256 haptic->hwdata->fd = fd; |
257 haptic->supported = EV_IsHaptic(fd); | 257 haptic->supported = EV_IsHaptic(fd); |
258 haptic->naxes = 2; /* Hardcoded for now, not sure if it's possible to find out. */ | |
258 | 259 |
259 /* Set the effects */ | 260 /* Set the effects */ |
260 if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) { | 261 if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) { |
261 SDL_SetError("Haptic: Unable to query device memory: %s", strerror(errno)); | 262 SDL_SetError("Haptic: Unable to query device memory: %s", strerror(errno)); |
262 goto open_err; | 263 goto open_err; |
417 switch (dir->type) { | 418 switch (dir->type) { |
418 case SDL_HAPTIC_POLAR: | 419 case SDL_HAPTIC_POLAR: |
419 /* Linux directions are inverted. */ | 420 /* Linux directions are inverted. */ |
420 tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000; | 421 tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000; |
421 return (Uint16) tmp; | 422 return (Uint16) tmp; |
423 | |
422 case SDL_HAPTIC_CARTESIAN: | 424 case SDL_HAPTIC_CARTESIAN: |
423 /* We must invert "x" and "y" to go clockwise. */ | 425 /* We must invert "x" and "y" to go clockwise. */ |
424 f = atan2(dir->dir[0], dir->dir[1]); | 426 f = atan2(dir->dir[0], dir->dir[1]); |
425 tmp = (int)(f*18000./M_PI) % 36000; | 427 tmp = (int)(f*18000./M_PI) % 36000; |
426 tmp = (tmp * 0xFFFF) / 36000; | 428 tmp = (tmp * 0xFFFF) / 36000; |
427 return (Uint16) tmp; | 429 return (Uint16) tmp; |
428 | 430 |
431 case SDL_HAPTIC_SPHERICAL: | |
432 tmp = (36000 - dir->dir[0]) + 27000; /* Convert to polars */ | |
433 tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; | |
434 return (Uint16) tmp; | |
435 | |
429 default: | 436 default: |
437 SDL_SetError("Haptic: Unsupported direction type."); | |
430 return -1; | 438 return -1; |
431 } | 439 } |
432 | 440 |
433 return 0; | 441 return 0; |
434 } | 442 } |
454 constant = &src->constant; | 462 constant = &src->constant; |
455 | 463 |
456 /* Header */ | 464 /* Header */ |
457 dest->type = FF_CONSTANT; | 465 dest->type = FF_CONSTANT; |
458 dest->direction = SDL_SYS_ToDirection(&constant->direction); | 466 dest->direction = SDL_SYS_ToDirection(&constant->direction); |
467 if (dest->direction < 0) return -1; | |
459 | 468 |
460 /* Replay */ | 469 /* Replay */ |
461 dest->replay.length = CLAMP(constant->length); | 470 dest->replay.length = CLAMP(constant->length); |
462 dest->replay.delay = CLAMP(constant->delay); | 471 dest->replay.delay = CLAMP(constant->delay); |
463 | 472 |
484 periodic = &src->periodic; | 493 periodic = &src->periodic; |
485 | 494 |
486 /* Header */ | 495 /* Header */ |
487 dest->type = FF_PERIODIC; | 496 dest->type = FF_PERIODIC; |
488 dest->direction = SDL_SYS_ToDirection(&periodic->direction); | 497 dest->direction = SDL_SYS_ToDirection(&periodic->direction); |
498 if (dest->direction < 0) return -1; | |
489 | 499 |
490 /* Replay */ | 500 /* Replay */ |
491 dest->replay.length = CLAMP(periodic->length); | 501 dest->replay.length = CLAMP(periodic->length); |
492 dest->replay.delay = CLAMP(periodic->delay); | 502 dest->replay.delay = CLAMP(periodic->delay); |
493 | 503 |
566 ramp = &src->ramp; | 576 ramp = &src->ramp; |
567 | 577 |
568 /* Header */ | 578 /* Header */ |
569 dest->type = FF_RAMP; | 579 dest->type = FF_RAMP; |
570 dest->direction = SDL_SYS_ToDirection(&ramp->direction); | 580 dest->direction = SDL_SYS_ToDirection(&ramp->direction); |
581 if (dest->direction < 0) return -1; | |
571 | 582 |
572 /* Replay */ | 583 /* Replay */ |
573 dest->replay.length = CLAMP(ramp->length); | 584 dest->replay.length = CLAMP(ramp->length); |
574 dest->replay.delay = CLAMP(ramp->delay); | 585 dest->replay.delay = CLAMP(ramp->delay); |
575 | 586 |