Skip to content

Commit

Permalink
Apply/reset trigger resistance for DualSense controllers every time t…
Browse files Browse the repository at this point in the history
…hey connect/reconnect, and do not wait for vibration data to be written first.
  • Loading branch information
Kaldaien committed Dec 15, 2024
1 parent 0910391 commit 8ef7346
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
24.12.15
24.12.15.1
==========
+ Apply/reset trigger resistance for DualSense controllers every time they
connect/reconnect, and do not wait for vibration data to be written first.

24.12.15
========
+ Added configurable constant trigger resistance for DualSense controlelrs...

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 12
#define SK_DATE 15
#define SK_REV_N 0
#define SK_REV 0
#define SK_REV_N 1
#define SK_REV 1

#ifndef _A2
#define _A2(a) #a
Expand Down
8 changes: 4 additions & 4 deletions include/SpecialK/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,10 @@ struct SK_HID_PlayStationDevice
ULONG last_right = 0;
ULONG start_left = 0; // The analog trigger's value when vibration started
ULONG start_right = 0; // The analog trigger's value when vibration started
float last_resist_start_l = -1.0f;
float last_resist_start_r = -1.0f;
float last_resist_str_l = -1.0f;
float last_resist_str_r = -1.0f;
float last_resist_start_l = -2.0f;
float last_resist_start_r = -2.0f;
float last_resist_str_l = -2.0f;
float last_resist_str_r = -2.0f;
bool used; // Flagged the first time a game sets trigger vibration
} trigger;

Expand Down
56 changes: 28 additions & 28 deletions src/input/hid_reports/playstation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2718,10 +2718,21 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
const ULONG last_trigger_r = pDevice->_vibration.trigger.last_right;
const ULONG last_trigger_l = pDevice->_vibration.trigger.last_left;

float& fLastResistStrL = pDevice->_vibration.trigger.last_resist_str_l;
float& fLastResistStrR = pDevice->_vibration.trigger.last_resist_str_r;
float& fLastResistPosL = pDevice->_vibration.trigger.last_resist_start_l;
float& fLastResistPosR = pDevice->_vibration.trigger.last_resist_start_r;

const bool bResistChange =
(std::exchange (fLastResistStrL, config.input.gamepad.dualsense.resist_strength_l) != config.input.gamepad.dualsense.resist_strength_l) |
(std::exchange (fLastResistStrR, config.input.gamepad.dualsense.resist_strength_r) != config.input.gamepad.dualsense.resist_strength_r) |
(std::exchange (fLastResistPosR, config.input.gamepad.dualsense.resist_start_r) != config.input.gamepad.dualsense.resist_start_r) |
(std::exchange (fLastResistPosL, config.input.gamepad.dualsense.resist_start_l) != config.input.gamepad.dualsense.resist_start_l);

const bool bRumble =
(dwRightMotor != 0 ||
dwLeftMotor != 0) || (dwLeftTrigger != 0
|| dwRightTrigger != 0);
|| dwRightTrigger != 0) || bResistChange;

// 500 msec grace period before allowing controller to use native haptics
output->UseRumbleNotHaptics = bRumble ||
Expand Down Expand Up @@ -2761,17 +2772,6 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
ReadULongAcquire (&pDevice->_vibration.left)
);

float& fLastResistStrL = pDevice->_vibration.trigger.last_resist_str_l;
float& fLastResistStrR = pDevice->_vibration.trigger.last_resist_str_r;
float& fLastResistPosL = pDevice->_vibration.trigger.last_resist_start_l;
float& fLastResistPosR = pDevice->_vibration.trigger.last_resist_start_r;

const bool bResistChange =
(std::exchange (fLastResistStrL, config.input.gamepad.dualsense.resist_strength_l) != config.input.gamepad.dualsense.resist_strength_l) |
(std::exchange (fLastResistStrR, config.input.gamepad.dualsense.resist_strength_r) != config.input.gamepad.dualsense.resist_strength_r) |
(std::exchange (fLastResistPosR, config.input.gamepad.dualsense.resist_start_r) != config.input.gamepad.dualsense.resist_start_r) |
(std::exchange (fLastResistPosL, config.input.gamepad.dualsense.resist_start_l) != config.input.gamepad.dualsense.resist_start_l);

