Skip to content

Commit

Permalink
Properly remove Adaptive Trigger force feedback when impulse vibratio…
Browse files Browse the repository at this point in the history
…n stops
  • Loading branch information
Kaldaien committed Nov 30, 2024
1 parent e1a65a6 commit 7c9d5bc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions include/SpecialK/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions src/input/hid_reports/playstation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2629,16 +2629,21 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
const ULONG dwRightMotor = ReadULongAcquire (&pDevice->_vibration.right);
const ULONG dwLeftMotor = ReadULongAcquire (&pDevice->_vibration.left);

static uint8_t last_trigger_r = 0;
static uint8_t last_trigger_l = 0;

const bool bRumble =
(dwRightMotor != 0 ||
dwLeftMotor != 0) || (ReadULongAcquire (&pDevice->_vibration.trigger.left) != 0
|| ReadULongAcquire (&pDevice->_vibration.trigger.right) != 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;
Expand Down Expand Up @@ -2674,7 +2679,7 @@ 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)
{ output->AllowLeftTriggerFFB = true;
Expand All @@ -2684,9 +2689,11 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.left) *
config.input.gamepad.impulse_strength_l, 0.0f, 1.0f) );
last_trigger_l = pDevice->_vibration.trigger.left != 0;
} else { output->AllowLeftTriggerFFB = true;
const auto trigger_effect = 0;
memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
last_trigger_l = pDevice->_vibration.trigger.left != 0;
}
if (pDevice->_vibration.trigger.right != 0)
{ output->AllowRightTriggerFFB = true;
Expand All @@ -2696,9 +2703,11 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.right) *
config.input.gamepad.impulse_strength_r, 0.0f, 1.0f) );
last_trigger_r = pDevice->_vibration.trigger.right != 0;
} else { output->AllowRightTriggerFFB = true;
const auto trigger_effect = 0;
memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
last_trigger_r = pDevice->_vibration.trigger.right != 0;
}
}

Expand Down Expand Up @@ -2820,14 +2829,19 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
const ULONG dwRightMotor = ReadULongAcquire (&pDevice->_vibration.right);
const ULONG dwLeftMotor = ReadULongAcquire (&pDevice->_vibration.left);

static uint8_t last_trigger_r = 0;
static uint8_t last_trigger_l = 0;

const bool bRumble =
(dwRightMotor != 0 ||
dwLeftMotor != 0) || (ReadULongAcquire (&pDevice->_vibration.trigger.left) != 0
|| ReadULongAcquire (&pDevice->_vibration.trigger.right) != 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)
{
Expand All @@ -2842,7 +2856,7 @@ 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)
{ output->AllowLeftTriggerFFB = true;
Expand All @@ -2852,9 +2866,11 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.left) *
config.input.gamepad.impulse_strength_l, 0.0f, 1.0f) );
last_trigger_l = pDevice->_vibration.trigger.left != 0;
} else { output->AllowLeftTriggerFFB = true;
const auto trigger_effect = 0;
memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
last_trigger_l = pDevice->_vibration.trigger.left != 0;
}
if (pDevice->_vibration.trigger.right != 0)
{ output->AllowRightTriggerFFB = true;
Expand All @@ -2864,9 +2880,11 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.right) *
config.input.gamepad.impulse_strength_r, 0.0f, 1.0f) );
last_trigger_r = pDevice->_vibration.trigger.right != 0;
} else { output->AllowRightTriggerFFB = true;
const auto trigger_effect = 0;
memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
last_trigger_r = pDevice->_vibration.trigger.right != 0;
}
}
output->AllowMuteLight = true;
Expand Down

0 comments on commit 7c9d5bc

Please sign in to comment.