Mercurial > sdl-ios-xcode
comparison src/haptic/linux/SDL_syshaptic.c @ 2644:ef0ba67154c1 gsoc2008_force_feedback
More comments.
Some code clean up.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 20:49:31 +0000 |
parents | 318e67011ad9 |
children | 269ba4f28d0e |
comparison
equal
deleted
inserted
replaced
2643:91fd5d3cb90e | 2644:ef0ba67154c1 |
---|---|
28 #include "SDL_joystick.h" | 28 #include "SDL_joystick.h" |
29 #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ | 29 #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ |
30 #include "../../joystick/linux/SDL_sysjoystick_c.h" /* For joystick hwdata */ | 30 #include "../../joystick/linux/SDL_sysjoystick_c.h" /* For joystick hwdata */ |
31 | 31 |
32 #include <unistd.h> /* close */ | 32 #include <unistd.h> /* close */ |
33 #include <linux/input.h> | 33 #include <linux/input.h> /* Force feedback linux stuff. */ |
34 #include <sys/ioctl.h> | 34 #include <fcntl.h> /* O_RDWR */ |
35 #include <sys/types.h> | |
36 #include <sys/stat.h> | |
37 #include <fcntl.h> | |
38 #include <linux/limits.h> | |
39 #include <limits.h> /* INT_MAX */ | 35 #include <limits.h> /* INT_MAX */ |
40 #include <string.h> | 36 #include <errno.h> /* errno, strerror */ |
41 #include <errno.h> | 37 #include <math.h> /* atan2 */ |
42 #include <math.h> | 38 |
43 | 39 /* Just in case. */ |
44 #ifndef M_PI | 40 #ifndef M_PI |
45 # define M_PI 3.14159265358979323846 | 41 # define M_PI 3.14159265358979323846 |
46 #endif | 42 #endif |
47 | 43 |
48 | 44 |
49 #define MAX_HAPTICS 32 | 45 #define MAX_HAPTICS 32 /* It's doubtful someone has more then 32 evdev */ |
50 | 46 |
51 | 47 |
52 /* | 48 /* |
53 * List of available haptic devices. | 49 * List of available haptic devices. |
54 */ | 50 */ |
55 static struct | 51 static struct |
56 { | 52 { |
57 char *fname; | 53 char *fname; /* Dev path name (like /dev/input/event1) */ |
58 SDL_Haptic *haptic; | 54 SDL_Haptic *haptic; /* Assosciated haptic. */ |
59 } SDL_hapticlist[MAX_HAPTICS]; | 55 } SDL_hapticlist[MAX_HAPTICS]; |
60 | 56 |
61 | 57 |
62 /* | 58 /* |
63 * Haptic system hardware data. | 59 * Haptic system hardware data. |
64 */ | 60 */ |
65 struct haptic_hwdata | 61 struct haptic_hwdata |
66 { | 62 { |
67 int fd; | 63 int fd; /* File descriptor of the device. */ |
68 char *fname; /* Points to the name in SDL_hapticlist. */ | 64 char *fname; /* Points to the name in SDL_hapticlist. */ |
69 }; | 65 }; |
70 | 66 |
71 | 67 |
72 /* | 68 /* |
346 SDL_SetError("Haptic: Unable to open %s: %s", | 342 SDL_SetError("Haptic: Unable to open %s: %s", |
347 SDL_hapticlist[i], strerror(errno)); | 343 SDL_hapticlist[i], strerror(errno)); |
348 return -1; | 344 return -1; |
349 } | 345 } |
350 | 346 |
347 /* Is it a mouse? */ | |
351 if (EV_IsMouse(fd)) { | 348 if (EV_IsMouse(fd)) { |
352 close(fd); | 349 close(fd); |
353 return i; | 350 return i; |
354 } | 351 } |
355 | 352 |
467 { | 464 { |
468 Uint16 ff_button; | 465 Uint16 ff_button; |
469 | 466 |
470 ff_button = 0; | 467 ff_button = 0; |
471 | 468 |
469 /* | |
470 * Not sure what the proper syntax is because this actually isn't implemented | |
471 * in the current kernel from what I've seen (2.6.26). | |
472 */ | |
472 if (button != 0) { | 473 if (button != 0) { |
473 ff_button = BTN_GAMEPAD + button - 1; | 474 ff_button = BTN_GAMEPAD + button - 1; |
474 } | 475 } |
475 | 476 |
476 return ff_button; | 477 return ff_button; |
646 dest->u.condition[1].right_coeff = condition->right_coeff[1]; | 647 dest->u.condition[1].right_coeff = condition->right_coeff[1]; |
647 dest->u.condition[1].left_coeff = condition->left_coeff[1]; | 648 dest->u.condition[1].left_coeff = condition->left_coeff[1]; |
648 dest->u.condition[1].deadband = CLAMP(condition->deadband[1]); | 649 dest->u.condition[1].deadband = CLAMP(condition->deadband[1]); |
649 dest->u.condition[1].center = condition->center[1]; | 650 dest->u.condition[1].center = condition->center[1]; |
650 | 651 |
652 /* | |
653 * There is no envelope in the linux force feedback api for conditions. | |
654 */ | |
655 | |
651 break; | 656 break; |
652 | 657 |
653 case SDL_HAPTIC_RAMP: | 658 case SDL_HAPTIC_RAMP: |
654 ramp = &src->ramp; | 659 ramp = &src->ramp; |
655 | 660 |