show controls gui
[drnoksnes] / usbjoy.h
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 /*
27   Enumeration: Axes values
28   This enumeration contains shortcuts to the values used on axes.
29   
30   Constants:
31   JOYUP    - Joystick Up
32   JOYDOWN  - Joystick Down
33   JOYLEFT  - Joystick Left
34   JOYRIGHT - Joystick Right
35
36   See also: 
37   <joy_getaxe>
38 */
39 #define JOYUP    (0)
40 #define JOYDOWN  (1)
41 #define JOYLEFT  (2)
42 #define JOYRIGHT (3)
43
44
45 /*
46   Struct: usbjoy
47
48   Contains all Joystick needed information.
49
50   Fields:
51   fd - File descriptor used.
52   name - Joystick's name.
53   device - /dev/input/jsX device.
54   numbuttons - Joystick's buttons.
55   numaxes - Joystick's axes.
56   numhats - Joystick's hats.
57   statebuttons - Current state of each button.
58   stateaxes - Current state of each direction.
59 */
60 struct usbjoy {
61   int fd;
62   char name [128];
63   char device [128];
64   int numbuttons;
65   int numaxes;
66   int numhats;
67   int statebuttons[32];
68   int stateaxes[4];
69 };
70
71
72 /*
73   Function: joy_open
74
75   Opens a USB joystick and fills its information.
76
77   Parameters:
78
79   joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
80
81   Returns:
82
83   Filled usbjoy structure.
84 */
85 struct usbjoy * joy_open (int joynumber);
86
87
88 /*
89   Function: joy_name
90
91   Returns Joystick's name.
92
93   Parameters:
94
95   joy - Selected joystick.
96
97   Returns:
98
99   Joystick's name or NULL if <usbjoy> struct is empty.
100 */
101 char * joy_name (struct usbjoy * joy);
102
103
104 /*
105   Function: joy_device
106
107   Returns Joystick's device.
108
109   Parameters:
110
111   joy - Selected joystick.
112
113   Returns:
114
115   Joystick's device or NULL if <usbjoy> struct is empty.
116 */
117 char * joy_device (struct usbjoy * joy);
118
119 /*
120   Function: joy_buttons
121
122   Returns Joystick's buttons number.
123
124   Parameters:
125
126   joy - Selected joystick.
127
128   Returns:
129
130   Joystick's buttons or 0 if <usbjoy> struct is empty.
131 */
132 int joy_buttons (struct usbjoy * joy);
133
134 /*
135   Function: joy_axes
136
137   Returns Joystick's axes number.
138
139   Parameters:
140
141   joy - Selected joystick.
142
143   Returns:
144
145   Joystick's axes or 0 if <usbjoy> struct is empty.
146 */
147 int joy_axes (struct usbjoy * joy);
148
149
150 /*
151   Function: joy_update
152
153   Updates Joystick's internal information (<statebuttons> and <stateaxes> fields).
154
155   Parameters:
156
157   joy - Selected joystick.
158
159   Returns:
160
161   0 - No events registered (no need to update).
162   1 - Events registered (a button or axe has been pushed).
163   -1 - Error: <usbjoy> struct is empty.
164 */
165 int joy_update (struct usbjoy * joy);
166
167
168 /*
169   Function: joy_getbutton
170
171   Returns Joystick's button information.
172
173   Parameters:
174
175   button - Button which value you want to know (from 0 to 31).
176   joy - Selected joystick.
177
178   Returns:
179
180   0 - Button NOT pushed.
181   1 - Button pushed.
182   -1 - Error: <usbjoy> struct is empty.
183 */
184 int joy_getbutton (int button, struct usbjoy * joy);
185
186
187 /*
188   Function: joy_getaxe
189
190   Returns Joystick's axes information.
191
192   Parameters:
193
194   axe - Axe which value you want to know (see <Axes values>).
195   joy - Selected joystick.
196
197   Returns:
198
199   0 - Direction NOT pushed.
200   1 - Direction pushed.
201   -1 - Error: <usbjoy> struct is empty.
202 */
203 int joy_getaxe (int axe, struct usbjoy * joy);
204
205 /*
206   Function: joy_close
207
208   Closes selected joystick's file descriptor and detroys it's fields.
209
210   Parameters:
211
212   joy - Selected joystick.
213
214   Returns:
215
216   0 - Joystick successfully closed.
217   -1 - Error: <usbjoy> struct is empty.
218 */
219 int joy_close (struct usbjoy * joy);
220
221 #endif // USBJOY_H