if (bRumble || (last_trigger_r != 0 || last_trigger_l != 0) || bResistChange)
{
auto effect = (dwLeftTrigger != 0) ?
Expand Down Expand Up @@ -2936,10 +2936,21 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
const ULONG last_trigger_r = pDevice->_vibration.trigger.last_right;
const ULONG last_trigger_l = pDevice->_vibration.trigger.last_left;

float& fLastResistStrL = pDevice->_vibration.trigger.last_resist_str_l;
float& fLastResistStrR = pDevice->_vibration.trigger.last_resist_str_r;
float& fLastResistPosL = pDevice->_vibration.trigger.last_resist_start_l;
float& fLastResistPosR = pDevice->_vibration.trigger.last_resist_start_r;

const bool bResistChange =
(std::exchange (fLastResistStrL, config.input.gamepad.dualsense.resist_strength_l) != config.input.gamepad.dualsense.resist_strength_l) |
(std::exchange (fLastResistStrR, config.input.gamepad.dualsense.resist_strength_r) != config.input.gamepad.dualsense.resist_strength_r) |
(std::exchange (fLastResistPosR, config.input.gamepad.dualsense.resist_start_r) != config.input.gamepad.dualsense.resist_start_r) |
(std::exchange (fLastResistPosL, config.input.gamepad.dualsense.resist_start_l) != config.input.gamepad.dualsense.resist_start_l);

const bool bRumble =
(dwRightMotor != 0 ||
dwLeftMotor != 0) || (dwLeftTrigger != 0
|| dwRightTrigger != 0);
|| dwRightTrigger != 0) || bResistChange;

// 500 msec grace period before allowing controller to use native haptics
output->UseRumbleNotHaptics = bRumble ||
Expand Down Expand Up @@ -2979,17 +2990,6 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
ReadULongAcquire (&pDevice->_vibration.left)
);

float& fLastResistStrL = pDevice->_vibration.trigger.last_resist_str_l;
float& fLastResistStrR = pDevice->_vibration.trigger.last_resist_str_r;
float& fLastResistPosL = pDevice->_vibration.trigger.last_resist_start_l;
float& fLastResistPosR = pDevice->_vibration.trigger.last_resist_start_r;

const bool bResistChange =
(std::exchange (fLastResistStrL, config.input.gamepad.dualsense.resist_strength_l) != config.input.gamepad.dualsense.resist_strength_l) |
(std::exchange (fLastResistStrR, config.input.gamepad.dualsense.resist_strength_r) != config.input.gamepad.dualsense.resist_strength_r) |
(std::exchange (fLastResistPosR, config.input.gamepad.dualsense.resist_start_r) != config.input.gamepad.dualsense.resist_start_r) |
(std::exchange (fLastResistPosL, config.input.gamepad.dualsense.resist_start_l) != config.input.gamepad.dualsense.resist_start_l);

if (bRumble || (last_trigger_r != 0 || last_trigger_l != 0) || bResistChange)
{
auto effect = (dwLeftTrigger != 0) ?
Expand Down Expand Up @@ -3981,10 +3981,10 @@ SK_HID_PlayStationDevice::reset_device (void)
_vibration.trigger.last_right = 0;
_vibration.trigger.start_left = 0;
_vibration.trigger.start_right = 0;
_vibration.trigger.last_resist_start_l = -1.0f;
_vibration.trigger.last_resist_start_r = -1.0f;
_vibration.trigger.last_resist_str_l = -1.0f;
_vibration.trigger.last_resist_str_r = -1.0f;
_vibration.trigger.last_resist_start_l = -2.0f;
_vibration.trigger.last_resist_start_r = -2.0f;
_vibration.trigger.last_resist_str_l = -2.0f;
_vibration.trigger.last_resist_str_r = -2.0f;

WriteULong64Release (&xinput.last_active, 0);

Expand Down

0 comments on commit 8ef7346

Please sign in to comment.