Navigation Menu

Skip to content

Commit

Permalink
Added SDL_JoystickHasLED
Browse files Browse the repository at this point in the history
Currently, this is only supported by the PS4 HIDAPI driver.
  • Loading branch information
slouken committed Nov 5, 2020
1 parent 83cddd2 commit e555d45
Show file tree
Hide file tree
Showing 27 changed files with 290 additions and 87 deletions.
9 changes: 9 additions & 0 deletions include/SDL_gamecontroller.h
Expand Up @@ -404,6 +404,15 @@ extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *ga
*/
extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);

/**
* Return whether a controller has an LED
*
* \param gamecontroller The controller to query
*
* \return SDL_TRUE, or SDL_FALSE if this controller does not have a modifiable LED
*/
extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);

/**
* Update a controller's LED color.
*
Expand Down
9 changes: 9 additions & 0 deletions include/SDL_joystick.h
Expand Up @@ -432,6 +432,15 @@ extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
*/
extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);

/**
* Return whether a joystick has an LED
*
* \param joystick The joystick to query
*
* \return SDL_TRUE, or SDL_FALSE if this joystick does not have a modifiable LED
*/
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick * joystick);

/**
* Update a joystick's LED color.
*
Expand Down
4 changes: 4 additions & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Expand Up @@ -768,3 +768,7 @@
#define SDL_AndroidRequestPermission SDL_AndroidRequestPermission_REAL
#define SDL_OpenURL SDL_OpenURL_REAL
#define SDL_HasSurfaceRLE SDL_HasSurfaceRLE_REAL
#define SDL_GameControllerHasLED SDL_GameControllerHasLED_REAL
#define SDL_GameControllerSetLED SDL_GameControllerSetLED_REAL
#define SDL_JoystickHasLED SDL_JoystickHasLED_REAL
#define SDL_JoystickSetLED SDL_JoystickSetLED_REAL
4 changes: 4 additions & 0 deletions src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -829,3 +829,7 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_AndroidRequestPermission,(const char *a),(a),return
#endif
SDL_DYNAPI_PROC(int,SDL_OpenURL,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_HasSurfaceRLE,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasLED,(SDL_GameController *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GameControllerSetLED,(SDL_GameController *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasLED,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_JoystickSetLED,(SDL_Joystick *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
6 changes: 6 additions & 0 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -2107,6 +2107,12 @@ SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequenc
return SDL_JoystickRumble(SDL_GameControllerGetJoystick(gamecontroller), low_frequency_rumble, high_frequency_rumble, duration_ms);
}

SDL_bool
SDL_GameControllerHasLED(SDL_GameController *gamecontroller)
{
return SDL_JoystickHasLED(SDL_GameControllerGetJoystick(gamecontroller));
}

int
SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down
18 changes: 18 additions & 0 deletions src/joystick/SDL_joystick.c
Expand Up @@ -901,6 +901,24 @@ SDL_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16
return result;
}

SDL_bool
SDL_JoystickHasLED(SDL_Joystick * joystick)
{
SDL_bool result;

if (!SDL_PrivateJoystickValid(joystick)) {
return SDL_FALSE;
}

SDL_LockJoysticks();

result = joystick->driver->HasLED(joystick);

SDL_UnlockJoysticks();

return result;
}

int
SDL_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down
1 change: 1 addition & 0 deletions src/joystick/SDL_sysjoystick.h
Expand Up @@ -128,6 +128,7 @@ typedef struct _SDL_JoystickDriver
int (*Rumble)(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);

/* LED functionality */
SDL_bool (*HasLED)(SDL_Joystick * joystick);
int (*SetLED)(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue);

