Skip to content

Commit

Permalink
Implemented SDL_GameControllerSetLED() for iOS/tvOS
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 7, 2020
1 parent faeac6e commit 749062e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/joystick/iphoneos/SDL_sysjoystick.m
Expand Up @@ -78,6 +78,7 @@ @interface GCMicroGamepad (SDL)
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 140000) || (__MAC_OS_VERSION_MAX_ALLOWED > 1500000)
#define ENABLE_MFI_BATTERY
#define ENABLE_MFI_RUMBLE
#define ENABLE_MFI_LIGHT
#define ENABLE_PHYSICAL_INPUT_PROFILE
#endif

Expand Down Expand Up @@ -1085,12 +1086,39 @@ -(void)cleanup
static SDL_bool
IOS_JoystickHasLED(SDL_Joystick * joystick)
{
#ifdef ENABLE_MFI_LIGHT
@autoreleasepool {
if (@available(iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller;
GCDeviceLight *light = controller.light;
if (light) {
return SDL_TRUE;
}
}
}
#endif /* ENABLE_MFI_LIGHT */

return SDL_FALSE;
}

static int
IOS_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
{
#ifdef ENABLE_MFI_LIGHT
@autoreleasepool {
if (@available(iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller;
GCDeviceLight *light = controller.light;
if (light) {
light.color = [[GCColor alloc] initWithRed:(float)red / 255.0f
green:(float)green / 255.0f
blue:(float)blue / 255.0f];
return 0;
}
}
}
#endif /* ENABLE_MFI_LIGHT */

return SDL_Unsupported();
}

Expand Down

0 comments on commit 749062e

Please sign in to comment.