From d599fd9110a99b5f2532d59be879c1ba7fd394b3 Mon Sep 17 00:00:00 2001 From: Kaldaien Date: Fri, 29 Nov 2024 23:31:59 -0500 Subject: [PATCH] Properly remove Adaptive Trigger force feedback when impulse vibration stops --- CHANGELOG.txt | 6 +- .../DirectXTex_Desktop_2015.suppress | 52 +++++++++++++++ include/SpecialK/DLL_VERSION.H | 4 +- include/SpecialK/input/input.h | 4 +- src/input/hid_reports/playstation.cpp | 66 ++++++++++++------- 5 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 depends/src/DirectXTex/DirectXTex_Desktop_2015.suppress diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8f7d8eee2..abf49c93d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,8 @@ -24.11.30.2 +24.11.30.3 +========== + + Properly remove Adaptive Trigger force feedback when impulse vibration stops + +24.11.30.2 ========== + Implement PlayStation Adaptive Trigger support for DualSense controllers connected using Bluetooth. diff --git a/depends/src/DirectXTex/DirectXTex_Desktop_2015.suppress b/depends/src/DirectXTex/DirectXTex_Desktop_2015.suppress new file mode 100644 index 000000000..b2415f554 --- /dev/null +++ b/depends/src/DirectXTex/DirectXTex_Desktop_2015.suppress @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + false + + + debug_utils.h + V802 + On _-bit platform, structure size can be reduced from _ to _ bytes by rearranging the fields according to their sizes in decreasing order. + 1907953360 + 123 + 14801337 + + \ No newline at end of file diff --git a/include/SpecialK/DLL_VERSION.H b/include/SpecialK/DLL_VERSION.H index c3d547afa..0b70d3750 100644 --- a/include/SpecialK/DLL_VERSION.H +++ b/include/SpecialK/DLL_VERSION.H @@ -3,8 +3,8 @@ #define SK_YEAR 24 #define SK_MONTH 11 #define SK_DATE 30 -#define SK_REV_N 2 -#define SK_REV 2 +#define SK_REV_N 3 +#define SK_REV 3 #ifndef _A2 #define _A2(a) #a diff --git a/include/SpecialK/input/input.h b/include/SpecialK/input/input.h index 8bbf6bee1..8edc80da2 100644 --- a/include/SpecialK/input/input.h +++ b/include/SpecialK/input/input.h @@ -1044,6 +1044,8 @@ struct SK_HID_PlayStationDevice struct { volatile ULONG left; volatile ULONG right; + ULONG last_left; + ULONG last_right; } trigger; volatile ULONG max_val = 0; @@ -1052,7 +1054,7 @@ struct SK_HID_PlayStationDevice // some kind of attempt to set a new value... otherwise, it // will tend to vibrate infinitely. static constexpr auto MAX_TTL_IN_MSECS = 1000UL; - } _vibration = { 0, 0, 0, 0, 0, 0 }; + } _vibration = { 0, 0, 0, 0, 0, 0, 0, 0 }; void setRGB (BYTE red, BYTE green, BYTE blue) { _color.r = red; diff --git a/src/input/hid_reports/playstation.cpp b/src/input/hid_reports/playstation.cpp index 4c04e24a4..35ea94fba 100644 --- a/src/input/hid_reports/playstation.cpp +++ b/src/input/hid_reports/playstation.cpp @@ -2626,19 +2626,26 @@ SK_HID_PlayStationDevice::write_output_report (bool force) SK_HID_DualSense_SetStateData* output = (SK_HID_DualSense_SetStateData *)&pOutputRaw [1]; - const ULONG dwRightMotor = ReadULongAcquire (&pDevice->_vibration.right); - const ULONG dwLeftMotor = ReadULongAcquire (&pDevice->_vibration.left); + const ULONG dwRightMotor = ReadULongAcquire (&pDevice->_vibration.right); + const ULONG dwLeftMotor = ReadULongAcquire (&pDevice->_vibration.left); + const ULONG dwRightTrigger = ReadULongAcquire (&pDevice->_vibration.trigger.right); + const ULONG dwLeftTrigger = ReadULongAcquire (&pDevice->_vibration.trigger.left); + + const ULONG last_trigger_r = pDevice->_vibration.trigger.last_right; + const ULONG last_trigger_l = pDevice->_vibration.trigger.last_left; const bool bRumble = (dwRightMotor != 0 || - dwLeftMotor != 0) || (ReadULongAcquire (&pDevice->_vibration.trigger.left) != 0 - || ReadULongAcquire (&pDevice->_vibration.trigger.right) != 0); + dwLeftMotor != 0) || (dwLeftTrigger != 0 + || dwRightTrigger != 0); // 500 msec grace period before allowing controller to use native haptics output->UseRumbleNotHaptics = bRumble || - (ReadULongAcquire (&pDevice->_vibration.last_set) > SK::ControlPanel::current_time - 500UL); + (ReadULongAcquire (&pDevice->_vibration.last_set) > SK::ControlPanel::current_time - 500UL) + || last_trigger_r != 0 + || last_trigger_l != 0; - if (bRumble) + if (bRumble || (last_trigger_r != 0 || last_trigger_l != 0)) { WriteULongRelease (&pDevice->_vibration.last_set, SK::ControlPanel::current_time); output->AllowMotorPowerLevel = true; @@ -2674,31 +2681,35 @@ SK_HID_PlayStationDevice::write_output_report (bool force) { 0x06, 15, 63, 0, 0, 0, 0, 0, 0, 0, 0 }, }; - if (bRumble) + if (bRumble || (last_trigger_r != 0 || last_trigger_l != 0)) { - if (pDevice->_vibration.trigger.left != 0) + if (dwLeftTrigger != 0) { output->AllowLeftTriggerFFB = true; const auto trigger_effect = 2; memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect])); output->LeftTriggerFFB [2] = static_cast (std::clamp ( - static_cast (pDevice->_vibration.trigger.left) * + static_cast (dwLeftTrigger) * config.input.gamepad.impulse_strength_l, 0.0f, 1.0f) ); - } else { output->AllowLeftTriggerFFB = true; + pDevice->_vibration.trigger.last_left = dwLeftTrigger; + } else { output->AllowLeftTriggerFFB = true; const auto trigger_effect = 0; memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect])); + pDevice->_vibration.trigger.last_left = dwLeftTrigger; } - if (pDevice->_vibration.trigger.right != 0) + if (dwRightTrigger != 0) { output->AllowRightTriggerFFB = true; const auto trigger_effect = 2; memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect])); output->RightTriggerFFB [2] = static_cast (std::clamp ( - static_cast (pDevice->_vibration.trigger.right) * + static_cast (dwRightTrigger) * config.input.gamepad.impulse_strength_r, 0.0f, 1.0f) ); + pDevice->_vibration.trigger.last_right = dwRightTrigger; } else { output->AllowRightTriggerFFB = true; const auto trigger_effect = 0; memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect])); + pDevice->_vibration.trigger.last_right = dwRightTrigger; } } @@ -2817,17 +2828,24 @@ SK_HID_PlayStationDevice::write_output_report (bool force) SK_HID_DualSense_SetStateData* output = (SK_HID_DualSense_SetStateData *)&bt_data [3]; - const ULONG dwRightMotor = ReadULongAcquire (&pDevice->_vibration.right); - const ULONG dwLeftMotor = ReadULongAcquire (&pDevice->_vibration.left); + const ULONG dwRightMotor = ReadULongAcquire (&pDevice->_vibration.right); + const ULONG dwLeftMotor = ReadULongAcquire (&pDevice->_vibration.left); + const ULONG dwRightTrigger = ReadULongAcquire (&pDevice->_vibration.trigger.right); + const ULONG dwLeftTrigger = ReadULongAcquire (&pDevice->_vibration.trigger.left); + + const ULONG last_trigger_r = pDevice->_vibration.trigger.last_right; + const ULONG last_trigger_l = pDevice->_vibration.trigger.last_left; const bool bRumble = (dwRightMotor != 0 || - dwLeftMotor != 0) || (ReadULongAcquire (&pDevice->_vibration.trigger.left) != 0 - || ReadULongAcquire (&pDevice->_vibration.trigger.right) != 0); + dwLeftMotor != 0) || (dwRightTrigger != 0 + || dwLeftTrigger != 0); // 500 msec grace period before allowing controller to use native haptics output->UseRumbleNotHaptics = bRumble || - (ReadULongAcquire (&pDevice->_vibration.last_set) > SK::ControlPanel::current_time - 500UL); + (ReadULongAcquire (&pDevice->_vibration.last_set) > SK::ControlPanel::current_time - 500UL) + || last_trigger_r != 0 + || last_trigger_l != 0; if (bRumble) { @@ -2842,31 +2860,35 @@ SK_HID_PlayStationDevice::write_output_report (bool force) { 0x06, 15, 63, 0, 0, 0, 0, 0, 0, 0, 0 }, }; - if (bRumble) + if (bRumble || (last_trigger_r != 0 || last_trigger_l != 0)) { - if (pDevice->_vibration.trigger.left != 0) + if (dwLeftTrigger != 0) { output->AllowLeftTriggerFFB = true; const auto trigger_effect = 2; memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect])); output->LeftTriggerFFB [2] = static_cast (std::clamp ( - static_cast (pDevice->_vibration.trigger.left) * + static_cast (dwLeftTrigger) * config.input.gamepad.impulse_strength_l, 0.0f, 1.0f) ); + pDevice->_vibration.trigger.last_left = dwLeftTrigger; } else { output->AllowLeftTriggerFFB = true; const auto trigger_effect = 0; memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect])); + pDevice->_vibration.trigger.last_left = dwLeftTrigger; } - if (pDevice->_vibration.trigger.right != 0) + if (dwRightTrigger != 0) { output->AllowRightTriggerFFB = true; const auto trigger_effect = 2; memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect])); output->RightTriggerFFB [2] = static_cast (std::clamp ( - static_cast (pDevice->_vibration.trigger.right) * + static_cast (dwRightTrigger) * config.input.gamepad.impulse_strength_r, 0.0f, 1.0f) ); + pDevice->_vibration.trigger.last_right = dwRightTrigger; } else { output->AllowRightTriggerFFB = true; const auto trigger_effect = 0; memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect])); + pDevice->_vibration.trigger.last_right = dwRightTrigger; } } output->AllowMuteLight = true;