From 8d92d57fb1949d288b12d940267629b43beb25f4 Mon Sep 17 00:00:00 2001 From: kamih Date: Sat, 25 Jan 2025 12:30:28 -0700 Subject: [PATCH 01/18] added first test of new HUD that sends trigger effects to dualsense controller via simple dll instead of dsx --- .../DualSense/DualSenseConfiguration.cs | 86 +++++++++++++++++++ .../Driving/DualSense/DualSenseJob.cs | 19 ++++ .../Driving/DualSense/DualSenseOverlay.cs | 49 +++++++++++ .../Overlays/Driving/DualSense/Resources.cs | 27 ++++++ .../Driving/DualSense/TriggerHaptics.cs | 77 +++++++++++++++++ 5 files changed, 258 insertions(+) create mode 100644 Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs create mode 100644 Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs create mode 100644 Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs create mode 100644 Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs create mode 100644 Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs new file mode 100644 index 000000000..1f13af5ed --- /dev/null +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs @@ -0,0 +1,86 @@ +using RaceElement.HUD.Overlay.Configuration; + +namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; + +internal sealed class DualSenseConfiguration : OverlayConfiguration +{ + public DualSenseConfiguration() + { + GenericConfiguration.AlwaysOnTop = false; + GenericConfiguration.Window = false; + GenericConfiguration.Opacity = 1.0f; + GenericConfiguration.AllowRescale = false; + } + + + [ConfigGrouping("Brake Slip", "Adjust the slip effect whilst applying the brakes.")] + public BrakeSlipHaptics BrakeSlip { get; init; } = new(); + public sealed class BrakeSlipHaptics + { + /// + /// The brake in percentage (divide by 100f if you want 0-1 value) + /// + [ToolTip("The minimum brake percentage before any effects are applied. See this like a deadzone.")] + [FloatRange(0.1f, 99f, 0.1f, 1)] + public float BrakeThreshold { get; init; } = 3f; + + [FloatRange(0.05f, 6f, 0.002f, 3)] + public float FrontSlipThreshold { get; init; } = 0.25f; + + [FloatRange(0.05f, 6f, 0.002f, 3)] + public float RearSlipThreshold { get; init; } = 0.25f; + + [ToolTip("Higher is stronger dynamic feedback.")] + [IntRange(5, 8, 1)] + public int FeedbackStrength { get; init; } = 7; + + [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] + [IntRange(1, 10, 1)] + public int MinFrequency { get; init; } = 10; + + [ToolTip("Sets the max frequency of the vibration effect in the trigger.")] + [IntRange(20, 150, 1)] + public int MaxFrequency { get; init; } = 100; + + [ToolTip("Change the amplitude(strength) of the vibration effect in the trigger.")] + [IntRange(1, 8, 1)] + public int Amplitude { get; init; } = 1; + } + + [ConfigGrouping("Throttle Slip", "Adjust the slip effect whilst applying the throttle.\nModify the threshold to increase or decrease sensitivity in different situations.")] + public ThrottleSlipHaptics ThrottleSlip { get; init; } = new(); + public sealed class ThrottleSlipHaptics + { + /// + /// The throttle in percentage (divide by 100f if you want 0-1 value) + /// + [ToolTip("The minimum throttle percentage before any effects are applied. See this like a deadzone.")] + [FloatRange(0.1f, 99f, 0.1f, 1)] + public float ThrottleThreshold { get; init; } = 3f; + + [ToolTip("Decrease this treshold to increase the sensitivity when the front wheels slip (understeer).")] + [FloatRange(0.05f, 6f, 0.002f, 3)] + public float FrontSlipThreshold { get; init; } = 0.35f; + + [ToolTip("Decrease this treshold to increase the sensitivity when the rear wheels slip (oversteer).")] + [FloatRange(0.05f, 10f, 0.002f, 3)] + public float RearSlipThreshold { get; init; } = 0.25f; + + [ToolTip("Higher is stronger dynamic feedback.")] + [IntRange(5, 8, 1)] + public int FeedbackStrength { get; init; } = 8; + + [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] + [IntRange(1, 10, 1)] + public int MinFrequency { get; init; } = 10; + + [ToolTip("Sets the max frequency of the vibration effect in the trigger.")] + [IntRange(20, 150, 1)] + public int MaxFrequency { get; init; } = 100; + + [ToolTip("Change the amplitude(strength) of the vibration effect in the trigger.")] + [IntRange(1, 8, 1)] + public int Amplitude { get; init; } = 1; + } + +} diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs new file mode 100644 index 000000000..1240795af --- /dev/null +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs @@ -0,0 +1,19 @@ +using RaceElement.Core.Jobs.Loop; +using static RaceElement.HUD.Common.Overlays.Driving.DualSense.Resources; + +namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; + +internal sealed class DualSenseJob(DualSenseOverlay overlay) : AbstractLoopJob +{ + public sealed override void RunAction() + { + //if (!overlay.ShouldRender()) + // return; + + TriggerHaptics.HandleAcceleration(overlay._config); + TriggerHaptics.HandleBraking(overlay._config); + } + public override void AfterCancel() + { + } +} diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs new file mode 100644 index 000000000..4c806616c --- /dev/null +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs @@ -0,0 +1,49 @@ +using RaceElement.Data.Games; +using RaceElement.HUD.Overlay.Internal; +using System.Diagnostics; +using System.Drawing; +using System.Text; + +using static RaceElement.HUD.Common.Overlays.Driving.DualSense.Resources; + +namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; + +[Overlay(Name = "DualSense", + Description = "Adds trigger effects to the DualSense Controller.\n See Guide in the Discord of Race Element for instructions.", + OverlayCategory = OverlayCategory.Inputs, + OverlayType = OverlayType.Drive, + Game = Game.RaceRoom | Game.AssettoCorsa1 | Game.AssettoCorsaEvo, + Authors = ["Reinier Klarenberg", "Guillaume Stordeur"] +)] +internal sealed class DualSenseOverlay : CommonAbstractOverlay +{ + internal readonly DualSenseConfiguration _config = new(); + private DualSenseJob _DualSenseJob; + + public DualSenseOverlay(Rectangle rectangle) : base(rectangle, "DualSense") + { + Width = 1; Height = 1; + RefreshRateHz = 1; + AllowReposition = false; + } + + public sealed override void BeforeStart() + { + if (IsPreviewing) return; + ds5w_init(); + _DualSenseJob = new DualSenseJob(this) { IntervalMillis = 1000 / 200 }; + _DualSenseJob.Run(); + } + public sealed override void BeforeStop() + { + if (IsPreviewing) return; + + _DualSenseJob?.CancelJoin(); + ds5w_shutdown(); + } + + public sealed override bool ShouldRender() => DefaultShouldRender() && !IsPreviewing; + + public sealed override void Render(Graphics g) { } + +} diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs new file mode 100644 index 000000000..f56a188ae --- /dev/null +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs @@ -0,0 +1,27 @@ +using System.Net; +using System.Runtime.InteropServices; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; + +internal static class Resources +{ + /* + DS5W_CAPI int ds5w_init(void); + DS5W_CAPI void ds5w_shutdown(void); + DS5W_CAPI int ds5w_set_trigger_effect_off(int left); + DS5W_CAPI int ds5w_set_trigger_effect_vibration(int left, int pos, int amp, int freq); + */ + [DllImport("ds5w_x64.dll", SetLastError = true)] + public static extern int ds5w_init(); + + [DllImport("ds5w_x64.dll", SetLastError = true)] + public static extern void ds5w_shutdown(); + + [DllImport("ds5w_x64.dll", SetLastError = true)] + public static extern int ds5w_set_trigger_effect_off(int left); + + [DllImport("ds5w_x64.dll", SetLastError = true)] + public static extern int ds5w_set_trigger_effect_vibration(int left, int pos, int amp, int freq); +} diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs new file mode 100644 index 000000000..b1200d03e --- /dev/null +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -0,0 +1,77 @@ +using RaceElement.Data.Common; +using RaceElement.Util.SystemExtensions; +using static RaceElement.HUD.Common.Overlays.Driving.DualSense.Resources; + +namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; + +internal static class TriggerHaptics +{ + public static void HandleBraking(DualSenseConfiguration config) + { + // TODO: add either an option to threshold it on brake input or based on some curve? + if (SimDataProvider.LocalCar.Inputs.Brake <= config.BrakeSlip.BrakeThreshold / 100f) + return; + float[] slipRatios = SimDataProvider.LocalCar.Tyres.SlipRatio; + if (slipRatios.Length != 4) + return; + + float slipRatioFront = Math.Max(slipRatios[0], slipRatios[1]); + float slipRatioRear = Math.Max(slipRatios[2], slipRatios[3]); + + // TODO: add option for front and rear ratio threshold. + if (slipRatioFront > config.BrakeSlip.FrontSlipThreshold || slipRatioRear > config.BrakeSlip.RearSlipThreshold) + { + float frontslipCoefecient = slipRatioFront * 4f; + frontslipCoefecient.ClipMax(10); + + float rearSlipCoefecient = slipRatioFront * 2f; + rearSlipCoefecient.ClipMax(7.5f); + + float magicValue = frontslipCoefecient + rearSlipCoefecient; + float percentage = magicValue * 1.0f / 17.5f; + //if (percentage >= 0.05f) + // p.AddAdaptiveTriggerToPacket(controllerIndex, Trigger.Left, TriggerMode.FEEDBACK, [1, (int)(config.BrakeSlip.FeedbackStrength * percentage)]); + + int freq = (int)(config.BrakeSlip.MaxFrequency * percentage); + freq.ClipMin(config.BrakeSlip.MinFrequency); + ds5w_set_trigger_effect_vibration(1, 0, config.BrakeSlip.Amplitude, freq); + } + else + { + ds5w_set_trigger_effect_off(1); + } + } + + public static void HandleAcceleration(DualSenseConfiguration config) + { + if (SimDataProvider.LocalCar.Inputs.Throttle <= config.ThrottleSlip.ThrottleThreshold / 100f) + return; + float[] slipRatios = SimDataProvider.LocalCar.Tyres.SlipRatio; + if (slipRatios.Length != 4) + return; + + float slipRatioFront = Math.Max(slipRatios[0], slipRatios[1]); + float slipRatioRear = Math.Max(slipRatios[2], slipRatios[3]); + + if (slipRatioFront > config.ThrottleSlip.FrontSlipThreshold || slipRatioRear > config.ThrottleSlip.RearSlipThreshold) + { + float frontslipCoefecient = slipRatioFront * 3f; + frontslipCoefecient.ClipMax(5); + float rearSlipCoefecient = slipRatioFront * 5f; + rearSlipCoefecient.ClipMax(7.5f); + + float magicValue = frontslipCoefecient + rearSlipCoefecient; + float percentage = magicValue * 1.0f / 12.5f; + //if (percentage >= 0.05f) + // p.AddAdaptiveTriggerToPacket(controllerIndex, Trigger.Right, TriggerMode.FEEDBACK, [1, (int)(config.ThrottleSlip.FeedbackStrength * percentage)]); + + int freq = (int)(config.ThrottleSlip.MaxFrequency * percentage); + freq.ClipMin(config.ThrottleSlip.MinFrequency); + ds5w_set_trigger_effect_vibration(0, 0, config.ThrottleSlip.Amplitude, freq); + } + else + { + ds5w_set_trigger_effect_off(0); + } + } +} From 7f69c46f849fbf1722dc99dccda4ea53a2acf515 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sat, 25 Jan 2025 22:19:19 +0100 Subject: [PATCH 02/18] embed ds5w_x64.dll - will require version checking to auto-update the extracted file - auto extracts the embedded dll at first usage --- .../Driving/DualSense/DualSenseOverlay.cs | 29 ++++++++++++++++++ .../Overlays/Driving/DualSense/Resources.cs | 23 ++++++-------- .../Overlays/Driving/DualSense/ds5w_x64.dll | Bin 0 -> 19968 bytes .../Race Element.HUD.Common.csproj | 9 ++++-- 4 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 Race Element.HUD.Common/Overlays/Driving/DualSense/ds5w_x64.dll diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs index 4c806616c..df3f5e486 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs @@ -2,6 +2,7 @@ using RaceElement.HUD.Overlay.Internal; using System.Diagnostics; using System.Drawing; +using System.Reflection; using System.Text; using static RaceElement.HUD.Common.Overlays.Driving.DualSense.Resources; @@ -30,6 +31,9 @@ public DualSenseOverlay(Rectangle rectangle) : base(rectangle, "DualSense") public sealed override void BeforeStart() { if (IsPreviewing) return; + + ExtractDs5ApiDll(); + ds5w_init(); _DualSenseJob = new DualSenseJob(this) { IntervalMillis = 1000 / 200 }; _DualSenseJob.Run(); @@ -42,6 +46,31 @@ public sealed override void BeforeStop() ds5w_shutdown(); } + /// + /// Extracts the embbed dll in this namespace folder, to the executing assembly folder. + /// only extracts if it does not exists. Does not check for version!!! + /// + private static void ExtractDs5ApiDll() + { + string dllPath = Path.Combine(AppContext.BaseDirectory, Path.GetFileName("ds5w_x64.dll")); + FileInfo dllFile = new FileInfo(dllPath); + if (dllFile.Exists) return; + + string resourceName = "RaceElement.HUD.Common.Overlays.Driving.DualSense.ds5w_x64.dll"; + var assembly = Assembly.GetExecutingAssembly(); + using (var stream = assembly.GetManifestResourceStream(resourceName)) + { + if (stream == null) + throw new FileNotFoundException($"Could not find resource: {resourceName}"); + + dllFile.Create(); + using (var fileStream = dllFile.Open(FileMode.Create, FileAccess.Write)) + { + stream.CopyTo(fileStream); + } + } + } + public sealed override bool ShouldRender() => DefaultShouldRender() && !IsPreviewing; public sealed override void Render(Graphics g) { } diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs index f56a188ae..7cc8ef70b 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs @@ -1,11 +1,8 @@ -using System.Net; -using System.Runtime.InteropServices; -using System.Text.Json; -using System.Text.Json.Serialization; +using System.Runtime.InteropServices; namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; -internal static class Resources +internal static partial class Resources { /* DS5W_CAPI int ds5w_init(void); @@ -13,15 +10,15 @@ internal static class Resources DS5W_CAPI int ds5w_set_trigger_effect_off(int left); DS5W_CAPI int ds5w_set_trigger_effect_vibration(int left, int pos, int amp, int freq); */ - [DllImport("ds5w_x64.dll", SetLastError = true)] - public static extern int ds5w_init(); + [LibraryImport("ds5w_x64.dll", SetLastError = true)] + public static partial int ds5w_init(); - [DllImport("ds5w_x64.dll", SetLastError = true)] - public static extern void ds5w_shutdown(); + [LibraryImport("ds5w_x64.dll", SetLastError = true)] + public static partial void ds5w_shutdown(); - [DllImport("ds5w_x64.dll", SetLastError = true)] - public static extern int ds5w_set_trigger_effect_off(int left); + [LibraryImport("ds5w_x64.dll", SetLastError = true)] + public static partial int ds5w_set_trigger_effect_off(int left); - [DllImport("ds5w_x64.dll", SetLastError = true)] - public static extern int ds5w_set_trigger_effect_vibration(int left, int pos, int amp, int freq); + [LibraryImport("ds5w_x64.dll", SetLastError = true)] + public static partial int ds5w_set_trigger_effect_vibration(int left, int pos, int amp, int freq); } diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/ds5w_x64.dll b/Race Element.HUD.Common/Overlays/Driving/DualSense/ds5w_x64.dll new file mode 100644 index 0000000000000000000000000000000000000000..fb56309a0d2ebb059fec63be5eb2e907cf85c96c GIT binary patch literal 19968 zcmeHv3wTpiw*O9>wCRf!Xs{}1z!a+3TAG68(IJPXaEhrE+5+-QOPiKpo7OxiFfax~ zrQsN5#>X(%(Lo)R86Sg!P(U%INLxfH1?8nu8Ak*4jujaMN6G!Ib52Tuaqj<{@6P}K z|L)A;+h?u4_F8MNz4qGAoKi4n9gAd)DUm`U#+m@>F^ccM|4LLa*6-#W{n(b6_l7np z%KwIIj(VW>>Ktyn&Suw{rWNUGYAdYi2??=!S@pg@EFSRi z`${gH)@=PH*NFUYc$M)X5k?!=ijWx}6rsZC1$<|#%IE`p_uQWa) z!oP9^AAbK)5ytXSB7KIfd=b_4V=XJpW31xADE88ek5z?vde|^sTtvUy*f3CLNYuJp z024*r12;%`1Y=Pm=`v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&$WP;B;QHT1SttPK`T-! z@V@79I=dgl{hSGOf(jk<0Vg<6#tGhnrZ?khlV1LTL{ zd(}y*;rZ83w{C2>jNFLw>|B6I)rQ&`x z7m08a;7S?y0B(_Sg6%TCAMl)v6O0)l$;Ja#BW;0xg1?sO1UJbz!80=cC15?y>16X# zz(kza9|BG=3yJ6i=gW8tt#=ivv24dO*kTqT(IN1>kg7LU$f*@Hs)c?;xBY-B}P$knR`E;3r6b z%lb0u|Cf9s#QRzu!i(qlUk7Z%2J}4% z%g_4f5W9UAiE|NID4EHMm<8`V{P!zGET2tdcO##V_hjJoyrul=66p<#hT%l9l=jO? zc|DQ|0L7?R0evp!U^ZrFRnTT*)yxXbc2>!1!IL5KWZ;J@>0cIGNIzn+3Ahnbuw3xe zusT)-{$;SH3^}Va;Cz%9^aJu^}60M}*t43^GDArT~-O>6-8sckNi*Dh+m zY;^^sN5f_dTZ-QzvM|I5%Lbl~wp5F@&trq3!wmTgcunax`JiM;s#ZP)adF@lbX}pJSFK z1~y^h(wb`B605_BO?A$QQRx{YbXI$LZ3PYjIU`DnC#PkP&^cW=FqKu~5Ro%tnbkRB z;!hG{C*ZVctyx&TOa}#aXU+&*kBxJdFS6E@;dd=txue!uTj@$GudNwZ=B!CyGHQel zn`c`k&Q~-0)&^BN-2|7z?R3$VldNsnf1}MXOq7G969*ie2$#uuP#o6#+^EG`QRuKO z!7jVX>g+A-Tbw7JjnHhfb&0iFS55Dn5oOMN`;yvwt&R~ow~Z^OBSX%J%Cc&wb%gGY zUOf};`0-jM+;N3X6Yl739KTrue True + + + + + + @@ -36,7 +42,6 @@ - + - From 1615691f7e5b5b83b5ce6467f2fa2ba965d71a54 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sat, 25 Jan 2025 22:22:42 +0100 Subject: [PATCH 03/18] Update DualSenseJob.cs disable effects after cancelling the dualsense job --- .../Overlays/Driving/DualSense/DualSenseJob.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs index 1240795af..1a016b10b 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs @@ -15,5 +15,7 @@ public sealed override void RunAction() } public override void AfterCancel() { + ds5w_set_trigger_effect_off(0); + ds5w_set_trigger_effect_off(1); } } From 09c796c23886f90af9cf648449031c6d77b9bbf6 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sat, 25 Jan 2025 23:24:33 +0100 Subject: [PATCH 04/18] Update DualSenseOverlay.cs fix creation of file --- .../Overlays/Driving/DualSense/DualSenseOverlay.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs index df3f5e486..a810f0a75 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs @@ -53,7 +53,7 @@ public sealed override void BeforeStop() private static void ExtractDs5ApiDll() { string dllPath = Path.Combine(AppContext.BaseDirectory, Path.GetFileName("ds5w_x64.dll")); - FileInfo dllFile = new FileInfo(dllPath); + FileInfo dllFile = new(dllPath); if (dllFile.Exists) return; string resourceName = "RaceElement.HUD.Common.Overlays.Driving.DualSense.ds5w_x64.dll"; @@ -63,11 +63,10 @@ private static void ExtractDs5ApiDll() if (stream == null) throw new FileNotFoundException($"Could not find resource: {resourceName}"); - dllFile.Create(); - using (var fileStream = dllFile.Open(FileMode.Create, FileAccess.Write)) - { - stream.CopyTo(fileStream); - } + using var fileStream = dllFile.Open(FileMode.Create, FileAccess.Write); + stream.CopyTo(fileStream); + stream.Close(); + fileStream.Close(); } } From ad4f4c81deaeb1fa27fb694a698eb2124a0c5727 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sat, 25 Jan 2025 23:38:13 +0100 Subject: [PATCH 05/18] Update TriggerHaptics.cs disable effects at all times (can be improved in the future to remember this state) --- .../Overlays/Driving/DualSense/TriggerHaptics.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs index b1200d03e..692a439c4 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -10,10 +10,16 @@ public static void HandleBraking(DualSenseConfiguration config) { // TODO: add either an option to threshold it on brake input or based on some curve? if (SimDataProvider.LocalCar.Inputs.Brake <= config.BrakeSlip.BrakeThreshold / 100f) + { + ds5w_set_trigger_effect_off(1); return; + } float[] slipRatios = SimDataProvider.LocalCar.Tyres.SlipRatio; if (slipRatios.Length != 4) + { + ds5w_set_trigger_effect_off(1); return; + } float slipRatioFront = Math.Max(slipRatios[0], slipRatios[1]); float slipRatioRear = Math.Max(slipRatios[2], slipRatios[3]); @@ -45,10 +51,16 @@ public static void HandleBraking(DualSenseConfiguration config) public static void HandleAcceleration(DualSenseConfiguration config) { if (SimDataProvider.LocalCar.Inputs.Throttle <= config.ThrottleSlip.ThrottleThreshold / 100f) + { + ds5w_set_trigger_effect_off(0); return; + } float[] slipRatios = SimDataProvider.LocalCar.Tyres.SlipRatio; if (slipRatios.Length != 4) + { + ds5w_set_trigger_effect_off(0); return; + } float slipRatioFront = Math.Max(slipRatios[0], slipRatios[1]); float slipRatioRear = Math.Max(slipRatios[2], slipRatios[3]); From 3615968f738e2d9e5d699c2855de68cb88034c14 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sat, 25 Jan 2025 23:40:45 +0100 Subject: [PATCH 06/18] Update DualSenseConfiguration.cs update default settings, feels better after the previous commit, you can turn down amplitude ofc! --- .../Overlays/Driving/DualSense/DualSenseConfiguration.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs index 1f13af5ed..43edd1974 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs @@ -36,7 +36,7 @@ public sealed class BrakeSlipHaptics [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] [IntRange(1, 10, 1)] - public int MinFrequency { get; init; } = 10; + public int MinFrequency { get; init; } = 3; [ToolTip("Sets the max frequency of the vibration effect in the trigger.")] [IntRange(20, 150, 1)] @@ -44,7 +44,7 @@ public sealed class BrakeSlipHaptics [ToolTip("Change the amplitude(strength) of the vibration effect in the trigger.")] [IntRange(1, 8, 1)] - public int Amplitude { get; init; } = 1; + public int Amplitude { get; init; } = 8; } [ConfigGrouping("Throttle Slip", "Adjust the slip effect whilst applying the throttle.\nModify the threshold to increase or decrease sensitivity in different situations.")] @@ -72,7 +72,7 @@ public sealed class ThrottleSlipHaptics [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] [IntRange(1, 10, 1)] - public int MinFrequency { get; init; } = 10; + public int MinFrequency { get; init; } = 6; [ToolTip("Sets the max frequency of the vibration effect in the trigger.")] [IntRange(20, 150, 1)] @@ -80,7 +80,7 @@ public sealed class ThrottleSlipHaptics [ToolTip("Change the amplitude(strength) of the vibration effect in the trigger.")] [IntRange(1, 8, 1)] - public int Amplitude { get; init; } = 1; + public int Amplitude { get; init; } = 7; } } From 7231cafe61bc58616cc83a784aaa4bf5439c83d9 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sat, 25 Jan 2025 23:49:29 +0100 Subject: [PATCH 07/18] Update TriggerHaptics.cs add feedback as 0 frequency --- .../Overlays/Driving/DualSense/TriggerHaptics.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs index 692a439c4..0ad5c10ed 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -35,8 +35,8 @@ public static void HandleBraking(DualSenseConfiguration config) float magicValue = frontslipCoefecient + rearSlipCoefecient; float percentage = magicValue * 1.0f / 17.5f; - //if (percentage >= 0.05f) - // p.AddAdaptiveTriggerToPacket(controllerIndex, Trigger.Left, TriggerMode.FEEDBACK, [1, (int)(config.BrakeSlip.FeedbackStrength * percentage)]); + if (percentage >= 0.05f) + ds5w_set_trigger_effect_vibration(1, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage), 0); int freq = (int)(config.BrakeSlip.MaxFrequency * percentage); freq.ClipMin(config.BrakeSlip.MinFrequency); @@ -74,8 +74,8 @@ public static void HandleAcceleration(DualSenseConfiguration config) float magicValue = frontslipCoefecient + rearSlipCoefecient; float percentage = magicValue * 1.0f / 12.5f; - //if (percentage >= 0.05f) - // p.AddAdaptiveTriggerToPacket(controllerIndex, Trigger.Right, TriggerMode.FEEDBACK, [1, (int)(config.ThrottleSlip.FeedbackStrength * percentage)]); + if (percentage >= 0.05f) + ds5w_set_trigger_effect_vibration(0, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage), 0); int freq = (int)(config.ThrottleSlip.MaxFrequency * percentage); freq.ClipMin(config.ThrottleSlip.MinFrequency); From 23b6b8f45321747e55b7ba7063e1df3d2fb7a471 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sat, 25 Jan 2025 23:57:19 +0100 Subject: [PATCH 08/18] Update TriggerHaptics.cs - fix ffb str to brake setting instead of throttle for brake slip feedback --- .../Overlays/Driving/DualSense/TriggerHaptics.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs index 0ad5c10ed..99a505b11 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -35,8 +35,9 @@ public static void HandleBraking(DualSenseConfiguration config) float magicValue = frontslipCoefecient + rearSlipCoefecient; float percentage = magicValue * 1.0f / 17.5f; + if (percentage >= 0.05f) - ds5w_set_trigger_effect_vibration(1, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage), 0); + ds5w_set_trigger_effect_vibration(1, 0, (int)(config.BrakeSlip.FeedbackStrength * percentage), 0); int freq = (int)(config.BrakeSlip.MaxFrequency * percentage); freq.ClipMin(config.BrakeSlip.MinFrequency); From d7ad4add6fc30d1bebe8ad00e27ae996e3fdb3be Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sun, 26 Jan 2025 00:10:31 +0100 Subject: [PATCH 09/18] revert tripperhaptics to vibration only --- .../Overlays/Driving/DualSense/TriggerHaptics.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs index 99a505b11..12eb22e9b 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -36,8 +36,8 @@ public static void HandleBraking(DualSenseConfiguration config) float magicValue = frontslipCoefecient + rearSlipCoefecient; float percentage = magicValue * 1.0f / 17.5f; - if (percentage >= 0.05f) - ds5w_set_trigger_effect_vibration(1, 0, (int)(config.BrakeSlip.FeedbackStrength * percentage), 0); + //if (percentage >= 0.05f) + // ds5w_set_trigger_effect_vibration(1, 0, (int)(config.BrakeSlip.FeedbackStrength * percentage), 90); int freq = (int)(config.BrakeSlip.MaxFrequency * percentage); freq.ClipMin(config.BrakeSlip.MinFrequency); @@ -75,8 +75,8 @@ public static void HandleAcceleration(DualSenseConfiguration config) float magicValue = frontslipCoefecient + rearSlipCoefecient; float percentage = magicValue * 1.0f / 12.5f; - if (percentage >= 0.05f) - ds5w_set_trigger_effect_vibration(0, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage), 0); + //if (percentage >= 0.05f) + // ds5w_set_trigger_effect_vibration(0, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage), 0); int freq = (int)(config.ThrottleSlip.MaxFrequency * percentage); freq.ClipMin(config.ThrottleSlip.MinFrequency); From 135b34da6eb16d5798595f953e6dbfb5d35b58ae Mon Sep 17 00:00:00 2001 From: kamih Date: Sat, 25 Jan 2025 16:28:49 -0700 Subject: [PATCH 10/18] added ds5w_set_trigger_effect_feedback and ds5w_set_trigger_effect_weapon to DualSense API Resources --- .../Overlays/Driving/DualSense/Resources.cs | 12 ++++++------ .../Overlays/Driving/DualSense/ds5w_x64.dll | Bin 19968 -> 19968 bytes 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs index 7cc8ef70b..bb8a16a15 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/Resources.cs @@ -4,12 +4,6 @@ namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; internal static partial class Resources { - /* - DS5W_CAPI int ds5w_init(void); - DS5W_CAPI void ds5w_shutdown(void); - DS5W_CAPI int ds5w_set_trigger_effect_off(int left); - DS5W_CAPI int ds5w_set_trigger_effect_vibration(int left, int pos, int amp, int freq); - */ [LibraryImport("ds5w_x64.dll", SetLastError = true)] public static partial int ds5w_init(); @@ -21,4 +15,10 @@ internal static partial class Resources [LibraryImport("ds5w_x64.dll", SetLastError = true)] public static partial int ds5w_set_trigger_effect_vibration(int left, int pos, int amp, int freq); + + [LibraryImport("ds5w_x64.dll", SetLastError = true)] + public static partial int ds5w_set_trigger_effect_feedback(int left, int pos, int strength); + + [LibraryImport("ds5w_x64.dll", SetLastError = true)] + public static partial int ds5w_set_trigger_effect_weapon(int left, int start, int end, int strength); } diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/ds5w_x64.dll b/Race Element.HUD.Common/Overlays/Driving/DualSense/ds5w_x64.dll index fb56309a0d2ebb059fec63be5eb2e907cf85c96c..a6e93968e85f47519d796ea711d552ad8db81a0a 100644 GIT binary patch delta 5382 zcmeHLdwf&n8U9Y%(}tEby`>k@v}v2rR-sf_7l9!ZIvokoHM1`76AcufC{s0q6NHEnNsTX?0L^QQDEEO`)B9(d(ZQ{ zm+$>9=lkAs65kfVw?$~n5Td@jV-q(E7NLz#5EjH_L^D=c$A2sQLTKcT$+0#)C1xjQwGE155%p$7U{`E6cLl zzwy30aP@7jC*#rMbFpVIZcEPorN_ZXzm^(HAa zEusGfzC>SAdEh$6`tOdy`rKnHVV+4+$h4*wSwe;#ZE)X55mZrVmh#9a#!>2 z4(tN9Q;!?c{{p@SW92T)Vjj_eSWPKH;`IcoW8zHaW!+3XS&KpJ-RrBE4By2GU6G8V zDUAy)t3xIu@qjo~qofp}Rl(6xBcQtzFygVhTbw#~ixhS88;nSK2)>Gs;JPrsmoe8X z+K~6bOC5AphYWut9uPMJFy^fQbkM1G&sl8cqBRX;H&V$bzuj{ADO^XI3p97 zK|CN%Gy~B=CE%wS*r9bZJ1>q))Af(xSH=|!9lR;7HhR$*Y+pRVaGeN>D@xUCw`2unSU2wm~n12V?C8lE5;**uC1>M?sElY*|eCK4<9d-^E-zx z6w>(N;a3Qc@-#z{?wgU^Wylid@|z8fwsi$cqr$4-e%U09WDF;wP6|#hltP<)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VRcu!=;AQN>`~Z7O#bYXVsCaE& zz#pUPlhpi@in9agVoOxR3u<6quz`yBCQz>Vs=ivqO4U9=#S|3-(Tvrp9iFRVv5HTs zn53X97|z&swIh$KxKG8J+Y+Bu?O&)E%&5J1P_>~> zA%-s+`=aIiFcj!%j4B@63I3~&c|)9Hr7YW3Acw_30>jkmBjoDT31o9o<1(oKxqV|X@u#%Y{pKZ*?qiX z+_e9AT&Rf=SV^&kK>pgeRjv>23ABkpJCb7P^^o0!iKxAhy^z@9m;@3W^)wkYee|(J zLvO-@-h%fu0HJqu1Z~6cBj66m3dl>4(-8W(QV;2eBw-z`o5iA7GssJju33EF`1H0D z<4O zb_j9=uk9!WTVUHgB(5E{xI!5HLyRZp@i$6Ro-Pdie*q89-T$V5(<1wA0dKpn^p#MY zuT^i_LN%^nO(EP8$Jk}m8^UKGq1fhxt&jw8!o%?adq42e1jh1Ur&awuWE}X=N<LN8=KIPH#M*cB@(nd_FiL-nT+TV*GL2=9ipgA>ky^nw#ERPD6Ijzb1ur!BS+ z+wBtg(3(W`DhFGSp$ZYsfh2$vE=$K5n+IiRS)!741SQ`AJE34gLU6)(l@n$|oUq$~ z_d{C1Yk+$pG!ul~nJB2R_W~u Date: Sun, 26 Jan 2025 00:38:27 +0100 Subject: [PATCH 11/18] Update TriggerHaptics.cs add feedback effect --- .../Overlays/Driving/DualSense/TriggerHaptics.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs index 12eb22e9b..4e5a51d1e 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -36,8 +36,11 @@ public static void HandleBraking(DualSenseConfiguration config) float magicValue = frontslipCoefecient + rearSlipCoefecient; float percentage = magicValue * 1.0f / 17.5f; - //if (percentage >= 0.05f) - // ds5w_set_trigger_effect_vibration(1, 0, (int)(config.BrakeSlip.FeedbackStrength * percentage), 90); + if (percentage >= 0.05f) + { + ds5w_set_trigger_effect_feedback(1, 0, (int)(config.BrakeSlip.FeedbackStrength * percentage)); + ds5w_set_trigger_effect_off(1); + } int freq = (int)(config.BrakeSlip.MaxFrequency * percentage); freq.ClipMin(config.BrakeSlip.MinFrequency); @@ -75,8 +78,11 @@ public static void HandleAcceleration(DualSenseConfiguration config) float magicValue = frontslipCoefecient + rearSlipCoefecient; float percentage = magicValue * 1.0f / 12.5f; - //if (percentage >= 0.05f) - // ds5w_set_trigger_effect_vibration(0, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage), 0); + if (percentage >= 0.05f) + { + ds5w_set_trigger_effect_feedback(0, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage)); + ds5w_set_trigger_effect_off(0); + } int freq = (int)(config.ThrottleSlip.MaxFrequency * percentage); freq.ClipMin(config.ThrottleSlip.MinFrequency); From 772c0e5b76a57d21a3b6221b6fee4e636362381b Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sun, 26 Jan 2025 00:51:12 +0100 Subject: [PATCH 12/18] Update TriggerHaptics.cs time trial --- .../Overlays/Driving/DualSense/TriggerHaptics.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs index 4e5a51d1e..4867e15b7 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -38,18 +38,20 @@ public static void HandleBraking(DualSenseConfiguration config) if (percentage >= 0.05f) { - ds5w_set_trigger_effect_feedback(1, 0, (int)(config.BrakeSlip.FeedbackStrength * percentage)); + float perc = (config.BrakeSlip.FeedbackStrength * percentage); + perc.ClipMin(config.BrakeSlip.FeedbackStrength); + ds5w_set_trigger_effect_feedback(1, 0, (int)perc); + Thread.Sleep((int)(1000f / 200)); ds5w_set_trigger_effect_off(1); } int freq = (int)(config.BrakeSlip.MaxFrequency * percentage); freq.ClipMin(config.BrakeSlip.MinFrequency); ds5w_set_trigger_effect_vibration(1, 0, config.BrakeSlip.Amplitude, freq); + Thread.Sleep((int)(1000f / 200 * 4)); } else - { ds5w_set_trigger_effect_off(1); - } } public static void HandleAcceleration(DualSenseConfiguration config) @@ -81,16 +83,16 @@ public static void HandleAcceleration(DualSenseConfiguration config) if (percentage >= 0.05f) { ds5w_set_trigger_effect_feedback(0, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage)); + Thread.Sleep((int)(1000f / 200)); ds5w_set_trigger_effect_off(0); } int freq = (int)(config.ThrottleSlip.MaxFrequency * percentage); freq.ClipMin(config.ThrottleSlip.MinFrequency); ds5w_set_trigger_effect_vibration(0, 0, config.ThrottleSlip.Amplitude, freq); + Thread.Sleep((int)(1000f / 200 * 4)); } else - { ds5w_set_trigger_effect_off(0); - } } } From fc48eeaeca6be139897a36a0acc1595e59734408 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sun, 26 Jan 2025 01:02:47 +0100 Subject: [PATCH 13/18] add seperate thread for throttle and brake ffb - added some sleeps to try out disabling the feedback effect and only enabling it shortly --- .../DualSense/DualSenseConfiguration.cs | 4 ++-- .../Driving/DualSense/DualSenseJob.cs | 21 ++++++++++++------- .../Driving/DualSense/DualSenseOverlay.cs | 13 ++++++++---- .../Driving/DualSense/TriggerHaptics.cs | 14 ++++++------- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs index 43edd1974..8a1ec60e3 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs @@ -31,7 +31,7 @@ public sealed class BrakeSlipHaptics public float RearSlipThreshold { get; init; } = 0.25f; [ToolTip("Higher is stronger dynamic feedback.")] - [IntRange(5, 8, 1)] + [IntRange(1, 8, 1)] public int FeedbackStrength { get; init; } = 7; [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] @@ -67,7 +67,7 @@ public sealed class ThrottleSlipHaptics public float RearSlipThreshold { get; init; } = 0.25f; [ToolTip("Higher is stronger dynamic feedback.")] - [IntRange(5, 8, 1)] + [IntRange(1, 8, 1)] public int FeedbackStrength { get; init; } = 8; [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs index 1a016b10b..d79789521 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs @@ -3,19 +3,26 @@ namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; -internal sealed class DualSenseJob(DualSenseOverlay overlay) : AbstractLoopJob +internal sealed class ThrottleJob(DualSenseOverlay overlay) : AbstractLoopJob { public sealed override void RunAction() { - //if (!overlay.ShouldRender()) - // return; + if (!overlay.ShouldRender()) + return; TriggerHaptics.HandleAcceleration(overlay._config); - TriggerHaptics.HandleBraking(overlay._config); } - public override void AfterCancel() + public override void AfterCancel() => ds5w_set_trigger_effect_off(0); +} + +internal sealed class BrakeJob(DualSenseOverlay overlay) : AbstractLoopJob +{ + public sealed override void RunAction() { - ds5w_set_trigger_effect_off(0); - ds5w_set_trigger_effect_off(1); + if (!overlay.ShouldRender()) + return; + + TriggerHaptics.HandleBraking(overlay._config); } + public override void AfterCancel() => ds5w_set_trigger_effect_off(1); } diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs index a810f0a75..7a1c5977b 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs @@ -19,7 +19,8 @@ namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; internal sealed class DualSenseOverlay : CommonAbstractOverlay { internal readonly DualSenseConfiguration _config = new(); - private DualSenseJob _DualSenseJob; + private ThrottleJob _throttleJob; + private BrakeJob _brakeJob; public DualSenseOverlay(Rectangle rectangle) : base(rectangle, "DualSense") { @@ -35,14 +36,18 @@ public sealed override void BeforeStart() ExtractDs5ApiDll(); ds5w_init(); - _DualSenseJob = new DualSenseJob(this) { IntervalMillis = 1000 / 200 }; - _DualSenseJob.Run(); + _throttleJob = new ThrottleJob(this) { IntervalMillis = 1000 / 200 }; + _brakeJob = new BrakeJob(this) { IntervalMillis = 1000 / 200 }; + _throttleJob.Run(); + _brakeJob.Run(); } public sealed override void BeforeStop() { if (IsPreviewing) return; - _DualSenseJob?.CancelJoin(); + _throttleJob?.CancelJoin(); + _brakeJob?.CancelJoin(); + ds5w_shutdown(); } diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs index 4867e15b7..640e7215a 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -28,27 +28,27 @@ public static void HandleBraking(DualSenseConfiguration config) if (slipRatioFront > config.BrakeSlip.FrontSlipThreshold || slipRatioRear > config.BrakeSlip.RearSlipThreshold) { float frontslipCoefecient = slipRatioFront * 4f; - frontslipCoefecient.ClipMax(10); + frontslipCoefecient.ClipMax(7.5f); float rearSlipCoefecient = slipRatioFront * 2f; - rearSlipCoefecient.ClipMax(7.5f); + rearSlipCoefecient.ClipMax(5f); float magicValue = frontslipCoefecient + rearSlipCoefecient; - float percentage = magicValue * 1.0f / 17.5f; + float percentage = magicValue * 1.0f / 12.5f; if (percentage >= 0.05f) { float perc = (config.BrakeSlip.FeedbackStrength * percentage); perc.ClipMin(config.BrakeSlip.FeedbackStrength); ds5w_set_trigger_effect_feedback(1, 0, (int)perc); - Thread.Sleep((int)(1000f / 200)); + Thread.Sleep((int)(1000f / 250)); ds5w_set_trigger_effect_off(1); } int freq = (int)(config.BrakeSlip.MaxFrequency * percentage); freq.ClipMin(config.BrakeSlip.MinFrequency); ds5w_set_trigger_effect_vibration(1, 0, config.BrakeSlip.Amplitude, freq); - Thread.Sleep((int)(1000f / 200 * 4)); + Thread.Sleep((int)(1000f / 250 * 4)); } else ds5w_set_trigger_effect_off(1); @@ -83,14 +83,14 @@ public static void HandleAcceleration(DualSenseConfiguration config) if (percentage >= 0.05f) { ds5w_set_trigger_effect_feedback(0, 0, (int)(config.ThrottleSlip.FeedbackStrength * percentage)); - Thread.Sleep((int)(1000f / 200)); + Thread.Sleep((int)(1000f / 250)); ds5w_set_trigger_effect_off(0); } int freq = (int)(config.ThrottleSlip.MaxFrequency * percentage); freq.ClipMin(config.ThrottleSlip.MinFrequency); ds5w_set_trigger_effect_vibration(0, 0, config.ThrottleSlip.Amplitude, freq); - Thread.Sleep((int)(1000f / 200 * 4)); + Thread.Sleep((int)(1000f / 250 * 4)); } else ds5w_set_trigger_effect_off(0); From 4780c3a16321027a464bafaa1e7c1cb153e12e39 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sun, 26 Jan 2025 01:10:34 +0100 Subject: [PATCH 14/18] revert back to single thread --- .../Overlays/Driving/DualSense/DualSenseJob.cs | 15 ++------------- .../Driving/DualSense/DualSenseOverlay.cs | 12 ++++-------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs index d79789521..f2e5a865a 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseJob.cs @@ -3,7 +3,7 @@ namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; -internal sealed class ThrottleJob(DualSenseOverlay overlay) : AbstractLoopJob +internal sealed class HapticsJob(DualSenseOverlay overlay) : AbstractLoopJob { public sealed override void RunAction() { @@ -11,18 +11,7 @@ public sealed override void RunAction() return; TriggerHaptics.HandleAcceleration(overlay._config); - } - public override void AfterCancel() => ds5w_set_trigger_effect_off(0); -} - -internal sealed class BrakeJob(DualSenseOverlay overlay) : AbstractLoopJob -{ - public sealed override void RunAction() - { - if (!overlay.ShouldRender()) - return; - TriggerHaptics.HandleBraking(overlay._config); } - public override void AfterCancel() => ds5w_set_trigger_effect_off(1); + public override void AfterCancel() { ds5w_set_trigger_effect_off(0); ds5w_set_trigger_effect_off(1); } } diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs index 7a1c5977b..3187e53c6 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseOverlay.cs @@ -19,8 +19,7 @@ namespace RaceElement.HUD.Common.Overlays.Driving.DualSense; internal sealed class DualSenseOverlay : CommonAbstractOverlay { internal readonly DualSenseConfiguration _config = new(); - private ThrottleJob _throttleJob; - private BrakeJob _brakeJob; + private HapticsJob _hapticsJob; public DualSenseOverlay(Rectangle rectangle) : base(rectangle, "DualSense") { @@ -36,17 +35,14 @@ public sealed override void BeforeStart() ExtractDs5ApiDll(); ds5w_init(); - _throttleJob = new ThrottleJob(this) { IntervalMillis = 1000 / 200 }; - _brakeJob = new BrakeJob(this) { IntervalMillis = 1000 / 200 }; - _throttleJob.Run(); - _brakeJob.Run(); + _hapticsJob = new HapticsJob(this) { IntervalMillis = 1000 / 200 }; + _hapticsJob.Run(); } public sealed override void BeforeStop() { if (IsPreviewing) return; - _throttleJob?.CancelJoin(); - _brakeJob?.CancelJoin(); + _hapticsJob?.CancelJoin(); ds5w_shutdown(); } From 4d725627cb35e92cde904bc425af982b8f175ea2 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sun, 26 Jan 2025 01:12:42 +0100 Subject: [PATCH 15/18] Update TriggerHaptics.cs - fix brake behavior --- .../Overlays/Driving/DualSense/TriggerHaptics.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs index 640e7215a..2abe4d66f 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/TriggerHaptics.cs @@ -38,9 +38,7 @@ public static void HandleBraking(DualSenseConfiguration config) if (percentage >= 0.05f) { - float perc = (config.BrakeSlip.FeedbackStrength * percentage); - perc.ClipMin(config.BrakeSlip.FeedbackStrength); - ds5w_set_trigger_effect_feedback(1, 0, (int)perc); + ds5w_set_trigger_effect_feedback(1, 0, (int)(config.BrakeSlip.FeedbackStrength * percentage)); Thread.Sleep((int)(1000f / 250)); ds5w_set_trigger_effect_off(1); } From 78348d1d7b781207dc698ded643daf03cd287044 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sun, 26 Jan 2025 01:19:01 +0100 Subject: [PATCH 16/18] Update DsxConfiguration.cs adjust defaults --- .../Overlays/Pitwall/DSX/DsxConfiguration.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Pitwall/DSX/DsxConfiguration.cs b/Race Element.HUD.Common/Overlays/Pitwall/DSX/DsxConfiguration.cs index 72f8197fc..43e57c53e 100644 --- a/Race Element.HUD.Common/Overlays/Pitwall/DSX/DsxConfiguration.cs +++ b/Race Element.HUD.Common/Overlays/Pitwall/DSX/DsxConfiguration.cs @@ -32,7 +32,7 @@ public sealed class BrakeSlipHaptics [ToolTip("Higher is stronger dynamic feedback.")] [IntRange(5, 8, 1)] - public int FeedbackStrength { get; init; } = 7; + public int FeedbackStrength { get; init; } = 3; [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] [IntRange(1, 10, 1)] @@ -44,7 +44,7 @@ public sealed class BrakeSlipHaptics [ToolTip("Change the amplitude(strength) of the vibration effect in the trigger.")] [IntRange(5, 8, 1)] - public int Amplitude { get; init; } = 8; + public int Amplitude { get; init; } = 6; } [ConfigGrouping("Throttle Slip", "Adjust the slip effect whilst applying the throttle.\nModify the threshold to increase or decrease sensitivity in different situations.")] @@ -68,7 +68,7 @@ public sealed class ThrottleSlipHaptics [ToolTip("Higher is stronger dynamic feedback.")] [IntRange(5, 8, 1)] - public int FeedbackStrength { get; init; } = 8; + public int FeedbackStrength { get; init; } = 2; [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] [IntRange(1, 10, 1)] From f0aa7b2c2dd147875b24ee89ec0b1fdc0a9985d2 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sun, 26 Jan 2025 01:27:13 +0100 Subject: [PATCH 17/18] Revert "Update DsxConfiguration.cs" This reverts commit 78348d1d7b781207dc698ded643daf03cd287044. --- .../Overlays/Pitwall/DSX/DsxConfiguration.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Pitwall/DSX/DsxConfiguration.cs b/Race Element.HUD.Common/Overlays/Pitwall/DSX/DsxConfiguration.cs index 43e57c53e..72f8197fc 100644 --- a/Race Element.HUD.Common/Overlays/Pitwall/DSX/DsxConfiguration.cs +++ b/Race Element.HUD.Common/Overlays/Pitwall/DSX/DsxConfiguration.cs @@ -32,7 +32,7 @@ public sealed class BrakeSlipHaptics [ToolTip("Higher is stronger dynamic feedback.")] [IntRange(5, 8, 1)] - public int FeedbackStrength { get; init; } = 3; + public int FeedbackStrength { get; init; } = 7; [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] [IntRange(1, 10, 1)] @@ -44,7 +44,7 @@ public sealed class BrakeSlipHaptics [ToolTip("Change the amplitude(strength) of the vibration effect in the trigger.")] [IntRange(5, 8, 1)] - public int Amplitude { get; init; } = 6; + public int Amplitude { get; init; } = 8; } [ConfigGrouping("Throttle Slip", "Adjust the slip effect whilst applying the throttle.\nModify the threshold to increase or decrease sensitivity in different situations.")] @@ -68,7 +68,7 @@ public sealed class ThrottleSlipHaptics [ToolTip("Higher is stronger dynamic feedback.")] [IntRange(5, 8, 1)] - public int FeedbackStrength { get; init; } = 2; + public int FeedbackStrength { get; init; } = 8; [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] [IntRange(1, 10, 1)] From 4659d9c5f1176784c3dbf14af9aec3bcc3ca7905 Mon Sep 17 00:00:00 2001 From: Reinier Klarenberg Date: Sun, 26 Jan 2025 01:27:54 +0100 Subject: [PATCH 18/18] Update DualSenseConfiguration.cs adjust defaults --- .../Overlays/Driving/DualSense/DualSenseConfiguration.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs index 8a1ec60e3..ea7423214 100644 --- a/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs +++ b/Race Element.HUD.Common/Overlays/Driving/DualSense/DualSenseConfiguration.cs @@ -32,11 +32,11 @@ public sealed class BrakeSlipHaptics [ToolTip("Higher is stronger dynamic feedback.")] [IntRange(1, 8, 1)] - public int FeedbackStrength { get; init; } = 7; + public int FeedbackStrength { get; init; } = 3; [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] [IntRange(1, 10, 1)] - public int MinFrequency { get; init; } = 3; + public int MinFrequency { get; init; } = 6; [ToolTip("Sets the max frequency of the vibration effect in the trigger.")] [IntRange(20, 150, 1)] @@ -44,7 +44,7 @@ public sealed class BrakeSlipHaptics [ToolTip("Change the amplitude(strength) of the vibration effect in the trigger.")] [IntRange(1, 8, 1)] - public int Amplitude { get; init; } = 8; + public int Amplitude { get; init; } = 6; } [ConfigGrouping("Throttle Slip", "Adjust the slip effect whilst applying the throttle.\nModify the threshold to increase or decrease sensitivity in different situations.")] @@ -68,7 +68,7 @@ public sealed class ThrottleSlipHaptics [ToolTip("Higher is stronger dynamic feedback.")] [IntRange(1, 8, 1)] - public int FeedbackStrength { get; init; } = 8; + public int FeedbackStrength { get; init; } = 2; [ToolTip("Sets the min frequency of the vibration effect in the trigger.")] [IntRange(1, 10, 1)]