Skip to content

Commit

Permalink
Do not send LED updates if nothing changed
Browse files Browse the repository at this point in the history
  • Loading branch information
LIJI32 committed May 30, 2020
1 parent fa72329 commit 4d91081
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions JoyKit/JOYController.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ @implementation JOYController

// Used when creating inputs
JOYElement *_previousAxisElement;

uint8_t _playerLEDs;

}

Expand Down Expand Up @@ -342,6 +344,7 @@ - (instancetype)initWithDevice:(IOHIDDeviceRef)device reportIDFilter:(NSArray <N
_logicallyConnected = true;
_device = (IOHIDDeviceRef)CFRetain(device);
_serialSuffix = suffix;
_playerLEDs = -1;

IOHIDDeviceRegisterInputValueCallback(device, HIDInput, (void *)self);
IOHIDDeviceScheduleWithRunLoop(device, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
Expand Down Expand Up @@ -709,6 +712,10 @@ - (void)sendReport:(NSData *)report
- (void)setPlayerLEDs:(uint8_t)mask
{
mask &= 0xF;
if (mask == _playerLEDs) {
return;
}
_playerLEDs = mask;
if (_isSwitch) {
_lastVendorSpecificOutput.switchPacket.reportID = 0x1; // Rumble and LEDs
_lastVendorSpecificOutput.switchPacket.sequence++;
Expand Down

0 comments on commit 4d91081

Please sign in to comment.