Skip to content

Commit

Permalink
Change DualSense trigger Full Click resistance depending on profile s…
Browse files Browse the repository at this point in the history
…ettings
  • Loading branch information
Ryochan7 committed Jul 20, 2021
1 parent 74cdcb0 commit 068360f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 24 deletions.
52 changes: 48 additions & 4 deletions DS4Windows/DS4Control/ControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,8 +1833,13 @@ public void CheckProfileOptions(int ind, DS4Device device, bool startUp=false)
// Reset current flick stick progress from previous profile
Mapping.flickMappingData[ind].Reset();

device.PrepareTriggerEffect(InputDevices.TriggerId.LeftTrigger, Global.L2OutputSettings[ind].TriggerEffect);
device.PrepareTriggerEffect(InputDevices.TriggerId.RightTrigger, Global.R2OutputSettings[ind].TriggerEffect);
Global.L2OutputSettings[ind].TrigEffectSettings.maxValue = (byte)(Math.Max(Global.L2ModInfo[ind].maxOutput, Global.L2ModInfo[ind].maxZone) / 100.0 * 255);
Global.R2OutputSettings[ind].TrigEffectSettings.maxValue = (byte)(Math.Max(Global.R2ModInfo[ind].maxOutput, Global.R2ModInfo[ind].maxZone) / 100.0 * 255);

device.PrepareTriggerEffect(InputDevices.TriggerId.LeftTrigger, Global.L2OutputSettings[ind].TriggerEffect,
Global.L2OutputSettings[ind].TrigEffectSettings);
device.PrepareTriggerEffect(InputDevices.TriggerId.RightTrigger, Global.R2OutputSettings[ind].TriggerEffect,
Global.R2OutputSettings[ind].TrigEffectSettings);

device.RumbleAutostopTime = getRumbleAutostopTime(ind);
device.setRumble(0, 0);
Expand Down Expand Up @@ -1911,15 +1916,54 @@ private void SetupInitialHookEvents(int ind, DS4Device device)

int tempIdx = ind;
Global.L2OutputSettings[ind].ResetEvents();
Global.L2ModInfo[ind].ResetEvents();
Global.L2OutputSettings[ind].TriggerEffectChanged += (sender, e) =>
{
device.PrepareTriggerEffect(InputDevices.TriggerId.LeftTrigger, Global.L2OutputSettings[tempIdx].TriggerEffect);
device.PrepareTriggerEffect(InputDevices.TriggerId.LeftTrigger, Global.L2OutputSettings[tempIdx].TriggerEffect,
Global.L2OutputSettings[tempIdx].TrigEffectSettings);
};
Global.L2ModInfo[ind].MaxOutputChanged += (sender, e) =>
{
TriggerDeadZoneZInfo tempInfo = sender as TriggerDeadZoneZInfo;
L2OutputSettings[tempIdx].TrigEffectSettings.maxValue = (byte)(Math.Max(tempInfo.maxOutput, tempInfo.maxZone) / 100.0 * 255.0);

// Refresh trigger effect
device.PrepareTriggerEffect(InputDevices.TriggerId.LeftTrigger, Global.L2OutputSettings[tempIdx].TriggerEffect,
Global.L2OutputSettings[tempIdx].TrigEffectSettings);
};
Global.L2ModInfo[ind].MaxZoneChanged += (sender, e) =>
{
TriggerDeadZoneZInfo tempInfo = sender as TriggerDeadZoneZInfo;
L2OutputSettings[tempIdx].TrigEffectSettings.maxValue = (byte)(Math.Max(tempInfo.maxOutput, tempInfo.maxZone) / 100.0 * 255.0);

// Refresh trigger effect
device.PrepareTriggerEffect(InputDevices.TriggerId.LeftTrigger, Global.L2OutputSettings[tempIdx].TriggerEffect,
Global.L2OutputSettings[tempIdx].TrigEffectSettings);
};

