From 7a6ae2d951c3234c68250791e6772d4e18e1e2bb Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 4 Jun 2021 22:21:41 +0300 Subject: [PATCH] Improved DualSense LEDs, fix several analog controls issues --- Cocoa/GBView.m | 14 +++++++++----- JoyKit/JOYController.h | 1 + JoyKit/JOYController.m | 24 ++++++++++++++++++++---- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index 99c6d4d..1e584e4 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -260,6 +260,7 @@ static const uint8_t workboy_vk_to_key[] = { - (void) flip { if (analogClockMultiplierValid && [[NSUserDefaults standardUserDefaults] boolForKey:@"GBAnalogControls"]) { + clockMultiplier = 1.0; GB_set_clock_multiplier(_gb, analogClockMultiplier); if (self.document.partner) { GB_set_clock_multiplier(self.document.partner.gb, analogClockMultiplier); @@ -290,10 +291,12 @@ static const uint8_t workboy_vk_to_key[] = { } } } - if (clockMultiplier > 1 || _turbo || (analogClockMultiplierValid && analogClockMultiplier > 1)) { + if ((!analogClockMultiplierValid && clockMultiplier > 1) || + _turbo || (analogClockMultiplierValid && analogClockMultiplier > 1)) { [self.osdView displayText:@"Fast forwarding..."]; } - else if (clockMultiplier < 1 || (analogClockMultiplierValid && analogClockMultiplier < 1)) { + else if ((!analogClockMultiplierValid && clockMultiplier < 1) || + (analogClockMultiplierValid && analogClockMultiplier < 1)) { [self.osdView displayText:@"Slow motion..."]; } current_buffer = (current_buffer + 1) % self.numberOfBuffers; @@ -499,7 +502,7 @@ static const uint8_t workboy_vk_to_key[] = { continue; } dispatch_async(dispatch_get_main_queue(), ^{ - [controller setPlayerLEDs:1 << player]; + [controller setPlayerLEDs:[controller LEDMaskForPlayer:player]]; }); NSDictionary *mapping = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitInstanceMapping"][controller.uniqueID]; if (!mapping) { @@ -558,13 +561,14 @@ static const uint8_t workboy_vk_to_key[] = { case JOYButtonUsageL1: { if (!analogClockMultiplierValid || analogClockMultiplier == 1.0 || !button.isPressed) { if (self.document.isSlave) { - GB_set_turbo_mode(self.document.partner.gb, button.isPressed, false); break; + GB_set_turbo_mode(self.document.partner.gb, button.isPressed, false); } else { - GB_set_turbo_mode(_gb, button.isPressed, button.isPressed && self.isRewinding); break; + GB_set_turbo_mode(_gb, button.isPressed, button.isPressed && self.isRewinding); } _turbo = button.isPressed; } + break; } case JOYButtonUsageR1: underclockKeyDown = button.isPressed; break; diff --git a/JoyKit/JOYController.h b/JoyKit/JOYController.h index 9ed7cf7..122371b 100644 --- a/JoyKit/JOYController.h +++ b/JoyKit/JOYController.h @@ -35,6 +35,7 @@ static NSString const *JOYHatsEmulateButtonsKey = @"JOYHatsEmulateButtons"; - (NSArray *) hats; - (void)setRumbleAmplitude:(double)amp; - (void)setPlayerLEDs:(uint8_t)mask; +- (uint8_t)LEDMaskForPlayer:(unsigned)player; @property (readonly, getter=isConnected) bool connected; @end diff --git a/JoyKit/JOYController.m b/JoyKit/JOYController.m index efdaa96..9ec378b 100644 --- a/JoyKit/JOYController.m +++ b/JoyKit/JOYController.m @@ -850,9 +850,25 @@ typedef union { [self sendReport:[NSData dataWithBytes:&_lastVendorSpecificOutput.dualsenseOutput length:sizeof(_lastVendorSpecificOutput.dualsenseOutput)]]; } +- (uint8_t)LEDMaskForPlayer:(unsigned)player +{ + if (_isDualShock3) { + return 2 << player; + } + if (_isUSBDualSense) { + switch (player) { + case 0: return 0x04; + case 1: return 0x0A; + case 2: return 0x15; + case 3: return 0x1B; + default: return 0; + } + } + return 1 << player; +} + - (void)setPlayerLEDs:(uint8_t)mask { - mask &= 0xF; if (mask == _playerLEDs) { return; } @@ -862,16 +878,16 @@ typedef union { _lastVendorSpecificOutput.switchPacket.sequence++; _lastVendorSpecificOutput.switchPacket.sequence &= 0xF; _lastVendorSpecificOutput.switchPacket.command = 0x30; // LED - _lastVendorSpecificOutput.switchPacket.commandData[0] = mask; + _lastVendorSpecificOutput.switchPacket.commandData[0] = mask & 0xF; [self sendReport:[NSData dataWithBytes:&_lastVendorSpecificOutput.switchPacket length:sizeof(_lastVendorSpecificOutput.switchPacket)]]; } else if (_isDualShock3) { _lastVendorSpecificOutput.ds3Output.reportID = 1; - _lastVendorSpecificOutput.ds3Output.ledsEnabled = mask << 1; + _lastVendorSpecificOutput.ds3Output.ledsEnabled = (mask & 0x1F); [self sendReport:[NSData dataWithBytes:&_lastVendorSpecificOutput.ds3Output length:sizeof(_lastVendorSpecificOutput.ds3Output)]]; } else if (_isDualSense) { - _lastVendorSpecificOutput.dualsenseOutput.playerLEDs = mask; + _lastVendorSpecificOutput.dualsenseOutput.playerLEDs = mask & 0x1F; [self sendDualSenseOutput]; } }