cc68a136 |
1 | /* Title: USB Joystick library |
2 | Version 0.2 |
3 | Written by Puck2099 (puck2099@gmail.com), (c) 2006. |
4 | <http://www.gp32wip.com> |
5 | |
6 | If you use this library or a part of it, please, let it know. |
7 | |
8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Lesser General Public |
10 | License as published by the Free Software Foundation; either |
11 | version 2.1 of the License, or (at your option) any later version. |
12 | |
13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Lesser General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Lesser General Public |
19 | License along with this library; if not, write to the Free Software |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | */ |
22 | |
23 | #ifndef USBJOY_H |
24 | #define USBJOY_H |
25 | |
26 | /* notaz: my Logitech has different button layout, and I want it to match gptx's */ |
27 | typedef enum { |
28 | JOY_TYPE_GENERIC, |
29 | JOY_TYPE_LOGITECH |
30 | } joy_type; |
31 | |
32 | /* |
33 | Enumeration: Axes values |
34 | This enumeration contains shortcuts to the values used on axes. |
35 | |
36 | Constants: |
37 | JOYUP - Joystick Up |
38 | JOYDOWN - Joystick Down |
39 | JOYLEFT - Joystick Left |
40 | JOYRIGHT - Joystick Right |
41 | |
42 | See also: |
43 | <joy_getaxe> |
44 | */ |
45 | #define JOYUP (0) |
46 | #define JOYDOWN (1) |
47 | #define JOYLEFT (2) |
48 | #define JOYRIGHT (3) |
49 | |
50 | |
51 | /* |
52 | Struct: usbjoy |
53 | |
54 | Contains all Joystick needed information. |
55 | |
56 | Fields: |
57 | fd - File descriptor used. |
58 | name - Joystick's name. |
59 | device - /dev/input/jsX device. |
60 | numbuttons - Joystick's buttons. |
61 | numaxes - Joystick's axes. |
62 | numhats - Joystick's hats. |
63 | statebuttons - Current state of each button. |
64 | stateaxes - Current state of each direction. |
65 | */ |
66 | struct usbjoy { |
67 | int fd; |
68 | char name [128]; |
69 | char device [128]; |
70 | int numbuttons; |
71 | int numaxes; |
72 | int numhats; |
73 | int statebuttons[32]; |
74 | int stateaxes[4]; |
75 | joy_type type; |
76 | }; |
77 | |
78 | |
79 | /* |
80 | Function: joy_open |
81 | |
82 | Opens a USB joystick and fills its information. |
83 | |
84 | Parameters: |
85 | |
86 | joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick). |
87 | |
88 | Returns: |
89 | |
90 | Filled usbjoy structure. |
91 | */ |
92 | struct usbjoy * joy_open (int joynumber); |
93 | |
94 | |
95 | /* |
96 | Function: joy_name |
97 | |
98 | Returns Joystick's name. |
99 | |
100 | Parameters: |
101 | |
102 | joy - Selected joystick. |
103 | |
104 | Returns: |
105 | |
106 | Joystick's name or NULL if <usbjoy> struct is empty. |
107 | */ |
108 | char * joy_name (struct usbjoy * joy); |
109 | |
110 | |
111 | /* |
112 | Function: joy_device |
113 | |
114 | Returns Joystick's device. |
115 | |
116 | Parameters: |
117 | |
118 | joy - Selected joystick. |
119 | |
120 | Returns: |
121 | |
122 | Joystick's device or NULL if <usbjoy> struct is empty. |
123 | */ |
124 | char * joy_device (struct usbjoy * joy); |
125 | |
126 | /* |
127 | Function: joy_buttons |
128 | |
129 | Returns Joystick's buttons number. |
130 | |
131 | Parameters: |
132 | |
133 | joy - Selected joystick. |
134 | |
135 | Returns: |
136 | |
137 | Joystick's buttons or 0 if <usbjoy> struct is empty. |
138 | */ |
139 | int joy_buttons (struct usbjoy * joy); |
140 | |
141 | /* |
142 | Function: joy_axes |
143 | |
144 | Returns Joystick's axes number. |
145 | |
146 | Parameters: |
147 | |
148 | joy - Selected joystick. |
149 | |
150 | Returns: |
151 | |
152 | Joystick's axes or 0 if <usbjoy> struct is empty. |
153 | */ |
154 | int joy_axes (struct usbjoy * joy); |
155 | |
156 | |
157 | /* |
158 | Function: joy_update |
159 | |
160 | Updates Joystick's internal information (<statebuttons> and <stateaxes> fields). |
161 | |
162 | Parameters: |
163 | |
164 | joy - Selected joystick. |
165 | |
166 | Returns: |
167 | |
168 | 0 - No events registered (no need to update). |
169 | 1 - Events registered (a button or axe has been pushed). |
170 | -1 - Error: <usbjoy> struct is empty. |
171 | */ |
172 | int joy_update (struct usbjoy * joy); |
173 | |
174 | |
175 | /* |
176 | Function: joy_getbutton |
177 | |
178 | Returns Joystick's button information. |
179 | |
180 | Parameters: |
181 | |
182 | button - Button which value you want to know (from 0 to 31). |
183 | joy - Selected joystick. |
184 | |
185 | Returns: |
186 | |
187 | 0 - Button NOT pushed. |
188 | 1 - Button pushed. |
189 | -1 - Error: <usbjoy> struct is empty. |
190 | */ |
191 | int joy_getbutton (int button, struct usbjoy * joy); |
192 | |
193 | |
194 | /* |
195 | Function: joy_getaxe |
196 | |
197 | Returns Joystick's axes information. |
198 | |
199 | Parameters: |
200 | |
201 | axe - Axe which value you want to know (see <Axes values>). |
202 | joy - Selected joystick. |
203 | |
204 | Returns: |
205 | |
206 | 0 - Direction NOT pushed. |
207 | 1 - Direction pushed. |
208 | -1 - Error: <usbjoy> struct is empty. |
209 | */ |
210 | int joy_getaxe (int axe, struct usbjoy * joy); |
211 | |
212 | /* |
213 | Function: joy_close |
214 | |
215 | Closes selected joystick's file descriptor and detroys it's fields. |
216 | |
217 | Parameters: |
218 | |
219 | joy - Selected joystick. |
220 | |
221 | Returns: |
222 | |
223 | 0 - Joystick successfully closed. |
224 | -1 - Error: <usbjoy> struct is empty. |
225 | */ |
226 | int joy_close (struct usbjoy * joy); |
227 | |
228 | |
229 | |
230 | /* gp2x stuff */ |
231 | extern int num_of_joys; |
232 | extern struct usbjoy *joys[4]; |
233 | |
234 | void gp2x_usbjoy_update(void); |
235 | void gp2x_usbjoy_init(void); |
236 | int gp2x_usbjoy_check(int joyno); |
237 | int gp2x_usbjoy_check2(int joyno); |
238 | void gp2x_usbjoy_deinit(void); |
239 | |
240 | |
241 | #endif // USBJOY_H |