Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
130 | ligi | 1 | |
2 | int connect_joy() |
||
3 | { |
||
4 | |||
5 | axis = (int *) calloc( 100, sizeof( int ) ); |
||
6 | button = (char *)calloc( 100, sizeof( char ) ); |
||
7 | button_trigger = (char *) calloc( 100, sizeof( char ) ); |
||
8 | |||
9 | |||
10 | // axis = (int *) calloc( num_of_axis, sizeof( int ) ); |
||
11 | // button = (char *)calloc( num_of_buttons, sizeof( char ) ); |
||
12 | // button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) ); |
||
13 | |||
14 | |||
15 | if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
||
16 | { |
||
17 | printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
||
18 | printf( "try modprobe joydev\n" ); |
||
19 | return 0; |
||
20 | } |
||
21 | |||
22 | ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis ); |
||
23 | ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons ); |
||
24 | ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick ); |
||
25 | |||
26 | printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n" |
||
27 | , name_of_joystick |
||
28 | , num_of_axis |
||
29 | , num_of_buttons ); |
||
30 | |||
31 | fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */ |
||
32 | |||
33 | return 1; |
||
34 | } |