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

Commit

Permalink
Added SDL_HapticStopAll.
Browse files Browse the repository at this point in the history
Cleaned up the dummy haptic driver a bit.
  • Loading branch information
bobbens committed Aug 24, 2008
1 parent eeee6d8 commit 2ed82eb
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 18 deletions.
18 changes: 15 additions & 3 deletions include/SDL_haptic.h
Expand Up @@ -764,6 +764,8 @@ extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
* \sa SDL_HapticClose
* \sa SDL_HapticSetGain
* \sa SDL_HapticSetAutocenter
* \sa SDL_HapticPause
* \sa SDL_HapticStopAll
*/
extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);

Expand Down Expand Up @@ -1080,7 +1082,7 @@ extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic, int aut
/**
* \fn extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic)
*
* \brief Pauses the haptic device.
* \brief Pauses a haptic device.
*
* Device must support the SDL_HAPTIC_PAUSE feature. Call SDL_HapticUnpause
* to resume playback.
Expand All @@ -1098,17 +1100,27 @@ extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
/**
* \fn extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic)
*
* \brief Unpauses the haptic device.
* \brief Unpauses a haptic device.
*
* Call to unpause after SDL_HapticPause.
*
* \param haptic Haptic device to pause.
* \return 0 on success or -1 on error.
* \return 0 on success or -1 on error.
*
* \sa SDL_HapticPause
*/
extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);

/**
* \fn extern DECSLPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic)
*
* \brief Stops all the currently playing effects on a haptic device.
*
* \param haptic Haptic device to stop.
* \return 0 on success or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
13 changes: 13 additions & 0 deletions src/haptic/SDL_haptic.c
Expand Up @@ -673,3 +673,16 @@ SDL_HapticUnpause(SDL_Haptic * haptic)
return SDL_SYS_HapticUnpause(haptic);
}

/*
* Stops all the currently playing effects.
*/
int
SDL_HapticStopAll(SDL_Haptic * haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}

return SDL_SYS_HapticStopAll(haptic);
}

7 changes: 7 additions & 0 deletions src/haptic/SDL_syshaptic.h
Expand Up @@ -194,3 +194,10 @@ extern int SDL_SYS_HapticPause(SDL_Haptic * haptic);
*/
extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);

/*
* Stops all the currently playing haptic effects on the device.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic);

23 changes: 21 additions & 2 deletions src/haptic/darwin/SDL_syshaptic.c
Expand Up @@ -1233,7 +1233,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic)
HRESULT ret;

ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
FFSFFC_PAUSE);
FFSFFC_PAUSE);
if (ret != FF_OK) {
SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
return -1;
Expand All @@ -1252,7 +1252,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
HRESULT ret;

ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
FFSFFC_CONTINUE);
FFSFFC_CONTINUE);
if (ret != FF_OK) {
SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
return -1;
Expand All @@ -1262,4 +1262,23 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
}


/*
* Stops all currently playing effects.
*/
int
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
{
HRESULT ret;

ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
FFSFFC_STOPALL);
if (ret != FF_OK) {
SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret));
return -1;
}

return 0;
}


#endif /* SDL_HAPTIC_IOKIT */
41 changes: 28 additions & 13 deletions src/haptic/dummy/SDL_syshaptic.c
Expand Up @@ -27,6 +27,13 @@
#include "../SDL_syshaptic.h"


static int
SDL_SYS_LogicError(void)
{
SDL_SetError("Logic error: No haptic devices available.");;
}


int
SDL_SYS_HapticInit(void)
{
Expand All @@ -37,15 +44,15 @@ SDL_SYS_HapticInit(void)
const char *
SDL_SYS_HapticName(int index)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return NULL;
}


int
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}

Expand All @@ -67,7 +74,7 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
int
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}

Expand Down Expand Up @@ -98,7 +105,7 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
struct haptic_effect * effect,
SDL_HapticEffect * base)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}

Expand All @@ -108,70 +115,78 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
struct haptic_effect * effect,
SDL_HapticEffect * data)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}


int
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, Uint32 iterations)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}


int
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}


void
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return;
}


int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect)
{
SDL_SetError("Logic error: No Haptic devices available.");
SDL_SYS_LogicError();
return -1;
}


int
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}


int
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}

int
SDL_SYS_HapticPause(SDL_Haptic * haptic)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}

int
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
{
SDL_SetError("Logic error: No haptic devices available.");
SDL_SYS_LogicError();
return -1;
}

int
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
{
SDL_SYS_LogicError();
return -1;
}



#endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */
20 changes: 20 additions & 0 deletions src/haptic/linux/SDL_syshaptic.c
Expand Up @@ -910,4 +910,24 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
}


/*
* Stops all the currently playing effects.
*/
int
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
{
int i, ret;;

for (i=0; i<haptic->neffects; i++) {
ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]);
if (ret < 0) {
SDL_SetError("Haptic: Error while trying to stop all playing effects.");
return -1;
}
}

return 0;
}


#endif /* SDL_HAPTIC_LINUX */
20 changes: 20 additions & 0 deletions src/haptic/win32/SDL_syshaptic.c
Expand Up @@ -1344,4 +1344,24 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
}


/*
* Stops all the playing effects on the device.
*/
int
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
{
HRESULT ret;

/* Try to stop the effects. */
ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
DISFFC_STOPALL );
if (FAILED(ret)) {
DI_SetError("Stopping the device",ret);
return -1;
}

return 0;
}


#endif /* SDL_HAPTIC_DINPUT */

0 comments on commit 2ed82eb

Please sign in to comment.