Mercurial > sdl-ios-xcode
comparison src/joystick/SDL_joystick.c @ 2489:96adc8025331 gsoc2008_force_feedback
Exposed some of the joystick stuff to the haptic subsystem.
Added SDL_JoystickIsHaptic().
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Wed, 02 Jul 2008 08:24:35 +0000 |
parents | c121d94672cb |
children | 99210400e8b9 |
comparison
equal
deleted
inserted
replaced
2488:8e2bdbccf7ff | 2489:96adc8025331 |
---|---|
191 } | 191 } |
192 } | 192 } |
193 return (opened); | 193 return (opened); |
194 } | 194 } |
195 | 195 |
196 static int | 196 |
197 ValidJoystick(SDL_Joystick ** joystick) | 197 /* |
198 * Checks to make sure the joystick is valid. | |
199 */ | |
200 int | |
201 SDL_PrivateJoystickValid(SDL_Joystick ** joystick) | |
198 { | 202 { |
199 int valid; | 203 int valid; |
200 | 204 |
201 if (*joystick == NULL) { | 205 if (*joystick == NULL) { |
202 *joystick = default_joystick; | 206 *joystick = default_joystick; |
214 * Get the device index of an opened joystick. | 218 * Get the device index of an opened joystick. |
215 */ | 219 */ |
216 int | 220 int |
217 SDL_JoystickIndex(SDL_Joystick * joystick) | 221 SDL_JoystickIndex(SDL_Joystick * joystick) |
218 { | 222 { |
219 if (!ValidJoystick(&joystick)) { | 223 if (!SDL_PrivateJoystickValid(&joystick)) { |
220 return (-1); | 224 return (-1); |
221 } | 225 } |
222 return (joystick->index); | 226 return (joystick->index); |
223 } | 227 } |
224 | 228 |
226 * Get the number of multi-dimensional axis controls on a joystick | 230 * Get the number of multi-dimensional axis controls on a joystick |
227 */ | 231 */ |
228 int | 232 int |
229 SDL_JoystickNumAxes(SDL_Joystick * joystick) | 233 SDL_JoystickNumAxes(SDL_Joystick * joystick) |
230 { | 234 { |
231 if (!ValidJoystick(&joystick)) { | 235 if (!SDL_PrivateJoystickValid(&joystick)) { |
232 return (-1); | 236 return (-1); |
233 } | 237 } |
234 return (joystick->naxes); | 238 return (joystick->naxes); |
235 } | 239 } |
236 | 240 |
238 * Get the number of hats on a joystick | 242 * Get the number of hats on a joystick |
239 */ | 243 */ |
240 int | 244 int |
241 SDL_JoystickNumHats(SDL_Joystick * joystick) | 245 SDL_JoystickNumHats(SDL_Joystick * joystick) |
242 { | 246 { |
243 if (!ValidJoystick(&joystick)) { | 247 if (!SDL_PrivateJoystickValid(&joystick)) { |
244 return (-1); | 248 return (-1); |
245 } | 249 } |
246 return (joystick->nhats); | 250 return (joystick->nhats); |
247 } | 251 } |
248 | 252 |
250 * Get the number of trackballs on a joystick | 254 * Get the number of trackballs on a joystick |
251 */ | 255 */ |
252 int | 256 int |
253 SDL_JoystickNumBalls(SDL_Joystick * joystick) | 257 SDL_JoystickNumBalls(SDL_Joystick * joystick) |
254 { | 258 { |
255 if (!ValidJoystick(&joystick)) { | 259 if (!SDL_PrivateJoystickValid(&joystick)) { |
256 return (-1); | 260 return (-1); |
257 } | 261 } |
258 return (joystick->nballs); | 262 return (joystick->nballs); |
259 } | 263 } |
260 | 264 |
262 * Get the number of buttons on a joystick | 266 * Get the number of buttons on a joystick |
263 */ | 267 */ |
264 int | 268 int |
265 SDL_JoystickNumButtons(SDL_Joystick * joystick) | 269 SDL_JoystickNumButtons(SDL_Joystick * joystick) |
266 { | 270 { |
267 if (!ValidJoystick(&joystick)) { | 271 if (!SDL_PrivateJoystickValid(&joystick)) { |
268 return (-1); | 272 return (-1); |
269 } | 273 } |
270 return (joystick->nbuttons); | 274 return (joystick->nbuttons); |
271 } | 275 } |
272 | 276 |
276 Sint16 | 280 Sint16 |
277 SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis) | 281 SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis) |
278 { | 282 { |
279 Sint16 state; | 283 Sint16 state; |
280 | 284 |
281 if (!ValidJoystick(&joystick)) { | 285 if (!SDL_PrivateJoystickValid(&joystick)) { |
282 return (0); | 286 return (0); |
283 } | 287 } |
284 if (axis < joystick->naxes) { | 288 if (axis < joystick->naxes) { |
285 state = joystick->axes[axis]; | 289 state = joystick->axes[axis]; |
286 } else { | 290 } else { |
296 Uint8 | 300 Uint8 |
297 SDL_JoystickGetHat(SDL_Joystick * joystick, int hat) | 301 SDL_JoystickGetHat(SDL_Joystick * joystick, int hat) |
298 { | 302 { |
299 Uint8 state; | 303 Uint8 state; |
300 | 304 |
301 if (!ValidJoystick(&joystick)) { | 305 if (!SDL_PrivateJoystickValid(&joystick)) { |
302 return (0); | 306 return (0); |
303 } | 307 } |
304 if (hat < joystick->nhats) { | 308 if (hat < joystick->nhats) { |
305 state = joystick->hats[hat]; | 309 state = joystick->hats[hat]; |
306 } else { | 310 } else { |
316 int | 320 int |
317 SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy) | 321 SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy) |
318 { | 322 { |
319 int retval; | 323 int retval; |
320 | 324 |
321 if (!ValidJoystick(&joystick)) { | 325 if (!SDL_PrivateJoystickValid(&joystick)) { |
322 return (-1); | 326 return (-1); |
323 } | 327 } |
324 | 328 |
325 retval = 0; | 329 retval = 0; |
326 if (ball < joystick->nballs) { | 330 if (ball < joystick->nballs) { |
345 Uint8 | 349 Uint8 |
346 SDL_JoystickGetButton(SDL_Joystick * joystick, int button) | 350 SDL_JoystickGetButton(SDL_Joystick * joystick, int button) |
347 { | 351 { |
348 Uint8 state; | 352 Uint8 state; |
349 | 353 |
350 if (!ValidJoystick(&joystick)) { | 354 if (!SDL_PrivateJoystickValid(&joystick)) { |
351 return (0); | 355 return (0); |
352 } | 356 } |
353 if (button < joystick->nbuttons) { | 357 if (button < joystick->nbuttons) { |
354 state = joystick->buttons[button]; | 358 state = joystick->buttons[button]; |
355 } else { | 359 } else { |
365 void | 369 void |
366 SDL_JoystickClose(SDL_Joystick * joystick) | 370 SDL_JoystickClose(SDL_Joystick * joystick) |
367 { | 371 { |
368 int i; | 372 int i; |
369 | 373 |
370 if (!ValidJoystick(&joystick)) { | 374 if (!SDL_PrivateJoystickValid(&joystick)) { |
371 return; | 375 return; |
372 } | 376 } |
373 | 377 |
374 /* First decrement ref count */ | 378 /* First decrement ref count */ |
375 if (--joystick->ref_count > 0) { | 379 if (--joystick->ref_count > 0) { |