1 | #include "joy.hpp" |
---|
2 | #include <stdio.h> |
---|
3 | #include <fcntl.h> |
---|
4 | #include <unistd.h> |
---|
5 | #include <sys/ioctl.h> |
---|
6 | #include <errno.h> |
---|
7 | //#include <linux/joystick.h> |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | int joy_fd=-1,joy_centx=863,joy_centy=705; |
---|
12 | |
---|
13 | |
---|
14 | int joy_init(int argc, char **argv) |
---|
15 | { |
---|
16 | return 0; |
---|
17 | /* int i,timeout; |
---|
18 | char *joy_dev="/dev/js0"; |
---|
19 | |
---|
20 | // see if the user specefied a different joy stick device to use |
---|
21 | |
---|
22 | for (i=1;i<argc;i++) |
---|
23 | { |
---|
24 | if (!strcmp(argv[i],"-joy_dev")) |
---|
25 | { |
---|
26 | i++; |
---|
27 | joy_dev=argv[i]; |
---|
28 | } else if (!strcmp(argv[i],"-joy")) |
---|
29 | joy_dev="/dev/js0"; |
---|
30 | else if (!strcmp(argv[i],"-joy2")) |
---|
31 | joy_dev="/dev/js1"; |
---|
32 | else if (!strcmp(argv[i],"-nojoy")) |
---|
33 | return 0; |
---|
34 | |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | if (!strcmp(joy_dev,"none")) // they asked not to have one! |
---|
39 | return 0; |
---|
40 | joy_fd=open(joy_dev,O_RDONLY); |
---|
41 | |
---|
42 | if (joy_fd<0) |
---|
43 | { |
---|
44 | printf("No joystick detected at %s (apply joystick patch)\n",joy_dev); |
---|
45 | return 0; // I guess they don't have one |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | timeout=10; |
---|
50 | |
---|
51 | ioctl (joy_fd, JS_SET_TIMELIMIT, &timeout); |
---|
52 | return 1; */ |
---|
53 | } |
---|
54 | |
---|
55 | void joy_status(int &b1, int &b2, int &b3, int &xv, int &yv) |
---|
56 | { |
---|
57 | /* if (joy_fd>=0) |
---|
58 | { |
---|
59 | struct JS_DATA_TYPE j; |
---|
60 | read(joy_fd,&j,sizeof(JS_DATA_TYPE)); |
---|
61 | b1=(j.buttons&1) ? 1 : 0; |
---|
62 | b2=(j.buttons&2) ? 1 : 0; |
---|
63 | b3=0; |
---|
64 | xv=(j.x-joy_centx)*2/joy_centx; |
---|
65 | yv=(j.y-joy_centy)*2/joy_centy; |
---|
66 | } else xv=yv=b1=b2=b3=0; */ |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | void joy_calibrate() |
---|
71 | { |
---|
72 | /* if (joy_fd>=0) |
---|
73 | { |
---|
74 | struct JS_DATA_TYPE j; |
---|
75 | read(joy_fd,&j,sizeof(JS_DATA_TYPE)); |
---|
76 | joy_centx=j.x; |
---|
77 | joy_centy=j.y; |
---|
78 | if (joy_centx==0) joy_centx=1; // can't dvide by 0 |
---|
79 | if (joy_centy==0) joy_centy=1; // can't dvide by 0 |
---|
80 | } */ |
---|
81 | } |
---|