SDL  2.0
SDL_joystick.h File Reference
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_joystick.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_JoystickGUID
 

Macros

Hat positions
#define SDL_HAT_CENTERED   0x00
 
#define SDL_HAT_UP   0x01
 
#define SDL_HAT_RIGHT   0x02
 
#define SDL_HAT_DOWN   0x04
 
#define SDL_HAT_LEFT   0x08
 
#define SDL_HAT_RIGHTUP   (SDL_HAT_RIGHT|SDL_HAT_UP)
 
#define SDL_HAT_RIGHTDOWN   (SDL_HAT_RIGHT|SDL_HAT_DOWN)
 
#define SDL_HAT_LEFTUP   (SDL_HAT_LEFT|SDL_HAT_UP)
 
#define SDL_HAT_LEFTDOWN   (SDL_HAT_LEFT|SDL_HAT_DOWN)
 

Typedefs

typedef Sint32 SDL_JoystickID
 

Enumerations

enum  SDL_JoystickPowerLevel {
  SDL_JOYSTICK_POWER_UNKNOWN = -1,
  SDL_JOYSTICK_POWER_EMPTY,
  SDL_JOYSTICK_POWER_LOW,
  SDL_JOYSTICK_POWER_MEDIUM,
  SDL_JOYSTICK_POWER_FULL,
  SDL_JOYSTICK_POWER_WIRED,
  SDL_JOYSTICK_POWER_MAX
}
 

Functions

int SDL_NumJoysticks (void)
 
const char * SDL_JoystickNameForIndex (int device_index)
 
SDL_Joystick * SDL_JoystickOpen (int device_index)
 
SDL_Joystick * SDL_JoystickFromInstanceID (SDL_JoystickID joyid)
 
const char * SDL_JoystickName (SDL_Joystick *joystick)
 
SDL_JoystickGUID SDL_JoystickGetDeviceGUID (int device_index)
 
SDL_JoystickGUID SDL_JoystickGetGUID (SDL_Joystick *joystick)
 
