Improved DualSense LEDs, fix several analog controls issues

This commit is contained in:
Lior Halphon 2021-06-04 22:21:41 +03:00
parent e71d3a7d3c
commit 7a6ae2d951
3 changed files with 30 additions and 9 deletions

View File

@ -260,6 +260,7 @@ static const uint8_t workboy_vk_to_key[] = {
- (void) flip - (void) flip
{ {
if (analogClockMultiplierValid && [[NSUserDefaults standardUserDefaults] boolForKey:@"GBAnalogControls"]) { if (analogClockMultiplierValid && [[NSUserDefaults standardUserDefaults] boolForKey:@"GBAnalogControls"]) {
clockMultiplier = 1.0;
GB_set_clock_multiplier(_gb, analogClockMultiplier); GB_set_clock_multiplier(_gb, analogClockMultiplier);
if (self.document.partner) { if (self.document.partner) {
GB_set_clock_multiplier(self.document.partner.gb, analogClockMultiplier); 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..."]; [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..."]; [self.osdView displayText:@"Slow motion..."];
} }
current_buffer = (current_buffer + 1) % self.numberOfBuffers; current_buffer = (current_buffer + 1) % self.numberOfBuffers;
@ -499,7 +502,7 @@ static const uint8_t workboy_vk_to_key[] = {
continue; continue;
} }
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[controller setPlayerLEDs:1 << player]; [controller setPlayerLEDs:[controller LEDMaskForPlayer:player]];
}); });
NSDictionary *mapping = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitInstanceMapping"][controller.uniqueID]; NSDictionary *mapping = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitInstanceMapping"][controller.uniqueID];
if (!mapping) { if (!mapping) {
@ -558,13 +561,14 @@ static const uint8_t workboy_vk_to_key[] = {
case JOYButtonUsageL1: { case JOYButtonUsageL1: {
if (!analogClockMultiplierValid || analogClockMultiplier == 1.0 || !button.isPressed) { if (!analogClockMultiplierValid || analogClockMultiplier == 1.0 || !button.isPressed) {
if (self.document.isSlave) { 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 { 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; _turbo = button.isPressed;
} }
break;
} }
case JOYButtonUsageR1: underclockKeyDown = button.isPressed; break; case JOYButtonUsageR1: underclockKeyDown = button.isPressed; break;

View File

@ -35,6 +35,7 @@ static NSString const *JOYHatsEmulateButtonsKey = @"JOYHatsEmulateButtons";
- (NSArray<JOYHat *> *) hats; - (NSArray<JOYHat *> *) hats;
- (void)setRumbleAmplitude:(double)amp; - (void)setRumbleAmplitude:(double)amp;
- (void)setPlayerLEDs:(uint8_t)mask; - (void)setPlayerLEDs:(uint8_t)mask;
- (uint8_t)LEDMaskForPlayer:(unsigned)player;
@property (readonly, getter=isConnected) bool connected; @property (readonly, getter=isConnected) bool connected;
@end @end

View File

@ -850,9 +850,25 @@ typedef union {
[self sendReport:[NSData dataWithBytes:&_lastVendorSpecificOutput.dualsenseOutput length:sizeof(_lastVendorSpecificOutput.dualsenseOutput)]]; [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 - (void)setPlayerLEDs:(uint8_t)mask
{ {
mask &= 0xF;
if (mask == _playerLEDs) { if (mask == _playerLEDs) {
return; return;
} }
@ -862,16 +878,16 @@ typedef union {
_lastVendorSpecificOutput.switchPacket.sequence++; _lastVendorSpecificOutput.switchPacket.sequence++;
_lastVendorSpecificOutput.switchPacket.sequence &= 0xF; _lastVendorSpecificOutput.switchPacket.sequence &= 0xF;
_lastVendorSpecificOutput.switchPacket.command = 0x30; // LED _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)]]; [self sendReport:[NSData dataWithBytes:&_lastVendorSpecificOutput.switchPacket length:sizeof(_lastVendorSpecificOutput.switchPacket)]];
} }
else if (_isDualShock3) { else if (_isDualShock3) {
_lastVendorSpecificOutput.ds3Output.reportID = 1; _lastVendorSpecificOutput.ds3Output.reportID = 1;
_lastVendorSpecificOutput.ds3Output.ledsEnabled = mask << 1; _lastVendorSpecificOutput.ds3Output.ledsEnabled = (mask & 0x1F);
[self sendReport:[NSData dataWithBytes:&_lastVendorSpecificOutput.ds3Output length:sizeof(_lastVendorSpecificOutput.ds3Output)]]; [self sendReport:[NSData dataWithBytes:&_lastVendorSpecificOutput.ds3Output length:sizeof(_lastVendorSpecificOutput.ds3Output)]];
} }
else if (_isDualSense) { else if (_isDualSense) {
_lastVendorSpecificOutput.dualsenseOutput.playerLEDs = mask; _lastVendorSpecificOutput.dualsenseOutput.playerLEDs = mask & 0x1F;
[self sendDualSenseOutput]; [self sendDualSenseOutput];
} }
} }