Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added SDL_HapticIndex.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Jul 8, 2008
1 parent f57909c commit fe47286
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
14 changes: 14 additions & 0 deletions include/SDL_haptic.h
Expand Up @@ -636,11 +636,25 @@ extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
* \param device_index Index of the device to open.
* \return Device identifier or NULL on error.
*
* \sa SDL_HapticIndex
* \sa SDL_HapticOpenFromJoystick
* \sa SDL_HapticClose
*/
extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);


/**
* \fn int SDL_HapticIndex(SDL_Haptic * haptic)
*
* \brief Gets the index of a haptic device.
*
* \param haptic Haptic device to get the index of.
* \return The index of the haptic device or -1 on error.
*
* \sa SDL_HapticOpen
*/
extern DECLSPEC int SDL_HapticIndex(SDL_Haptic * haptic);

/**
* \fn int SDL_JoystickIsHaptic(SDL_Joystick * joystick)
*
Expand Down
50 changes: 32 additions & 18 deletions src/haptic/SDL_haptic.c
Expand Up @@ -58,6 +58,24 @@ SDL_HapticInit(void)
}


/*
* Checks to see if the haptic device is valid
*/
static int
ValidHaptic(SDL_Haptic ** haptic)
{
int valid;

if (*haptic == NULL) {
SDL_SetError("Haptic device hasn't been opened yet");
valid = 0;
} else {
valid = 1;
}
return valid;
}


/*
* Returns the number of available devices.
*/
Expand Down Expand Up @@ -130,6 +148,20 @@ SDL_HapticOpen(int device_index)
}


/*
* Returns the index to a haptic device.
*/
int
SDL_HapticIndex(SDL_Haptic * haptic)
{
if (!ValidHaptic(&haptic)) {
return -1;
}

return haptic->index;
}


/*
* Returns SDL_TRUE if joystick has haptic features.
*/
Expand Down Expand Up @@ -203,24 +235,6 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
}


/*
* Checks to see if the haptic device is valid
*/
static int
ValidHaptic(SDL_Haptic ** haptic)
{
int valid;

if (*haptic == NULL) {
SDL_SetError("Haptic device hasn't been opened yet");
valid = 0;
} else {
valid = 1;
}
return valid;
}


/*
* Closes a SDL_Haptic device.
*/
Expand Down

0 comments on commit fe47286

Please sign in to comment.