void SDL_JoystickGetGUIDString (SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
 
SDL_JoystickGUID SDL_JoystickGetGUIDFromString (const char *pchGUID)
 
SDL_bool SDL_JoystickGetAttached (SDL_Joystick *joystick)
 
SDL_JoystickID SDL_JoystickInstanceID (SDL_Joystick *joystick)
 
int SDL_JoystickNumAxes (SDL_Joystick *joystick)
 
int SDL_JoystickNumBalls (SDL_Joystick *joystick)
 
int SDL_JoystickNumHats (SDL_Joystick *joystick)
 
int SDL_JoystickNumButtons (SDL_Joystick *joystick)
 
void SDL_JoystickUpdate (void)
 
int SDL_JoystickEventState (int state)
 
Sint16 SDL_JoystickGetAxis (SDL_Joystick *joystick, int axis)
 
Uint8 SDL_JoystickGetHat (SDL_Joystick *joystick, int hat)
 
int SDL_JoystickGetBall (SDL_Joystick *joystick, int ball, int *dx, int *dy)
 
Uint8 SDL_JoystickGetButton (SDL_Joystick *joystick, int button)
 
void SDL_JoystickClose (SDL_Joystick *joystick)
 
SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel (SDL_Joystick *joystick)
 

Detailed Description

Include file for SDL joystick event handling

The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick behind a device_index changing as joysticks are plugged and unplugged.

The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.

The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of the device (a X360 wired controller for example). This identifier is platform dependent.

In order to use these functions, SDL_Init() must have been called with the SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks, and load appropriate drivers.

If you would like to receive joystick updates while the application is in the background, you should set the following hint before calling SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS

Definition in file SDL_joystick.h.

Macro Definition Documentation

§ SDL_HAT_CENTERED

§ SDL_HAT_DOWN

#define SDL_HAT_DOWN   0x04

§ SDL_HAT_LEFT

#define SDL_HAT_LEFT   0x08

§ SDL_HAT_LEFTDOWN

#define SDL_HAT_LEFTDOWN   (SDL_HAT_LEFT|SDL_HAT_DOWN)

Definition at line 215 of file SDL_joystick.h.

Referenced by SDLTest_PrintEvent().

§ SDL_HAT_LEFTUP

#define SDL_HAT_LEFTUP   (SDL_HAT_LEFT|SDL_HAT_UP)

Definition at line 214 of file SDL_joystick.h.

Referenced by SDLTest_PrintEvent().

§ SDL_HAT_RIGHT

#define SDL_HAT_RIGHT   0x02

§ SDL_HAT_RIGHTDOWN

#define SDL_HAT_RIGHTDOWN   (SDL_HAT_RIGHT|SDL_HAT_DOWN)

Definition at line 213 of file SDL_joystick.h.

Referenced by SDLTest_PrintEvent().

§ SDL_HAT_RIGHTUP

#define SDL_HAT_RIGHTUP   (SDL_HAT_RIGHT|SDL_HAT_UP)

Definition at line 212 of file SDL_joystick.h.

Referenced by SDLTest_PrintEvent().

§ SDL_HAT_UP

#define SDL_HAT_UP   0x01

Typedef Documentation

§ SDL_JoystickID

SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 return SDL_AudioCVT SDL_AudioFormat Uint8 int SDL_AudioFormat Uint8 int return Uint8 const Uint8 Uint32 int const char return return return return return return return return Uint32 return Uint32 SDL_Event return SDL_Event int return SDL_EventFilter void SDL_EventFilter void SDL_EventFilter void int return const char const char return SDL_JoystickGUID return int return int return SDL_GameController return int return const char return SDL_GameController SDL_GameControllerAxis return const char return SDL_GameController SDL_GameControllerButton return SDL_GameController SDL_RWops return SDL_TouchID SDL_RWops return int return int return return SDL_Joystick return SDL_Haptic SDL_Haptic return SDL_Haptic return SDL_Haptic SDL_HapticEffect return SDL_Haptic int Uint32 return SDL_Haptic int SDL_Haptic int return SDL_Haptic return SDL_Haptic return SDL_Haptic return SDL_Haptic return const char const char return const char SDL_HintCallback void int return SDL_Joystick return SDL_Joystick return const char return SDL_Joystick return SDL_Joystick return SDL_Joystick return int return SDL_Joystick int return SDL_Joystick int return return return SDL_Scancode return SDL_Scancode return SDL_Keycode return return const char return void int SDL_LogPriority SDL_LogOutputFunction void Uint32 const char const char SDL_Window return int int return SDL_Window int int return SDL_Surface int int return SDL_Cursor return int return SDL_mutex return SDL_mutex return Uint32 return SDL_sem return SDL_sem Uint32 return SDL_sem return SDL_cond SDL_cond return SDL_cond SDL_mutex Uint32 return Uint32 int Uint32 Uint32 Uint32 Uint32 return Uint32 return int return SDL_Palette const SDL_Color int int return const SDL_PixelFormat Uint8 Uint8 Uint8 return Uint32 const SDL_PixelFormat Uint8 Uint8 Uint8 float Uint16 int int return const SDL_Rect const SDL_Rect SDL_Rect return const SDL_Point int const SDL_Rect SDL_Rect return return int int Uint32 SDL_Window SDL_Renderer return SDL_Surface return SDL_Renderer SDL_RendererInfo return SDL_Renderer Uint32 int int int return SDL_Texture Uint32 int int int return SDL_Texture Uint8 Uint8 Uint8 return SDL_Texture Uint8 return SDL_Texture SDL_BlendMode return SDL_Texture const SDL_Rect const Uint8 int const Uint8 int const Uint8 int return SDL_Texture SDL_Renderer SDL_Texture return SDL_Renderer int int return SDL_Renderer const SDL_Rect return SDL_Renderer const SDL_Rect return SDL_Renderer float float return SDL_Renderer Uint8 Uint8 Uint8 Uint8 return SDL_Renderer SDL_BlendMode return SDL_Renderer return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Rect int return SDL_Renderer const SDL_Rect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_Rect const double const SDL_Point const SDL_RendererFlip return SDL_Renderer SDL_Renderer SDL_Texture return void int return return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops Uint16 return SDL_RWops Uint32 return SDL_RWops Uint64 return const char unsigned int unsigned int unsigned int unsigned int Uint32 return SDL_Window SDL_Surface SDL_WindowShapeMode return size_t return void size_t return const char return void size_t size_t int(*) a int return int return int size_t return size_t return const wchar_t return const wchar_t size_t return const char size_t return const char size_t return char return char return const char int return int char int return long char int return Sint64 char int return const char return const char char int return const char char int return const char char return const char const char size_t return const char const char size_t return double return double return double return double return double return double return double int return float return const char const char return SDL_iconv_t const char size_t char size_t return Uint32 int int int Uint32 Uint32 Uint32 Uint32 return SDL_Surface SDL_Surface return SDL_RWops int return SDL_Surface int return SDL_Surface Uint32 return SDL_Surface Uint8 Uint8 Uint8 return SDL_Surface Uint8 return SDL_Surface SDL_BlendMode return SDL_Surface SDL_Rect SDL_Surface Uint32 Uint32 return SDL_Surface const SDL_Rect Uint32 return SDL_Surface const SDL_Rect SDL_Surface SDL_Rect return SDL_Surface const SDL_Rect SDL_Surface const SDL_Rect return SDL_Surface SDL_Rect SDL_Surface SDL_Rect return SDL_Thread return SDL_Thread return SDL_Thread int return SDL_TLSID const void void(*) return return Uint32 SDL_TimerID return int return SDL_TouchID int return return return const char return return int return int return int SDL_DisplayMode return int const SDL_DisplayMode SDL_DisplayMode return SDL_Window const SDL_DisplayMode return SDL_Window return const void return Uint32 return SDL_Window const char SDL_Window SDL_Surface SDL_Window const char return SDL_Window int int SDL_Window int int SDL_Window int int SDL_Window int int SDL_Window SDL_Window SDL_Window SDL_Window Uint32 return SDL_Window return SDL_Window SDL_bool SDL_Window float return SDL_Window const Uint16 const Uint16 const Uint16 return SDL_Window const char return SDL_GLattr int return SDL_Window return return SDL_Window int int return SDL_GLContext SDL_RWops int return return void return int int return double return SDL_bool return int int return SDL_AudioDeviceID const void Uint32 return SDL_AudioDeviceID int float float float return SDL_JoystickID

Definition at line 72 of file SDL_joystick.h.

Enumeration Type Documentation

§ SDL_JoystickPowerLevel

Enumerator
SDL_JOYSTICK_POWER_UNKNOWN 
SDL_JOYSTICK_POWER_EMPTY 
SDL_JOYSTICK_POWER_LOW 
SDL_JOYSTICK_POWER_MEDIUM 
SDL_JOYSTICK_POWER_FULL 
SDL_JOYSTICK_POWER_WIRED 
SDL_JOYSTICK_POWER_MAX 

Definition at line 74 of file SDL_joystick.h.

Function Documentation

§ SDL_JoystickClose()

void SDL_JoystickClose ( SDL_Joystick *  joystick)

Close a joystick previously opened with SDL_JoystickOpen().

Definition at line 411 of file SDL_joystick.c.

References NULL, SDL_free(), SDL_joysticks, SDL_SYS_JoystickClose(), and SDL_updating_joystick.

Referenced by SDL_JoystickOpen(), SDL_JoystickQuit(), and SDL_JoystickUpdate().

412 {
413  SDL_Joystick *joysticklist;
414  SDL_Joystick *joysticklistprev;
415 
416  if (!joystick) {
417  return;
418  }
419 
420  /* First decrement ref count */
421  if (--joystick->ref_count > 0) {
422  return;
423  }
424 
425  if (joystick == SDL_updating_joystick) {
426  return;
427  }
428 
429  SDL_SYS_JoystickClose(joystick);
430  joystick->hwdata = NULL;
431 
432  joysticklist = SDL_joysticks;
433  joysticklistprev = NULL;
434  while (joysticklist) {
435  if (joystick == joysticklist) {
436  if (joysticklistprev) {
437  /* unlink this entry */
438  joysticklistprev->next = joysticklist->next;
439  } else {
440  SDL_joysticks = joystick->next;
441  }
442  break;
443  }
444  joysticklistprev = joysticklist;
445  joysticklist = joysticklist->next;
446  }
447 
448  SDL_free(joystick->name);
449 
450  /* Free the data associated with this joystick */
451  SDL_free(joystick->axes);
452  SDL_free(joystick->hats);
453  SDL_free(joystick->balls);
454  SDL_free(joystick->buttons);
455  SDL_free(joystick);
456 }
static SDL_Joystick * SDL_updating_joystick
Definition: SDL_joystick.c:37
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:143
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

§ SDL_JoystickCurrentPowerLevel()

SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel ( SDL_Joystick *  joystick)

Return the battery level of this joystick

Definition at line 920 of file SDL_joystick.c.

References SDL_JOYSTICK_POWER_UNKNOWN, and SDL_PrivateJoystickValid().

921 {
922  if (!SDL_PrivateJoystickValid(joystick)) {
924  }
925  return joystick->epowerlevel;
926 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200

§ SDL_JoystickEventState()

int SDL_JoystickEventState ( int  state)

Enable/disable joystick event polling.

If joystick events are disabled, you must call SDL_JoystickUpdate() yourself and check the state of the joystick when you want joystick information.

The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.

Definition at line 788 of file SDL_joystick.c.

References i, SDL_arraysize, SDL_DISABLE, SDL_ENABLE, SDL_EventState, SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED, SDL_JOYHATMOTION, and SDL_QUERY.

789 {
790 #if SDL_EVENTS_DISABLED
791  return SDL_DISABLE;
792 #else
793  const Uint32 event_list[] = {
796  };
797  unsigned int i;
798 
799  switch (state) {
800  case SDL_QUERY:
801  state = SDL_DISABLE;
802  for (i = 0; i < SDL_arraysize(event_list); ++i) {
803  state = SDL_EventState(event_list[i], SDL_QUERY);
804  if (state == SDL_ENABLE) {
805  break;
806  }
807  }
808  break;
809  default:
810  for (i = 0; i < SDL_arraysize(event_list); ++i) {
811  SDL_EventState(event_list[i], state);
812  }
813  break;
814  }
815  return (state);
816 #endif /* SDL_EVENTS_DISABLED */
817 }
struct xkb_state * state
#define SDL_ENABLE
Definition: SDL_events.h:722
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_DISABLE
Definition: SDL_events.h:721
#define SDL_EventState
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:90
#define SDL_QUERY
Definition: SDL_events.h:719

§ SDL_JoystickFromInstanceID()

SDL_Joystick* SDL_JoystickFromInstanceID ( SDL_JoystickID  joyid)

Return the SDL_Joystick associated with an instance id.

Definition at line 381 of file SDL_joystick.c.

References NULL, and SDL_joysticks.

382 {
383  SDL_Joystick *joystick = SDL_joysticks;
384  while (joystick) {
385  if (joystick->instance_id == joyid) {
386  return joystick;
387  }
388  joystick = joystick->next;
389  }
390 
391  return NULL;
392 }
#define NULL
Definition: begin_code.h:143
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

§ SDL_JoystickGetAttached()

SDL_bool SDL_JoystickGetAttached ( SDL_Joystick *  joystick)

Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.

Definition at line 355 of file SDL_joystick.c.

References SDL_FALSE, SDL_PrivateJoystickValid(), and SDL_SYS_JoystickAttached().

356 {
357  if (!SDL_PrivateJoystickValid(joystick)) {
358  return SDL_FALSE;
359  }
360 
361  return SDL_SYS_JoystickAttached(joystick);
362 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)

§ SDL_JoystickGetAxis()

Sint16 SDL_JoystickGetAxis ( SDL_Joystick *  joystick,
int  axis 
)

Get the current state of an axis control on a joystick.

The state is a value ranging from -32768 to 32767.

The axis indices start at index 0.

Definition at line 266 of file SDL_joystick.c.

References axis, SDL_PrivateJoystickValid(), SDL_SetError, and state.

267 {
268  Sint16 state;
269 
270  if (!SDL_PrivateJoystickValid(joystick)) {
271  return (0);
272  }
273  if (axis < joystick->naxes) {
274  state = joystick->axes[axis];
275  } else {
276  SDL_SetError("Joystick only has %d axes", joystick->naxes);
277  state = 0;
278  }
279  return (state);
280 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200
struct xkb_state * state
SDL_Texture * axis
#define SDL_SetError
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:147

§ SDL_JoystickGetBall()

int SDL_JoystickGetBall ( SDL_Joystick *  joystick,
int  ball,
int *  dx,
int *  dy 
)

Get the ball axis change since the last poll.

Returns
0, or -1 if you passed it invalid parameters.

The ball indices start at index 0.

Definition at line 306 of file SDL_joystick.c.

References retval, SDL_PrivateJoystickValid(), and SDL_SetError.

307 {
308  int retval;
309 
310  if (!SDL_PrivateJoystickValid(joystick)) {
311  return (-1);
312  }
313 
314  retval = 0;
315  if (ball < joystick->nballs) {
316  if (dx) {
317  *dx = joystick->balls[ball].dx;
318  }
319  if (dy) {
320  *dy = joystick->balls[ball].dy;
321  }
322  joystick->balls[ball].dx = 0;
323  joystick->balls[ball].dy = 0;
324  } else {
325  return SDL_SetError("Joystick only has %d balls", joystick->nballs);
326  }
327  return (retval);
328 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200
SDL_bool retval
#define SDL_SetError

§ SDL_JoystickGetButton()

Uint8 SDL_JoystickGetButton ( SDL_Joystick *  joystick,
int  button 
)

Get the current state of a button on a joystick.

The button indices start at index 0.

Definition at line 334 of file SDL_joystick.c.

References button, SDL_PrivateJoystickValid(), SDL_SetError, and state.

335 {
336  Uint8 state;
337 
338  if (!SDL_PrivateJoystickValid(joystick)) {
339  return (0);
340  }
341  if (button < joystick->nbuttons) {
342  state = joystick->buttons[button];
343  } else {
344  SDL_SetError("Joystick only has %d buttons", joystick->nbuttons);
345  state = 0;
346  }
347  return (state);
348 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200
SDL_Texture * button
struct xkb_state * state
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
#define SDL_SetError

§ SDL_JoystickGetDeviceGUID()

SDL_JoystickGUID SDL_JoystickGetDeviceGUID ( int  device_index)

Return the GUID for the joystick at this index

Definition at line 820 of file SDL_joystick.c.

References SDL_NumJoysticks(), SDL_SetError, SDL_SYS_JoystickGetDeviceGUID(), and SDL_zero.

821 {
822  if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
823  SDL_JoystickGUID emptyGUID;
824  SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
825  SDL_zero(emptyGUID);
826  return emptyGUID;
827  }
828  return SDL_SYS_JoystickGetDeviceGUID(device_index);
829 }
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:75
#define SDL_zero(x)
Definition: SDL_stdinc.h:359
#define SDL_SetError
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)

§ SDL_JoystickGetGUID()

SDL_JoystickGUID SDL_JoystickGetGUID ( SDL_Joystick *  joystick)

Return the GUID for this opened joystick

Definition at line 832 of file SDL_joystick.c.

References SDL_PrivateJoystickValid(), SDL_SYS_JoystickGetGUID(), and SDL_zero.

833 {
834  if (!SDL_PrivateJoystickValid(joystick)) {
835  SDL_JoystickGUID emptyGUID;
836  SDL_zero(emptyGUID);
837  return emptyGUID;
838  }
839  return SDL_SYS_JoystickGetGUID(joystick);
840 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200
#define SDL_zero(x)
Definition: SDL_stdinc.h:359
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)

§ SDL_JoystickGetGUIDFromString()

SDL_JoystickGUID SDL_JoystickGetGUIDFromString ( const char *  pchGUID)

convert a string into a joystick formatted guid

Definition at line 890 of file SDL_joystick.c.

References i, nibble(), SDL_memset, and SDL_strlen.

891 {
892  SDL_JoystickGUID guid;
893  int maxoutputbytes= sizeof(guid);
894  size_t len = SDL_strlen(pchGUID);
895  Uint8 *p;
896  size_t i;
897 
898  /* Make sure it's even */
899  len = (len) & ~0x1;
900 
901  SDL_memset(&guid, 0x00, sizeof(guid));
902 
903  p = (Uint8 *)&guid;
904  for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i+=2, p++) {
905  *p = (nibble(pchGUID[i]) << 4) | nibble(pchGUID[i+1]);
906  }
907 
908  return guid;
909 }
GLuint GLfloat GLfloat GLfloat x1
GLfloat GLfloat p
GLenum GLsizei len
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
static unsigned char nibble(char c)
Definition: SDL_joystick.c:869
#define SDL_strlen
#define SDL_memset

§ SDL_JoystickGetGUIDString()

void SDL_JoystickGetGUIDString ( SDL_JoystickGUID  guid,
char *  pszGUID,
int  cbGUID 
)

Return a string representation for this guid. pszGUID must point to at least 33 bytes (32 for the string plus a NULL terminator).

Definition at line 843 of file SDL_joystick.c.

References SDL_JoystickGUID::data, i, and NULL.

844 {
845  static const char k_rgchHexToASCII[] = "0123456789abcdef";
846  int i;
847 
848  if ((pszGUID == NULL) || (cbGUID <= 0)) {
849  return;
850  }
851 
852  for (i = 0; i < sizeof(guid.data) && i < (cbGUID-1)/2; i++) {
853  /* each input byte writes 2 ascii chars, and might write a null byte. */
854  /* If we don't have room for next input byte, stop */
855  unsigned char c = guid.data[i];
856 
857  *pszGUID++ = k_rgchHexToASCII[c >> 4];
858  *pszGUID++ = k_rgchHexToASCII[c & 0x0F];
859  }
860  *pszGUID = '\0';
861 }
Uint8 data[16]
Definition: SDL_joystick.h:69
const GLubyte * c
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:143

§ SDL_JoystickGetHat()

Uint8 SDL_JoystickGetHat ( SDL_Joystick *  joystick,
int  hat 
)

Get the current state of a POV hat on a joystick.

The hat indices start at index 0.

Returns
The return value is one of the following positions:

Definition at line 286 of file SDL_joystick.c.

References SDL_PrivateJoystickValid(), SDL_SetError, and state.

287 {
288  Uint8 state;
289 
290  if (!SDL_PrivateJoystickValid(joystick)) {
291  return (0);
292  }
293  if (hat < joystick->nhats) {
294  state = joystick->hats[hat];
295  } else {
296  SDL_SetError("Joystick only has %d hats", joystick->nhats);
297  state = 0;
298  }
299  return (state);
300 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200
struct xkb_state * state
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
#define SDL_SetError

§ SDL_JoystickInstanceID()

SDL_JoystickID SDL_JoystickInstanceID ( SDL_Joystick *  joystick)

Get the instance ID of an opened joystick or -1 if the joystick is invalid.

Definition at line 368 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

369 {
370  if (!SDL_PrivateJoystickValid(joystick)) {
371  return (-1);
372  }
373 
374  return (joystick->instance_id);
375 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200

§ SDL_JoystickName()

const char* SDL_JoystickName ( SDL_Joystick *  joystick)

Return the name for this currently opened joystick. If no name can be found, this function returns NULL.

Definition at line 398 of file SDL_joystick.c.

References NULL, and SDL_PrivateJoystickValid().

399 {
400  if (!SDL_PrivateJoystickValid(joystick)) {
401  return (NULL);
402  }
403 
404  return (joystick->name);
405 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200
#define NULL
Definition: begin_code.h:143

§ SDL_JoystickNameForIndex()

const char* SDL_JoystickNameForIndex ( int  device_index)

Get the implementation dependent name of a joystick. This can be called before any joysticks are opened. If no name can be found, this function returns NULL.

Definition at line 84 of file SDL_joystick.c.

References NULL, SDL_NumJoysticks(), SDL_SetError, and SDL_SYS_JoystickNameForDeviceIndex().

85 {
86  if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
87  SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
88  return (NULL);
89  }
90  return (SDL_SYS_JoystickNameForDeviceIndex(device_index));
91 }
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:75
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
#define NULL
Definition: begin_code.h:143
#define SDL_SetError

§ SDL_JoystickNumAxes()

int SDL_JoystickNumAxes ( SDL_Joystick *  joystick)

Get the number of general axis controls on a joystick.

Definition at line 218 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

219 {
220  if (!SDL_PrivateJoystickValid(joystick)) {
221  return (-1);
222  }
223  return (joystick->naxes);
224 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200

§ SDL_JoystickNumBalls()

int SDL_JoystickNumBalls ( SDL_Joystick *  joystick)

Get the number of trackballs on a joystick.

Joystick trackballs have only relative motion events associated with them and their state cannot be polled.

Definition at line 242 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

243 {
244  if (!SDL_PrivateJoystickValid(joystick)) {
245  return (-1);
246  }
247  return (joystick->nballs);
248 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200

§ SDL_JoystickNumButtons()

int SDL_JoystickNumButtons ( SDL_Joystick *  joystick)

Get the number of buttons on a joystick.

Definition at line 254 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

255 {
256  if (!SDL_PrivateJoystickValid(joystick)) {
257  return (-1);
258  }
259  return (joystick->nbuttons);
260 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200

§ SDL_JoystickNumHats()

int SDL_JoystickNumHats ( SDL_Joystick *  joystick)

Get the number of POV hats on a joystick.

Definition at line 230 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

231 {
232  if (!SDL_PrivateJoystickValid(joystick)) {
233  return (-1);
234  }
235  return (joystick->nhats);
236 }
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:200

§ SDL_JoystickOpen()

SDL_Joystick* SDL_JoystickOpen ( int  device_index)

Open a joystick for use. The index passed as an argument refers to the N'th joystick on the system. This index is not the value which will identify this joystick in future joystick events. The joystick's instance id (SDL_JoystickID) will be used there instead.

Returns
A joystick identifier, or NULL if an error occurred.

Definition at line 101 of file SDL_joystick.c.

References SDL_GameController::joystick, NULL, SDL_free(), SDL_JOYSTICK_POWER_UNKNOWN, SDL_JoystickClose(), SDL_joysticks, SDL_malloc, SDL_memset, SDL_NumJoysticks(), SDL_OutOfMemory, SDL_SetError, SDL_strdup, SDL_SYS_GetInstanceIdOfDeviceIndex(), SDL_SYS_JoystickNameForDeviceIndex(), SDL_SYS_JoystickOpen(), and SDL_SYS_JoystickUpdate().

102 {
103  SDL_Joystick *joystick;
104  SDL_Joystick *joysticklist;
105  const char *joystickname = NULL;
106 
107  if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
108  SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
109  return (NULL);
110  }
111 
112  joysticklist = SDL_joysticks;
113  /* If the joystick is already open, return it
114  * it is important that we have a single joystick * for each instance id
115  */
116  while (joysticklist) {
117  if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == joysticklist->instance_id) {
118  joystick = joysticklist;
119  ++joystick->ref_count;
120  return (joystick);
121  }
122  joysticklist = joysticklist->next;
123  }
124 
125  /* Create and initialize the joystick */
126  joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick));
127  if (joystick == NULL) {
128  SDL_OutOfMemory();
129  return NULL;
130  }
131 
132  SDL_memset(joystick, 0, (sizeof *joystick));
133  if (SDL_SYS_JoystickOpen(joystick, device_index) < 0) {
134  SDL_free(joystick);
135  return NULL;
136  }
137 
138  joystickname = SDL_SYS_JoystickNameForDeviceIndex(device_index);
139  if (joystickname)
140  joystick->name = SDL_strdup(joystickname);
141  else
142  joystick->name = NULL;
143 
144  if (joystick->naxes > 0) {
145  joystick->axes = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
146  joystick->axes_zero = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
147  }
148  if (joystick->nhats > 0) {
149  joystick->hats = (Uint8 *) SDL_malloc
150  (joystick->nhats * sizeof(Uint8));
151  }
152  if (joystick->nballs > 0) {
153  joystick->balls = (struct balldelta *) SDL_malloc
154  (joystick->nballs * sizeof(*joystick->balls));
155  }
156  if (joystick->nbuttons > 0) {
157  joystick->buttons = (Uint8 *) SDL_malloc
158  (joystick->nbuttons * sizeof(Uint8));
159  }
160  if (((joystick->naxes > 0) && !joystick->axes)
161  || ((joystick->nhats > 0) && !joystick->hats)
162  || ((joystick->nballs > 0) && !joystick->balls)
163  || ((joystick->nbuttons > 0) && !joystick->buttons)) {
164  SDL_OutOfMemory();
165  SDL_JoystickClose(joystick);
166  return NULL;
167  }
168  if (joystick->axes) {
169  SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
170  SDL_memset(joystick->axes_zero, 0, joystick->naxes * sizeof(Sint16));
171  }
172  if (joystick->hats) {
173  SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
174  }
175  if (joystick->balls) {
176  SDL_memset(joystick->balls, 0,
177  joystick->nballs * sizeof(*joystick->balls));
178  }
179  if (joystick->buttons) {
180  SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8));
181  }
182  joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
183 
184  /* Add joystick to list */
185  ++joystick->ref_count;
186  /* Link the joystick in the list */
187  joystick->next = SDL_joysticks;
188  SDL_joysticks = joystick;
189 
190  SDL_SYS_JoystickUpdate(joystick);
191 
192  return (joystick);
193 }
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:411
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
void SDL_free(void *mem)
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
#define SDL_strdup
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
#define SDL_malloc
#define SDL_memset
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:147
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

§ SDL_JoystickUpdate()

void SDL_JoystickUpdate ( void  )

Update the current state of the open joysticks.

This is called automatically by the event loop if any joystick events are enabled.

Definition at line 736 of file SDL_joystick.c.

References i, NULL, SDL_FALSE, SDL_HAT_CENTERED, SDL_JoystickClose(), SDL_joysticks, SDL_PrivateJoystickAxis(), SDL_PrivateJoystickButton(), SDL_PrivateJoystickHat(), SDL_SYS_JoystickDetect(), SDL_SYS_JoystickUpdate(), and SDL_updating_joystick.

737 {
738  SDL_Joystick *joystick;
739 
740  joystick = SDL_joysticks;
741  while (joystick) {
742  SDL_Joystick *joysticknext;
743  /* save off the next pointer, the Update call may cause a joystick removed event
744  * and cause our joystick pointer to be freed
745  */
746  joysticknext = joystick->next;
747 
748  SDL_updating_joystick = joystick;
749 
750  SDL_SYS_JoystickUpdate(joystick);
751 
752  if (joystick->force_recentering) {
753  int i;
754 
755  /* Tell the app that everything is centered/unpressed... */
756  for (i = 0; i < joystick->naxes; i++) {
757  SDL_PrivateJoystickAxis(joystick, i, joystick->axes_zero[i]);
758  }
759 
760  for (i = 0; i < joystick->nbuttons; i++) {
761  SDL_PrivateJoystickButton(joystick, i, 0);
762  }
763 
764  for (i = 0; i < joystick->nhats; i++) {
766  }
767 
768  joystick->force_recentering = SDL_FALSE;
769  }
770 
772 
773  /* If the joystick was closed while updating, free it here */
774  if (joystick->ref_count <= 0) {
775  SDL_JoystickClose(joystick);
776  }
777 
778  joystick = joysticknext;
779  }
780 
781  /* this needs to happen AFTER walking the joystick list above, so that any
782  dangling hardware data from removed devices can be free'd
783  */
785 }
static SDL_Joystick * SDL_updating_joystick
Definition: SDL_joystick.c:37
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:411
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
Definition: SDL_joystick.c:608
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
Definition: SDL_joystick.c:684
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
Definition: SDL_joystick.c:567
void SDL_SYS_JoystickDetect()
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:143
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:207
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

§ SDL_NumJoysticks()

int SDL_NumJoysticks ( void  )

Count the number of joysticks attached to the system right now

Definition at line 75 of file SDL_joystick.c.

References SDL_SYS_NumJoysticks().

Referenced by SDL_JoystickGetDeviceGUID(), SDL_JoystickNameForIndex(), and SDL_JoystickOpen().

76 {
77  return SDL_SYS_NumJoysticks();
78 }
int SDL_SYS_NumJoysticks()