Mercurial > sdl-ios-xcode
comparison src/joystick/linux/SDL_sysjoystick.c @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | c71e05b4dc2e |
children | c0a74f199ecf |
comparison
equal
deleted
inserted
replaced
1360:70a9cfb4cf1b | 1361:19418e4422cb |
---|---|
29 #include <limits.h> /* For the definition of PATH_MAX */ | 29 #include <limits.h> /* For the definition of PATH_MAX */ |
30 #ifdef __arm__ | 30 #ifdef __arm__ |
31 #include <linux/limits.h> /* Arm cross-compiler needs this */ | 31 #include <linux/limits.h> /* Arm cross-compiler needs this */ |
32 #endif | 32 #endif |
33 #include <linux/joystick.h> | 33 #include <linux/joystick.h> |
34 #ifdef USE_INPUT_EVENTS | 34 #if SDL_INPUT_LINUXEV |
35 #include <linux/input.h> | 35 #include <linux/input.h> |
36 #endif | 36 #endif |
37 | 37 |
38 #include "SDL_joystick.h" | 38 #include "SDL_joystick.h" |
39 #include "SDL_sysjoystick.h" | 39 #include "../SDL_sysjoystick.h" |
40 #include "SDL_joystick_c.h" | 40 #include "../SDL_joystick_c.h" |
41 | 41 |
42 /* Special joystick configurations */ | 42 /* Special joystick configurations */ |
43 static struct { | 43 static struct { |
44 const char *name; | 44 const char *name; |
45 int naxes; | 45 int naxes; |
166 struct hwdata_ball { | 166 struct hwdata_ball { |
167 int axis[2]; | 167 int axis[2]; |
168 } *balls; | 168 } *balls; |
169 | 169 |
170 /* Support for the Linux 2.4 unified input interface */ | 170 /* Support for the Linux 2.4 unified input interface */ |
171 #ifdef USE_INPUT_EVENTS | 171 #if SDL_INPUT_LINUXEV |
172 SDL_bool is_hid; | 172 SDL_bool is_hid; |
173 Uint8 key_map[KEY_MAX-BTN_MISC]; | 173 Uint8 key_map[KEY_MAX-BTN_MISC]; |
174 Uint8 abs_map[ABS_MAX]; | 174 Uint8 abs_map[ABS_MAX]; |
175 struct axis_correct { | 175 struct axis_correct { |
176 int used; | 176 int used; |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 #endif /* USE_LOGICAL_JOYSTICKS */ | 258 #endif /* USE_LOGICAL_JOYSTICKS */ |
259 | 259 |
260 #ifdef USE_INPUT_EVENTS | 260 #if SDL_INPUT_LINUXEV |
261 #define test_bit(nr, addr) \ | 261 #define test_bit(nr, addr) \ |
262 (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0) | 262 (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0) |
263 | 263 |
264 static int EV_IsJoystick(int fd) | 264 static int EV_IsJoystick(int fd) |
265 { | 265 { |
276 test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit) && | 276 test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit) && |
277 (test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_A, keybit) || test_bit(BTN_1, keybit)))) return 0; | 277 (test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_A, keybit) || test_bit(BTN_1, keybit)))) return 0; |
278 return(1); | 278 return(1); |
279 } | 279 } |
280 | 280 |
281 #endif /* USE_INPUT_EVENTS */ | 281 #endif /* SDL_INPUT_LINUXEV */ |
282 | 282 |
283 /* Function to scan the system for joysticks */ | 283 /* Function to scan the system for joysticks */ |
284 int SDL_SYS_JoystickInit(void) | 284 int SDL_SYS_JoystickInit(void) |
285 { | 285 { |
286 /* The base path of the joystick devices */ | 286 /* The base path of the joystick devices */ |
287 const char *joydev_pattern[] = { | 287 const char *joydev_pattern[] = { |
288 #ifdef USE_INPUT_EVENTS | 288 #if SDL_INPUT_LINUXEV |
289 "/dev/input/event%d", | 289 "/dev/input/event%d", |
290 #endif | 290 #endif |
291 "/dev/input/js%d", | 291 "/dev/input/js%d", |
292 "/dev/js%d" | 292 "/dev/js%d" |
293 }; | 293 }; |
343 | 343 |
344 fd = open(path, O_RDONLY, 0); | 344 fd = open(path, O_RDONLY, 0); |
345 if ( fd < 0 ) { | 345 if ( fd < 0 ) { |
346 continue; | 346 continue; |
347 } | 347 } |
348 #ifdef USE_INPUT_EVENTS | 348 #if SDL_INPUT_LINUXEV |
349 #ifdef DEBUG_INPUT_EVENTS | 349 #ifdef DEBUG_INPUT_EVENTS |
350 printf("Checking %s\n", path); | 350 printf("Checking %s\n", path); |
351 #endif | 351 #endif |
352 if ( (i == 0) && ! EV_IsJoystick(fd) ) { | 352 if ( (i == 0) && ! EV_IsJoystick(fd) ) { |
353 close(fd); | 353 close(fd); |
364 } | 364 } |
365 } else | 365 } else |
366 break; | 366 break; |
367 } | 367 } |
368 | 368 |
369 #ifdef USE_INPUT_EVENTS | 369 #if SDL_INPUT_LINUXEV |
370 /* This is a special case... | 370 /* This is a special case... |
371 If the event devices are valid then the joystick devices | 371 If the event devices are valid then the joystick devices |
372 will be duplicates but without extra information about their | 372 will be duplicates but without extra information about their |
373 hats or balls. Unfortunately, the event devices can't | 373 hats or balls. Unfortunately, the event devices can't |
374 currently be calibrated, so it's a win-lose situation. | 374 currently be calibrated, so it's a win-lose situation. |
398 #endif | 398 #endif |
399 name = NULL; | 399 name = NULL; |
400 fd = open(SDL_joylist[index].fname, O_RDONLY, 0); | 400 fd = open(SDL_joylist[index].fname, O_RDONLY, 0); |
401 if ( fd >= 0 ) { | 401 if ( fd >= 0 ) { |
402 if ( | 402 if ( |
403 #ifdef USE_INPUT_EVENTS | 403 #if SDL_INPUT_LINUXEV |
404 (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) && | 404 (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) && |
405 #endif | 405 #endif |
406 (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0) ) { | 406 (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0) ) { |
407 name = SDL_joylist[index].fname; | 407 name = SDL_joylist[index].fname; |
408 } else { | 408 } else { |
538 } | 538 } |
539 | 539 |
540 return(handled); | 540 return(handled); |
541 } | 541 } |
542 | 542 |
543 #ifdef USE_INPUT_EVENTS | 543 #if SDL_INPUT_LINUXEV |
544 | 544 |
545 static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd) | 545 static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd) |
546 { | 546 { |
547 int i, t; | 547 int i, t; |
548 unsigned long keybit[40]; | 548 unsigned long keybit[40]; |
637 } | 637 } |
638 } | 638 } |
639 return(joystick->hwdata->is_hid); | 639 return(joystick->hwdata->is_hid); |
640 } | 640 } |
641 | 641 |
642 #endif /* USE_INPUT_EVENTS */ | 642 #endif /* SDL_INPUT_LINUXEV */ |
643 | 643 |
644 #ifndef NO_LOGICAL_JOYSTICKS | 644 #ifndef NO_LOGICAL_JOYSTICKS |
645 static void ConfigLogicalJoystick(SDL_Joystick *joystick) | 645 static void ConfigLogicalJoystick(SDL_Joystick *joystick) |
646 { | 646 { |
647 struct joystick_logical_layout* layout; | 647 struct joystick_logical_layout* layout; |
709 #ifndef NO_LOGICAL_JOYSTICKS | 709 #ifndef NO_LOGICAL_JOYSTICKS |
710 if (realjoy) | 710 if (realjoy) |
711 ConfigLogicalJoystick(joystick); | 711 ConfigLogicalJoystick(joystick); |
712 else | 712 else |
713 #endif | 713 #endif |
714 #ifdef USE_INPUT_EVENTS | 714 #if SDL_INPUT_LINUXEV |
715 if ( ! EV_ConfigJoystick(joystick, fd) ) | 715 if ( ! EV_ConfigJoystick(joystick, fd) ) |
716 #endif | 716 #endif |
717 JS_ConfigJoystick(joystick, fd); | 717 JS_ConfigJoystick(joystick, fd); |
718 | 718 |
719 return(0); | 719 return(0); |
912 break; | 912 break; |
913 } | 913 } |
914 } | 914 } |
915 } | 915 } |
916 } | 916 } |
917 #ifdef USE_INPUT_EVENTS | 917 #if SDL_INPUT_LINUXEV |
918 static __inline__ int EV_AxisCorrect(SDL_Joystick *joystick, int which, int value) | 918 static __inline__ int EV_AxisCorrect(SDL_Joystick *joystick, int which, int value) |
919 { | 919 { |
920 struct axis_correct *correct; | 920 struct axis_correct *correct; |
921 | 921 |
922 correct = &joystick->hwdata->abs_correct[which]; | 922 correct = &joystick->hwdata->abs_correct[which]; |
1014 break; | 1014 break; |
1015 } | 1015 } |
1016 } | 1016 } |
1017 } | 1017 } |
1018 } | 1018 } |
1019 #endif /* USE_INPUT_EVENTS */ | 1019 #endif /* SDL_INPUT_LINUXEV */ |
1020 | 1020 |
1021 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) | 1021 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) |
1022 { | 1022 { |
1023 int i; | 1023 int i; |
1024 | 1024 |
1025 #ifdef USE_INPUT_EVENTS | 1025 #if SDL_INPUT_LINUXEV |
1026 if ( joystick->hwdata->is_hid ) | 1026 if ( joystick->hwdata->is_hid ) |
1027 EV_HandleEvents(joystick); | 1027 EV_HandleEvents(joystick); |
1028 else | 1028 else |
1029 #endif | 1029 #endif |
1030 JS_HandleEvents(joystick); | 1030 JS_HandleEvents(joystick); |