From c536393054bde52336eeb9d4ea76bdf85cac6466 Mon Sep 17 00:00:00 2001 From: General4878 Date: Sat, 13 Sep 2025 18:05:23 +0200 Subject: [PATCH] FLM: Removed built in haptic on drag from MoveByFauxLizard into its own method and added haptic feedback for LPad drag --- .../Devices/MouseControllerFauxLizard.cs | 70 ++++++++++++++----- .../Profiles/Default/GuideShortcutsProfile.cs | 64 ++++++++++++----- 2 files changed, 100 insertions(+), 34 deletions(-) diff --git a/SteamController/Devices/MouseControllerFauxLizard.cs b/SteamController/Devices/MouseControllerFauxLizard.cs index 8a6b99b..8c997a6 100644 --- a/SteamController/Devices/MouseControllerFauxLizard.cs +++ b/SteamController/Devices/MouseControllerFauxLizard.cs @@ -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 bufX = new(), bufY = new(); private double totalDeltaX = 0, totalDeltaY = 0; private bool gestureCommitted = false; @@ -31,13 +30,13 @@ namespace SteamController.Devices private Queue 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; 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 buffer) { diff --git a/SteamController/Profiles/Default/GuideShortcutsProfile.cs b/SteamController/Profiles/Default/GuideShortcutsProfile.cs index c45106f..72fb822 100644 --- a/SteamController/Profiles/Default/GuideShortcutsProfile.cs +++ b/SteamController/Profiles/Default/GuideShortcutsProfile.cs @@ -121,15 +121,6 @@ namespace SteamController.Profiles.Default protected void EmulateScrollOnLPad(Context c) { - //Send haptic for pad presses - if (!c.Steam.LizardButtons && !c.Steam.LizardMouse) - { - if (c.Steam.BtnLPadPress.Pressed() || c.Steam.BtnLPadPress.JustPressed()) - { - c.Steam.SendHaptic(HapticPad.Left, HapticStyle.Strong, 8); - } - } - if (c.Steam.LPadX) { c.Mouse.HorizontalScroll( @@ -150,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) @@ -184,20 +200,36 @@ namespace SteamController.Profiles.Default c.Mouse[Devices.MouseController.Button.Left] = c.Steam.BtnRPadPress; } - //Send haptic for pad presses + c.Mouse.MoveByFauxLizard( + c.Steam.RPadX.GetDeltaValue(Context.PadToMouseSensitivity, Devices.DeltaValueMode.Delta, 10), + -c.Steam.RPadY.GetDeltaValue(Context.PadToMouseSensitivity, Devices.DeltaValueMode.Delta, 10), + 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); } - } - c.Mouse.MoveByFauxLizard( - c.Steam.RPadX.GetDeltaValue(Context.PadToMouseSensitivity, Devices.DeltaValueMode.Delta, 10), - -c.Steam.RPadY.GetDeltaValue(Context.PadToMouseSensitivity, Devices.DeltaValueMode.Delta, 10), - c - ); + // 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); + } } } }