/* Function to update the state of a joystick - called as a device poll.
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/android/SDL_sysjoystick.c
Expand Up @@ -633,6 +633,12 @@ ANDROID_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uin
return SDL_Unsupported();
}

static SDL_bool
ANDROID_JoystickHasLED(SDL_Joystick * joystick)
{
return SDL_FALSE;
}

static int
ANDROID_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -717,6 +723,7 @@ SDL_JoystickDriver SDL_ANDROID_JoystickDriver =
ANDROID_JoystickGetDeviceInstanceID,
ANDROID_JoystickOpen,
ANDROID_JoystickRumble,
ANDROID_JoystickHasLED,
ANDROID_JoystickSetLED,
ANDROID_JoystickUpdate,
ANDROID_JoystickClose,
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/bsd/SDL_sysjoystick.c
Expand Up @@ -768,6 +768,12 @@ BSD_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
return SDL_FALSE;
}

static SDL_bool
BSD_JoystickHasLED(SDL_Joystick * joystick)
{
return SDL_FALSE;
}

static int
BSD_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand All @@ -786,6 +792,7 @@ SDL_JoystickDriver SDL_BSD_JoystickDriver =
BSD_JoystickGetDeviceInstanceID,
BSD_JoystickOpen,
BSD_JoystickRumble,
BSD_JoystickHasLED,
BSD_JoystickSetLED,
BSD_JoystickUpdate,
BSD_JoystickClose,
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/darwin/SDL_sysjoystick.c
Expand Up @@ -922,6 +922,12 @@ DARWIN_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint
return 0;
}

static SDL_bool
DARWIN_JoystickHasLED(SDL_Joystick * joystick)
{
return SDL_FALSE;
}

static int
DARWIN_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -1075,6 +1081,7 @@ SDL_JoystickDriver SDL_DARWIN_JoystickDriver =
DARWIN_JoystickGetDeviceInstanceID,
DARWIN_JoystickOpen,
DARWIN_JoystickRumble,
DARWIN_JoystickHasLED,
DARWIN_JoystickSetLED,
DARWIN_JoystickUpdate,
DARWIN_JoystickClose,
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/dummy/SDL_sysjoystick.c
Expand Up @@ -89,6 +89,12 @@ DUMMY_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint1
return SDL_Unsupported();
}

static SDL_bool
DUMMY_JoystickHasLED(SDL_Joystick * joystick)
{
return SDL_FALSE;
}

static int
DUMMY_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -128,6 +134,7 @@ SDL_JoystickDriver SDL_DUMMY_JoystickDriver =
DUMMY_JoystickGetDeviceInstanceID,
DUMMY_JoystickOpen,
DUMMY_JoystickRumble,
DUMMY_JoystickHasLED,
DUMMY_JoystickSetLED,
DUMMY_JoystickUpdate,
DUMMY_JoystickClose,
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/emscripten/SDL_sysjoystick.c
Expand Up @@ -409,6 +409,12 @@ EMSCRIPTEN_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
return SDL_FALSE;
}

static SDL_bool
EMSCRIPTEN_JoystickHasLED(SDL_Joystick * joystick)
{
return SDL_FALSE;
}

static int
EMSCRIPTEN_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand All @@ -427,6 +433,7 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver =
EMSCRIPTEN_JoystickGetDeviceInstanceID,
EMSCRIPTEN_JoystickOpen,
EMSCRIPTEN_JoystickRumble,
EMSCRIPTEN_JoystickHasLED,
EMSCRIPTEN_JoystickSetLED,
EMSCRIPTEN_JoystickUpdate,
EMSCRIPTEN_JoystickClose,
Expand Down
6 changes: 6 additions & 0 deletions src/joystick/haiku/SDL_haikujoystick.cc
Expand Up @@ -265,6 +265,11 @@ extern "C"
return SDL_FALSE;
}

static SDL_bool HAIKU_JoystickHasLED(SDL_Joystick * joystick)
{
return SDL_FALSE;
}

static int HAIKU_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
{
return SDL_Unsupported();
Expand All @@ -282,6 +287,7 @@ extern "C"
HAIKU_JoystickGetDeviceInstanceID,
HAIKU_JoystickOpen,
HAIKU_JoystickRumble,
HAIKU_JoystickHasLED,
HAIKU_JoystickSetLED,
HAIKU_JoystickUpdate,
HAIKU_JoystickClose,
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/hidapi/SDL_hidapi_gamecube.c
Expand Up @@ -363,6 +363,12 @@ HIDAPI_DriverGameCube_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *jo
return -1;
}

static SDL_bool
HIDAPI_DriverGameCube_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
return SDL_FALSE;
}

static int
HIDAPI_DriverGameCube_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -408,6 +414,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube =
HIDAPI_DriverGameCube_UpdateDevice,
HIDAPI_DriverGameCube_OpenJoystick,
HIDAPI_DriverGameCube_RumbleJoystick,
HIDAPI_DriverGameCube_HasJoystickLED,
HIDAPI_DriverGameCube_SetJoystickLED,
HIDAPI_DriverGameCube_CloseJoystick,
HIDAPI_DriverGameCube_FreeDevice,
Expand Down
11 changes: 9 additions & 2 deletions src/joystick/hidapi/SDL_hidapi_ps4.c
Expand Up @@ -102,7 +102,7 @@ typedef struct {
int player_index;
Uint16 rumble_left;
Uint16 rumble_right;
Uint8 color_set;
SDL_bool color_set;
Uint8 led_red;
Uint8 led_green;
Uint8 led_blue;
Expand Down Expand Up @@ -365,12 +365,18 @@ HIDAPI_DriverPS4_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
return 0;
}

static SDL_bool
HIDAPI_DriverPS4_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
return SDL_TRUE;
}

static int
HIDAPI_DriverPS4_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;

ctx->color_set = 1;
ctx->color_set = SDL_TRUE;
ctx->led_red = red;
ctx->led_green = green;
ctx->led_blue = blue;
Expand Down Expand Up @@ -564,6 +570,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4 =
HIDAPI_DriverPS4_UpdateDevice,
HIDAPI_DriverPS4_OpenJoystick,
HIDAPI_DriverPS4_RumbleJoystick,
HIDAPI_DriverPS4_HasJoystickLED,
HIDAPI_DriverPS4_SetJoystickLED,
HIDAPI_DriverPS4_CloseJoystick,
HIDAPI_DriverPS4_FreeDevice,
Expand Down
8 changes: 8 additions & 0 deletions src/joystick/hidapi/SDL_hidapi_steam.c
Expand Up @@ -1034,6 +1034,13 @@ HIDAPI_DriverSteam_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
return SDL_Unsupported();
}

static SDL_bool
HIDAPI_DriverSteam_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
/* You should use the full Steam Input API for LED support */
return SDL_FALSE;
}