Global.R2OutputSettings[ind].ResetEvents();
Global.R2OutputSettings[ind].TriggerEffectChanged += (sender, e) =>
{
device.PrepareTriggerEffect(InputDevices.TriggerId.RightTrigger, Global.R2OutputSettings[tempIdx].TriggerEffect);
device.PrepareTriggerEffect(InputDevices.TriggerId.RightTrigger, Global.R2OutputSettings[tempIdx].TriggerEffect,
Global.R2OutputSettings[tempIdx].TrigEffectSettings);
};
Global.R2ModInfo[ind].MaxOutputChanged += (sender, e) =>
{
TriggerDeadZoneZInfo tempInfo = sender as TriggerDeadZoneZInfo;
R2OutputSettings[tempIdx].TrigEffectSettings.maxValue = (byte)(tempInfo.maxOutput / 100.0 * 255.0);

// Refresh trigger effect
device.PrepareTriggerEffect(InputDevices.TriggerId.RightTrigger, Global.R2OutputSettings[tempIdx].TriggerEffect,
Global.R2OutputSettings[tempIdx].TrigEffectSettings);
};
Global.R2ModInfo[ind].MaxZoneChanged += (sender, e) =>
{
TriggerDeadZoneZInfo tempInfo = sender as TriggerDeadZoneZInfo;
R2OutputSettings[tempIdx].TrigEffectSettings.maxValue = (byte)(tempInfo.maxOutput / 100.0 * 255.0);

// Refresh trigger effect
device.PrepareTriggerEffect(InputDevices.TriggerId.RightTrigger, Global.R2OutputSettings[tempIdx].TriggerEffect,
Global.R2OutputSettings[tempIdx].TrigEffectSettings);
};
}

Expand Down
62 changes: 61 additions & 1 deletion DS4Windows/DS4Control/ProfilePropGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,63 @@ public class StickAntiSnapbackInfo

public class TriggerDeadZoneZInfo
{
public byte deadZone; // Trigger deadzone is expressed in axis units
// Trigger deadzone is expressed in axis units (bad old convention)
public byte deadZone;

public byte DeadZone
{
get => deadZone;
set
{
if (deadZone == value) return;
deadZone = value;
DeadZoneChanged?.Invoke(this, EventArgs.Empty);
}
}
public event EventHandler DeadZoneChanged;

public int antiDeadZone;
public int maxZone = 100;
public int MaxZone
{
get => maxZone;
set
{
if (maxZone == value) return;
maxZone = value;
MaxZoneChanged?.Invoke(this, EventArgs.Empty);
}
}
public event EventHandler MaxZoneChanged;

public double maxOutput = 100.0;

public double MaxOutput
{
get => maxOutput;
set
{
if (maxOutput == value) return;
maxOutput = value;
MaxOutputChanged?.Invoke(this, EventArgs.Empty);
}
}
public event EventHandler MaxOutputChanged;

public void Reset()
{
deadZone = 0;
antiDeadZone = 0;
MaxZone = 100;
MaxOutput = 100.0;
}

public void ResetEvents()
{
MaxZoneChanged = null;
MaxOutputChanged = null;
DeadZoneChanged = null;
}
}

public class GyroMouseInfo
Expand Down Expand Up @@ -780,6 +833,13 @@ public InputDevices.TriggerEffects TriggerEffect
}
public event EventHandler TriggerEffectChanged;

public InputDevices.TriggerEffectSettings effectSettings =
new InputDevices.TriggerEffectSettings();
public ref InputDevices.TriggerEffectSettings TrigEffectSettings
{
get => ref effectSettings;
}

