From 9d0dc49fd2381cf232fb138eea69809feecc06f4 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 27 Sep 2023 08:52:26 -0500 Subject: [PATCH] Implement controller LED support --- Limelight/Input/ControllerSupport.h | 1 + Limelight/Input/ControllerSupport.m | 22 +++++++++++++++++++ Limelight/Stream/Connection.m | 6 +++++ Limelight/Stream/ConnectionCallbacks.h | 1 + .../StreamFrameViewController.m | 6 +++++ 5 files changed, 36 insertions(+) diff --git a/Limelight/Input/ControllerSupport.h b/Limelight/Input/ControllerSupport.h index f839bb7..335f21a 100644 --- a/Limelight/Input/ControllerSupport.h +++ b/Limelight/Input/ControllerSupport.h @@ -43,6 +43,7 @@ -(void) rumble:(unsigned short)controllerNumber lowFreqMotor:(unsigned short)lowFreqMotor highFreqMotor:(unsigned short)highFreqMotor; -(void) rumbleTriggers:(uint16_t)controllerNumber leftTrigger:(uint16_t)leftTrigger rightTrigger:(uint16_t)rightTrigger; -(void) setMotionEventState:(uint16_t)controllerNumber motionType:(uint8_t)motionType reportRateHz:(uint16_t)reportRateHz; +-(void) setControllerLed:(uint16_t)controllerNumber r:(uint8_t)r g:(uint8_t)g b:(uint8_t)b; +(int) getConnectedGamepadMask:(StreamConfiguration*)streamConfig; diff --git a/Limelight/Input/ControllerSupport.m b/Limelight/Input/ControllerSupport.m index 9c8f11d..3841d1a 100644 --- a/Limelight/Input/ControllerSupport.m +++ b/Limelight/Input/ControllerSupport.m @@ -175,6 +175,23 @@ static const double MOUSE_SPEED_DIVISOR = 1.25; } } +-(void) setControllerLed:(uint16_t)controllerNumber r:(uint8_t)r g:(uint8_t)g b:(uint8_t)b { + if (@available(iOS 14.0, tvOS 14.0, *)) { + Controller* controller = [_controllers objectForKey:[NSNumber numberWithInteger:controllerNumber]]; + if (controller == nil) { + // No connected controller for this player + return; + } + + if (controller.gamepad.light == nil) { + // No LED control supported for this controller + return; + } + + controller.gamepad.light.color = [[GCColor alloc] initWithRed:(r / 255.0f) green:(g / 255.0f) blue:(b / 255.0f)]; + } +} + -(void) updateLeftStick:(Controller*)controller x:(short)x y:(short)y { @synchronized(controller) { @@ -514,6 +531,11 @@ static const double MOUSE_SPEED_DIVISOR = 1.25; } } + // Detect RGB LED support + if (controller.light) { + capabilities |= LI_CCAP_RGB_LED; + } + LiSendControllerArrivalEvent(controller.playerIndex, [self getActiveGamepadMask], type, supportedButtonFlags, capabilities); } } diff --git a/Limelight/Stream/Connection.m b/Limelight/Stream/Connection.m index c40119e..cd86037 100644 --- a/Limelight/Stream/Connection.m +++ b/Limelight/Stream/Connection.m @@ -345,6 +345,11 @@ void ClSetMotionEventState(uint16_t controllerNumber, uint8_t motionType, uint16 [_callbacks setMotionEventState:controllerNumber motionType:motionType reportRateHz:reportRateHz]; } +void ClSetControllerLED(uint16_t controllerNumber, uint8_t r, uint8_t g, uint8_t b) +{ + [_callbacks setControllerLed:controllerNumber r:r g:g b:b]; +} + -(void) terminate { // Interrupt any action blocking LiStartConnection(). This is @@ -467,6 +472,7 @@ void ClSetMotionEventState(uint16_t controllerNumber, uint8_t motionType, uint16 _clCallbacks.setHdrMode = ClSetHdrMode; _clCallbacks.rumbleTriggers = ClRumbleTriggers; _clCallbacks.setMotionEventState = ClSetMotionEventState; + _clCallbacks.setControllerLED = ClSetControllerLED; return self; } diff --git a/Limelight/Stream/ConnectionCallbacks.h b/Limelight/Stream/ConnectionCallbacks.h index c67cd1e..f9c13b4 100644 --- a/Limelight/Stream/ConnectionCallbacks.h +++ b/Limelight/Stream/ConnectionCallbacks.h @@ -19,6 +19,7 @@ - (void) setHdrMode:(bool)enabled; - (void) rumbleTriggers:(uint16_t)controllerNumber leftTrigger:(uint16_t)leftTrigger rightTrigger:(uint16_t)rightTrigger; - (void) setMotionEventState:(uint16_t)controllerNumber motionType:(uint8_t)motionType reportRateHz:(uint16_t)reportRateHz; +- (void) setControllerLed:(uint16_t)controllerNumber r:(uint8_t)r g:(uint8_t)g b:(uint8_t)b; - (void) videoContentShown; @end diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 67db79d..d5681d7 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -538,6 +538,12 @@ [_controllerSupport setMotionEventState:controllerNumber motionType:motionType reportRateHz:reportRateHz]; } +- (void) setControllerLed:(uint16_t)controllerNumber r:(uint8_t)r g:(uint8_t)g b:(uint8_t)b { + Log(LOG_I, @"Set controller LED on gamepad %d: l%02x%02x%02x", controllerNumber, r, g, b); + + [_controllerSupport setControllerLed:controllerNumber r:r g:g b:b]; +} + - (void)connectionStatusUpdate:(int)status { Log(LOG_W, @"Connection status update: %d", status);