comparison src/joystick/linux/SDL_sysjoystick.c @ 2713:0906692aa6a4

Final merge of Google Summer of Code 2008 work... Force Feedback for SDL by Edgar Simo, mentored by Ryan C. Gordon
author Sam Lantinga <slouken@libsdl.org>
date Mon, 25 Aug 2008 09:55:03 +0000
parents a5de28552be4
children 204be4fc2726
comparison
equal deleted inserted replaced
2712:c4e697245676 2713:0906692aa6a4
29 #include <unistd.h> 29 #include <unistd.h>
30 #include <fcntl.h> 30 #include <fcntl.h>
31 #include <sys/ioctl.h> 31 #include <sys/ioctl.h>
32 #include <limits.h> /* For the definition of PATH_MAX */ 32 #include <limits.h> /* For the definition of PATH_MAX */
33 #include <linux/joystick.h> 33 #include <linux/joystick.h>
34 #if SDL_INPUT_LINUXEV
35 #include <linux/input.h>
36 #endif
37 34
38 #include "SDL_joystick.h" 35 #include "SDL_joystick.h"
39 #include "../SDL_sysjoystick.h" 36 #include "../SDL_sysjoystick.h"
40 #include "../SDL_joystick_c.h" 37 #include "../SDL_joystick_c.h"
38 #include "SDL_sysjoystick_c.h"
41 39
42 /* Special joystick configurations */ 40 /* Special joystick configurations */
43 static struct 41 static struct
44 { 42 {
45 const char *name; 43 const char *name;
276 int logicalno; 274 int logicalno;
277 #endif /* USE_LOGICAL_JOYSTICKS */ 275 #endif /* USE_LOGICAL_JOYSTICKS */
278 } SDL_joylist[MAX_JOYSTICKS]; 276 } SDL_joylist[MAX_JOYSTICKS];
279 277
280 278
281 /* The private structure used to keep track of a joystick */
282 struct joystick_hwdata
283 {
284 int fd;
285 /* The current linux joystick driver maps hats to two axes */
286 struct hwdata_hat
287 {
288 int axis[2];
289 } *hats;
290 /* The current linux joystick driver maps balls to two axes */
291 struct hwdata_ball
292 {
293 int axis[2];
294 } *balls;
295
296 /* Support for the Linux 2.4 unified input interface */
297 #if SDL_INPUT_LINUXEV
298 SDL_bool is_hid;
299 Uint8 key_map[KEY_MAX - BTN_MISC];
300 Uint8 abs_map[ABS_MAX];
301 struct axis_correct
302 {
303 int used;
304 int coef[3];
305 } abs_correct[ABS_MAX];
306 #endif
307 };
308
309
310 #ifndef NO_LOGICAL_JOYSTICKS 279 #ifndef NO_LOGICAL_JOYSTICKS
311 280
312 static int 281 static int
313 CountLogicalJoysticks(int max) 282 CountLogicalJoysticks(int max)
314 { 283 {
803 */ 772 */
804 int 773 int
805 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) 774 SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
806 { 775 {
807 int fd; 776 int fd;
777 char *fname;
808 SDL_logical_joydecl(int realindex); 778 SDL_logical_joydecl(int realindex);
809 SDL_logical_joydecl(SDL_Joystick * realjoy = NULL); 779 SDL_logical_joydecl(SDL_Joystick * realjoy = NULL);
810 780
811 /* Open the joystick and set the joystick file descriptor */ 781 /* Open the joystick and set the joystick file descriptor */
812 #ifndef NO_LOGICAL_JOYSTICKS 782 #ifndef NO_LOGICAL_JOYSTICKS
816 786
817 if (realjoy == NULL) 787 if (realjoy == NULL)
818 return (-1); 788 return (-1);
819 789
820 fd = realjoy->hwdata->fd; 790 fd = realjoy->hwdata->fd;
791 fname = realjoy->hwdata->fname;
821 792
822 } else { 793 } else {
823 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); 794 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0);
795 fname = SDL_joylist[joystick->index].fname;
824 } 796 }
825 SDL_joylist[joystick->index].joy = joystick; 797 SDL_joylist[joystick->index].joy = joystick;
826 #else 798 #else
827 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); 799 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0);
800 fname = SDL_joylist[joystick->index].fname;
828 #endif 801 #endif
829 802
830 if (fd < 0) { 803 if (fd < 0) {
831 SDL_SetError("Unable to open %s\n", SDL_joylist[joystick->index]); 804 SDL_SetError("Unable to open %s\n", SDL_joylist[joystick->index]);
832 return (-1); 805 return (-1);
838 close(fd); 811 close(fd);
839 return (-1); 812 return (-1);
840 } 813 }
841 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); 814 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
842 joystick->hwdata->fd = fd; 815 joystick->hwdata->fd = fd;
816 joystick->hwdata->fname = fname;
843 817
844 /* Set the joystick to non-blocking read mode */ 818 /* Set the joystick to non-blocking read mode */
845 fcntl(fd, F_SETFL, O_NONBLOCK); 819 fcntl(fd, F_SETFL, O_NONBLOCK);
846 820
847 /* Get the number of buttons and axes on the joystick */ 821 /* Get the number of buttons and axes on the joystick */