From b444ecd1eedfc1895cddb089d897142281125c4d Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 1 Jun 2021 00:46:06 +0300 Subject: [PATCH] Fix configuration of analog shoulder buttons for analog turbo/slow motion when using a PS5 controller --- Cocoa/GBPreferencesWindow.m | 41 +++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m index 96e9c160..22c60e8f 100644 --- a/Cocoa/GBPreferencesWindow.m +++ b/Cocoa/GBPreferencesWindow.m @@ -478,31 +478,46 @@ static const unsigned gb_to_joykit[] = { - [GBRight]=JOYButtonUsageDPadRight, - [GBLeft]=JOYButtonUsageDPadLeft, - [GBUp]=JOYButtonUsageDPadUp, - [GBDown]=JOYButtonUsageDPadDown, - [GBA]=JOYButtonUsageA, - [GBB]=JOYButtonUsageB, - [GBSelect]=JOYButtonUsageSelect, - [GBStart]=JOYButtonUsageStart, - [GBTurbo]=JOYButtonUsageL1, - [GBRewind]=JOYButtonUsageL2, - [GBUnderclock]=JOYButtonUsageR1, + [GBRight] = JOYButtonUsageDPadRight, + [GBLeft] = JOYButtonUsageDPadLeft, + [GBUp] = JOYButtonUsageDPadUp, + [GBDown] = JOYButtonUsageDPadDown, + [GBA] = JOYButtonUsageA, + [GBB] = JOYButtonUsageB, + [GBSelect] = JOYButtonUsageSelect, + [GBStart] = JOYButtonUsageStart, + [GBTurbo] = JOYButtonUsageL1, + [GBRewind] = JOYButtonUsageL2, + [GBUnderclock] = JOYButtonUsageR1, }; + // Todo: JoyKit might need an API to match an axis to a button if (joystick_configuration_state == GBUnderclock) { for (JOYAxis *axis in controller.axes) { - if (axis.value > 0.5) { + if (axis.value > 0.5 || + (axis.usage == JOYAxisUsageL1 && button.usage == JOYButtonUsageL1) || + (axis.usage == JOYAxisUsageL2 && button.usage == JOYButtonUsageL2) || + (axis.usage == JOYAxisUsageL3 && button.usage == JOYButtonUsageL3) || + (axis.usage == JOYAxisUsageR1 && button.usage == JOYButtonUsageR1) || + (axis.usage == JOYAxisUsageR2 && button.usage == JOYButtonUsageR2) || + (axis.usage == JOYAxisUsageR3 && button.usage == JOYButtonUsageR3)) { mapping[@"AnalogUnderclock"] = @(axis.uniqueID); + break; } } } if (joystick_configuration_state == GBTurbo) { for (JOYAxis *axis in controller.axes) { - if (axis.value > 0.5) { + if (axis.value > 0.5 || + (axis.usage == JOYAxisUsageL1 && button.usage == JOYButtonUsageL1) || + (axis.usage == JOYAxisUsageL2 && button.usage == JOYButtonUsageL2) || + (axis.usage == JOYAxisUsageL3 && button.usage == JOYButtonUsageL3) || + (axis.usage == JOYAxisUsageR1 && button.usage == JOYButtonUsageR1) || + (axis.usage == JOYAxisUsageR2 && button.usage == JOYButtonUsageR2) || + (axis.usage == JOYAxisUsageR3 && button.usage == JOYButtonUsageR3)) { mapping[@"AnalogTurbo"] = @(axis.uniqueID); + break; } } }