public void ResetSettings()
{
//mode = TriggerMode.Normal;
Expand Down
10 changes: 6 additions & 4 deletions DS4Windows/DS4Control/ScpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7122,10 +7122,12 @@ private void ResetProfile(int device)
lsModInfo[device].maxOutput = rsModInfo[device].maxOutput = 100.0;
lsModInfo[device].fuzz = rsModInfo[device].fuzz = StickDeadZoneInfo.DEFAULT_FUZZ;

l2ModInfo[device].deadZone = r2ModInfo[device].deadZone = 0;
l2ModInfo[device].antiDeadZone = r2ModInfo[device].antiDeadZone = 0;
l2ModInfo[device].maxZone = r2ModInfo[device].maxZone = 100;
l2ModInfo[device].maxOutput = r2ModInfo[device].maxOutput = 100.0;
//l2ModInfo[device].deadZone = r2ModInfo[device].deadZone = 0;
//l2ModInfo[device].antiDeadZone = r2ModInfo[device].antiDeadZone = 0;
//l2ModInfo[device].maxZone = r2ModInfo[device].maxZone = 100;
//l2ModInfo[device].maxOutput = r2ModInfo[device].maxOutput = 100.0;
l2ModInfo[device].Reset();
r2ModInfo[device].Reset();

LSRotation[device] = 0.0;
RSRotation[device] = 0.0;
Expand Down
16 changes: 8 additions & 8 deletions DS4Windows/DS4Forms/ViewModels/ProfileSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,14 +1318,14 @@ public double R2DeadZone

public double L2MaxZone
{
get => Global.L2ModInfo[device].maxZone / 100.0;
set => Global.L2ModInfo[device].maxZone = (int)(value * 100.0);
get => Global.L2ModInfo[device].MaxZone / 100.0;
set => Global.L2ModInfo[device].MaxZone = (int)(value * 100.0);
}

public double R2MaxZone
{
get => Global.R2ModInfo[device].maxZone / 100.0;
set => Global.R2ModInfo[device].maxZone = (int)(value * 100.0);
get => Global.R2ModInfo[device].MaxZone / 100.0;
set => Global.R2ModInfo[device].MaxZone = (int)(value * 100.0);
}

public double L2AntiDeadZone
Expand All @@ -1342,14 +1342,14 @@ public double R2AntiDeadZone

public double L2MaxOutput
{
get => Global.L2ModInfo[device].maxOutput / 100.0;
set => Global.L2ModInfo[device].maxOutput = value * 100.0;
get => Global.L2ModInfo[device].MaxOutput / 100.0;
set => Global.L2ModInfo[device].MaxOutput = value * 100.0;
}

public double R2MaxOutput
{
get => Global.R2ModInfo[device].maxOutput / 100.0;
set => Global.R2ModInfo[device].maxOutput = value * 100.0;
get => Global.R2ModInfo[device].MaxOutput / 100.0;
set => Global.R2ModInfo[device].MaxOutput = value * 100.0;
}

public double L2Sens
Expand Down
2 changes: 1 addition & 1 deletion DS4Windows/DS4Library/DS4Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@ private void SetupOptionsEvents()
}

public virtual void PrepareTriggerEffect(InputDevices.TriggerId trigger,
InputDevices.TriggerEffects effect)
InputDevices.TriggerEffects effect, InputDevices.TriggerEffectSettings effectSettings)
{
}

Expand Down
17 changes: 11 additions & 6 deletions DS4Windows/DS4Library/InputDevices/DualSenseDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public struct TriggerEffectData
public byte triggerPressedStrength;
public byte triggerActuationFrequency;

public void ChangeData(TriggerEffects effect)
public void ChangeData(TriggerEffects effect, TriggerEffectSettings effectSettings)
{
switch (effect)
{
Expand All @@ -69,9 +69,14 @@ public void ChangeData(TriggerEffects effect)
triggerPressedStrength = triggerActuationFrequency = 0;
break;
case TriggerEffects.FullClick:
int tempStartResValue = Math.Max((int)effectSettings.maxValue, 0);
//Debug.WriteLine(tempStartResValue);
triggerMotorMode = 0x02;
triggerStartResistance = 0x94;
triggerEffectForce = 0xB4;
//triggerStartResistance = 0x94;
triggerStartResistance = (byte)(0x94 * (tempStartResValue / 255.0));
//triggerEffectForce = 0xB4;
triggerEffectForce = (byte)((0xB4 - triggerStartResistance) * (effectSettings.maxValue / 255.0) + triggerStartResistance);
//Debug.WriteLine(triggerEffectForce);
triggerRangeForce = 0xFF;
triggerNearReleaseStrength = 0x00;
triggerNearMiddleStrength = 0x00;
Expand Down Expand Up @@ -1301,15 +1306,15 @@ private void PreparePlayerLEDBarByte()
}
}

public override void PrepareTriggerEffect(TriggerId trigger, TriggerEffects effect)
public override void PrepareTriggerEffect(TriggerId trigger, TriggerEffects effect, TriggerEffectSettings effectSettings)
{
if (trigger == TriggerId.LeftTrigger)
{
l2EffectData.ChangeData(effect);
l2EffectData.ChangeData(effect, effectSettings);
}
else if (trigger == TriggerId.RightTrigger)
{
r2EffectData.ChangeData(effect);
r2EffectData.ChangeData(effect, effectSettings);
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions DS4Windows/DS4Library/InputDevices/TriggerEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public enum TriggerId : ushort
Trigger1,
RightTrigger = Trigger1,
}

public struct TriggerEffectSettings
{
public byte maxValue;
public byte startValue;
}
}

0 comments on commit 068360f

Please sign in to comment.