static int
HIDAPI_DriverSteam_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -1171,6 +1178,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam =
HIDAPI_DriverSteam_UpdateDevice,
HIDAPI_DriverSteam_OpenJoystick,
HIDAPI_DriverSteam_RumbleJoystick,
HIDAPI_DriverSteam_HasJoystickLED,
HIDAPI_DriverSteam_SetJoystickLED,
HIDAPI_DriverSteam_CloseJoystick,
HIDAPI_DriverSteam_FreeDevice,
Expand Down
8 changes: 8 additions & 0 deletions src/joystick/hidapi/SDL_hidapi_switch.c
Expand Up @@ -920,6 +920,13 @@ HIDAPI_DriverSwitch_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys
return HIDAPI_DriverSwitch_ActuallyRumbleJoystick(ctx, low_frequency_rumble, high_frequency_rumble);
}

static SDL_bool
HIDAPI_DriverSwitch_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
/* Doesn't have an RGB LED, so don't return true here */
return SDL_FALSE;
}

static int
HIDAPI_DriverSwitch_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -1273,6 +1280,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch =
HIDAPI_DriverSwitch_UpdateDevice,
HIDAPI_DriverSwitch_OpenJoystick,
HIDAPI_DriverSwitch_RumbleJoystick,
HIDAPI_DriverSwitch_HasJoystickLED,
HIDAPI_DriverSwitch_SetJoystickLED,
HIDAPI_DriverSwitch_CloseJoystick,
HIDAPI_DriverSwitch_FreeDevice,
Expand Down
8 changes: 8 additions & 0 deletions src/joystick/hidapi/SDL_hidapi_xbox360.c
Expand Up @@ -796,6 +796,13 @@ HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joy
return 0;
}

static SDL_bool
HIDAPI_DriverXbox360_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
/* Doesn't have an RGB LED, so don't return true here */
return SDL_FALSE;
}

static int
HIDAPI_DriverXbox360_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -1308,6 +1315,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360 =
HIDAPI_DriverXbox360_UpdateDevice,
HIDAPI_DriverXbox360_OpenJoystick,
HIDAPI_DriverXbox360_RumbleJoystick,
HIDAPI_DriverXbox360_HasJoystickLED,
HIDAPI_DriverXbox360_SetJoystickLED,
HIDAPI_DriverXbox360_CloseJoystick,
HIDAPI_DriverXbox360_FreeDevice,
Expand Down
8 changes: 8 additions & 0 deletions src/joystick/hidapi/SDL_hidapi_xbox360w.c
Expand Up @@ -157,6 +157,13 @@ HIDAPI_DriverXbox360W_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *jo
return 0;
}

static SDL_bool
HIDAPI_DriverXbox360W_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
/* Doesn't have an RGB LED, so don't return true here */
return SDL_FALSE;
}

static int
HIDAPI_DriverXbox360W_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -300,6 +307,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W =
HIDAPI_DriverXbox360W_UpdateDevice,
HIDAPI_DriverXbox360W_OpenJoystick,
HIDAPI_DriverXbox360W_RumbleJoystick,
HIDAPI_DriverXbox360W_HasJoystickLED,
HIDAPI_DriverXbox360W_SetJoystickLED,
HIDAPI_DriverXbox360W_CloseJoystick,
HIDAPI_DriverXbox360W_FreeDevice,
Expand Down
8 changes: 8 additions & 0 deletions src/joystick/hidapi/SDL_hidapi_xboxone.c
Expand Up @@ -364,6 +364,13 @@ HIDAPI_DriverXboxOne_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joy
return 0;
}

static SDL_bool
HIDAPI_DriverXboxOne_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
/* Doesn't have an RGB LED, so don't return true here */
return SDL_FALSE;
}

static int
HIDAPI_DriverXboxOne_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
Expand Down Expand Up @@ -836,6 +843,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne =
HIDAPI_DriverXboxOne_UpdateDevice,
HIDAPI_DriverXboxOne_OpenJoystick,
HIDAPI_DriverXboxOne_RumbleJoystick,
HIDAPI_DriverXboxOne_HasJoystickLED,
HIDAPI_DriverXboxOne_SetJoystickLED,
HIDAPI_DriverXboxOne_CloseJoystick,
HIDAPI_DriverXboxOne_FreeDevice,
Expand Down

0 comments on commit e555d45

Please sign in to comment.