Compare commits

...

3 commits

2 changed files with 104 additions and 19 deletions

View file

@ -11,15 +11,14 @@ namespace SteamController.Devices
private const int velocityWindowSize = 20; // Velocity smoothing window size
private const double minGlideMagnitude = 0.8; // Minimum velocity to start glide
private const double minGlideVelocity = 0.15; // Minimum velocity to continue glide
private const double hapticTriggerDelta = 45; // Distance threshold for haptic feedback
private const sbyte hapticStrength = 5; // Haptic feedback intensity
private const double hapticTriggerDelta = 30; // Distance threshold for haptic feedback on each pad
// Functional constants (derived once)
private readonly double gestureRadiusSq = gestureRadius * gestureRadius;
private readonly double minGlideMagnitudeSq = minGlideMagnitude * minGlideMagnitude;
private readonly double minGlideVelocitySq = minGlideVelocity * minGlideVelocity;
// Runtime state
// Runtime state RPad
private Queue<double> bufX = new(), bufY = new();
private double totalDeltaX = 0, totalDeltaY = 0;
private bool gestureCommitted = false;
@ -31,13 +30,13 @@ namespace SteamController.Devices
private Queue<double> velocityHistoryX = new(), velocityHistoryY = new();
private double velocitySumX = 0, velocitySumY = 0;
private double hapticDelta = 0;
// Runtime state haptics
private double hapticDeltaR = 0;
private double hapticDeltaL = 0;
// Main movement logic
public void MoveByFauxLizard(double dx, double dy, Context c)
public void MoveByFauxLizard(double dx, double dy, bool isTouched)
{
bool isTouched = c.Steam.BtnRPadTouch?.LastValue ?? false;
if (!isTouched)
{
// Start glide if gesture was committed and velocity is high enough
@ -72,7 +71,7 @@ namespace SteamController.Devices
// Reset gesture state
gestureCommitted = false;
totalDeltaX = totalDeltaY = hapticDelta = 0;
totalDeltaX = totalDeltaY = 0;
return;
}
@ -130,19 +129,54 @@ namespace SteamController.Devices
double finalX = flushedX + rampedX;
double finalY = flushedY + rampedY;
// Haptic trigger
double finalMagSq = finalX * finalX + finalY * finalY;
hapticDelta += Math.Sqrt(finalMagSq); // Only one sqrt per frame
if (hapticDelta >= hapticTriggerDelta)
{
c.Steam.SendHaptic(HapticPad.Right, HapticStyle.Weak, hapticStrength);
hapticDelta -= hapticTriggerDelta;
}
MoveBy(finalX, finalY);
}
// Checks whether the pads have been dragged enough to trigger a haptic feedback
public bool HapticDragRFauxLizard(double dx, double dy, bool isTouched)
{
if (isTouched)
{
double finalMagSq = dx * dx + dy * dy;
if (hapticDeltaR < hapticTriggerDelta)
hapticDeltaR += Math.Sqrt(finalMagSq);
if (hapticDeltaR >= hapticTriggerDelta)
{
hapticDeltaR -= hapticTriggerDelta;
return true;
}
}
else
hapticDeltaR = 0;
return false;
}
public bool HapticDragLFauxLizard(double dx, double dy, bool isTouched)
{
if (isTouched)
{
double finalMagSq = dx * dx + dy * dy;
if (hapticDeltaL < hapticTriggerDelta)
hapticDeltaL += Math.Sqrt(finalMagSq);
if (hapticDeltaL >= hapticTriggerDelta)
{
hapticDeltaL -= hapticTriggerDelta;
return true;
}
}
else
hapticDeltaL = 0;
return false;
}
// Input smoothing
private double SmoothDelta(double raw, Queue<double> buffer)
{

View file

@ -2,6 +2,7 @@ using System.Diagnostics;
using ExternalHelpers;
using PowerControl.Helpers;
using WindowsInput;
using static SteamController.Devices.SteamController;
namespace SteamController.Profiles.Default
{
@ -140,6 +141,31 @@ namespace SteamController.Profiles.Default
)
);
}
if (!c.Steam.LizardButtons && !c.Steam.LizardMouse)
{
// Send haptic for pad presses
if (c.Steam.BtnLPadPress.Pressed() || c.Steam.BtnLPadPress.JustPressed())
{
c.Steam.SendHaptic(HapticPad.Left, HapticStyle.Strong, 8);
}
// Send haptic for pad drag
if (c.Mouse.HapticDragLFauxLizard(
c.Steam.LPadX.GetDeltaValue(
150,
Devices.DeltaValueMode.Delta,
10
),
c.Steam.LPadY.GetDeltaValue(
150,
Devices.DeltaValueMode.Delta,
10
),
c.Steam.BtnLPadTouch?.LastValue ?? false
))
c.Steam.SendHaptic(HapticPad.Left, HapticStyle.Weak, 5);
}
}
protected void EmulateMouseOnRStick(Context c)
@ -177,8 +203,33 @@ namespace SteamController.Profiles.Default
c.Mouse.MoveByFauxLizard(
c.Steam.RPadX.GetDeltaValue(Context.PadToMouseSensitivity, Devices.DeltaValueMode.Delta, 10),
-c.Steam.RPadY.GetDeltaValue(Context.PadToMouseSensitivity, Devices.DeltaValueMode.Delta, 10),
c
c.Steam.BtnRPadTouch?.LastValue ?? false
);
if (!c.Steam.LizardButtons && !c.Steam.LizardMouse)
{
// Send haptic for pad presses
if (c.Steam.BtnRPadPress.Pressed() || c.Steam.BtnRPadPress.JustPressed())
{
c.Steam.SendHaptic(HapticPad.Right, HapticStyle.Strong, 8);
}
// Send haptic for pad drag
if (c.Mouse.HapticDragRFauxLizard(
c.Steam.RPadX.GetDeltaValue(
150,
Devices.DeltaValueMode.Delta,
10
),
c.Steam.RPadY.GetDeltaValue(
150,
Devices.DeltaValueMode.Delta,
10
),
c.Steam.BtnRPadTouch?.LastValue ?? false
))
c.Steam.SendHaptic(HapticPad.Right, HapticStyle.Weak, 5);
}
}
}
}