joystick: Add APIs to query rumble support

main
Cameron Gutman 2021-11-11 15:53:11 -06:00 committed by Sam Lantinga
parent afccabb881
commit fe09a4930a
8 changed files with 134 additions and 9 deletions

View File

@ -857,6 +857,8 @@ extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *
* \returns 0, or -1 if rumble isn't supported on this controller
*
* \since This function is available since SDL 2.0.9.
*
* \sa SDL_GameControllerHasRumble
*/
extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
@ -879,6 +881,8 @@ extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecon
* \returns 0, or -1 if trigger rumble isn't supported on this controller
*
* \since This function is available since SDL 2.0.14.
*
* \sa SDL_GameControllerHasRumbleTriggers
*/
extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
@ -893,6 +897,32 @@ extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController
*/
extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);
/**
* Query whether a game controller has rumble support.
*
* \param gamecontroller The controller to query
* \returns SDL_TRUE, or SDL_FALSE if this controller does not have
* rumble support
*
* \since This function is available since SDL 2.0.18.
*
* \sa SDL_GameControllerRumble
*/
extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumble(SDL_GameController *gamecontroller);
/**
* Query whether a game controller has rumble support on triggers.
*
* \param gamecontroller The controller to query
* \returns SDL_TRUE, or SDL_FALSE if this controller does not have
* trigger rumble support
*
* \since This function is available since SDL 2.0.18.
*
* \sa SDL_GameControllerRumbleTriggers
*/
extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller);
/**
* Update a game controller's LED color.
*

View File

@ -818,6 +818,8 @@ extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick,
* \returns 0, or -1 if rumble isn't supported on this joystick
*
* \since This function is available since SDL 2.0.9.
*
* \sa SDL_JoystickHasRumble
*/
extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
@ -841,6 +843,8 @@ extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 lo
* \returns 0, or -1 if trigger rumble isn't supported on this joystick
*
* \since This function is available since SDL 2.0.14.
*
* \sa SDL_JoystickHasRumbleTriggers
*/
extern DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
@ -857,6 +861,30 @@ extern DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, U
*/
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick);
/**
* Query whether a joystick has rumble support.
*
* \param joystick The joystick to query
* \return SDL_TRUE if the joystick has rumble, SDL_FALSE otherwise.
*
* \since This function is available since SDL 2.0.18.
*
* \sa SDL_JoystickRumble
*/
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick);
/**
* Query whether a joystick has rumble support on triggers.
*
* \param joystick The joystick to query
* \return SDL_TRUE if the joystick has trigger rumble, SDL_FALSE otherwise.
*
* \since This function is available since SDL 2.0.18.
*
* \sa SDL_JoystickRumbleTriggers
*/
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick);
/**
* Update a joystick's LED color.
*

View File

@ -849,3 +849,7 @@
#define SDL_hid_device_change_count SDL_hid_device_change_count_REAL
#define SDL_hid_open SDL_hid_open_REAL
#define SDL_hid_open_path SDL_hid_open_path_REAL
#define SDL_JoystickHasRumble SDL_JoystickHasRumble_REAL
#define SDL_JoystickHasRumbleTriggers SDL_JoystickHasRumbleTriggers_REAL
#define SDL_GameControllerHasRumble SDL_GameControllerHasRumble_REAL
#define SDL_GameControllerHasRumbleTriggers SDL_GameControllerHasRumbleTriggers_REAL

View File

@ -918,3 +918,7 @@ SDL_DYNAPI_PROC(void,SDL_RenderLogicalToWindow,(SDL_Renderer *a, float b, float
SDL_DYNAPI_PROC(Uint32,SDL_hid_device_change_count,(void),(),return)
SDL_DYNAPI_PROC(SDL_hid_device*,SDL_hid_open,(unsigned short a, unsigned short b, const wchar_t *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_hid_device*,SDL_hid_open_path,(const char *a, int b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumble,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumbleTriggers,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumble,(SDL_GameController *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumbleTriggers,(SDL_GameController *a),(a),return)

View File

@ -2450,6 +2450,18 @@ SDL_GameControllerHasLED(SDL_GameController *gamecontroller)
return SDL_JoystickHasLED(SDL_GameControllerGetJoystick(gamecontroller));
}
SDL_bool
SDL_GameControllerHasRumble(SDL_GameController *gamecontroller)
{
return SDL_JoystickHasRumble(SDL_GameControllerGetJoystick(gamecontroller));
}
SDL_bool
SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller)
{
return SDL_JoystickHasRumbleTriggers(SDL_GameControllerGetJoystick(gamecontroller));
}
int
SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue)
{

View File

@ -951,6 +951,42 @@ SDL_JoystickHasLED(SDL_Joystick *joystick)
return result;
}
SDL_bool
SDL_JoystickHasRumble(SDL_Joystick *joystick)
{
SDL_bool result;
if (!SDL_PrivateJoystickValid(joystick)) {
return SDL_FALSE;
}
SDL_LockJoysticks();
result = (joystick->driver->GetCapabilities(joystick) & SDL_JOYCAP_RUMBLE) != 0;
SDL_UnlockJoysticks();
return result;
}
SDL_bool
SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick)
{
SDL_bool result;
if (!SDL_PrivateJoystickValid(joystick)) {
return SDL_FALSE;
}
SDL_LockJoysticks();
result = (joystick->driver->GetCapabilities(joystick) & SDL_JOYCAP_RUMBLE_TRIGGERS) != 0;
SDL_UnlockJoysticks();
return result;
}
int
SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{

View File

@ -168,6 +168,14 @@ static void AddController(int device_index, SDL_bool verbose)
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_GYRO, SDL_TRUE);
}
if (SDL_GameControllerHasRumble(gamecontroller)) {
SDL_Log("Rumble supported");
}
if (SDL_GameControllerHasRumbleTriggers(gamecontroller)) {
SDL_Log("Trigger rumble supported");
}
UpdateWindowTitle();
}

View File

@ -78,15 +78,18 @@ PrintJoystick(SDL_Joystick *joystick)
break;
}
SDL_Log("Joystick\n");
SDL_Log(" name: %s\n", SDL_JoystickName(joystick));
SDL_Log(" type: %s\n", type);
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
SDL_Log(" guid: %s\n", guid);
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
SDL_Log(" name: %s\n", SDL_JoystickName(joystick));
SDL_Log(" type: %s\n", type);
SDL_Log(" LED: %s\n", SDL_JoystickHasLED(joystick) ? "yes" : "no");
SDL_Log(" rumble: %s\n", SDL_JoystickHasRumble(joystick) ? "yes" : "no");
SDL_Log("trigger rumble: %s\n", SDL_JoystickHasRumbleTriggers(joystick) ? "yes" : "no");
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
SDL_Log(" instance id: %d\n", SDL_JoystickInstanceID(joystick));
SDL_Log(" guid: %s\n", guid);
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
}
static void