From e52459d02d3e490691c686ab38adce10f85fe86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Mon, 28 Nov 2022 11:05:07 +0100 Subject: [PATCH] Do not send repeated haptic if disabled --- RELEASE.md | 1 + .../Devices/SteamControllerHaptic.cs | 18 +++++++++++++++++- SteamController/Profiles/X360RumbleProfile.cs | 2 -- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index df6f926..3736f26 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -28,3 +28,4 @@ It does help this project on being supported. - STEAM + 3 dots brings Task Manager (CTRL+SHIFT+ESCAPE) - Append `controller_blacklist` to `config.vdf` if missing - Add configurable BackPanel keys (allowed mappings are subject to change) +- Fix delay in X360Rumble: Do not send repeated haptic if disabled diff --git a/SteamController/Devices/SteamControllerHaptic.cs b/SteamController/Devices/SteamControllerHaptic.cs index 2d72533..9b7dcca 100644 --- a/SteamController/Devices/SteamControllerHaptic.cs +++ b/SteamController/Devices/SteamControllerHaptic.cs @@ -8,7 +8,9 @@ namespace SteamController.Devices { public partial class SteamController { - public bool SetHaptic(byte position, ushort amplitude, ushort period, ushort count = 0) + private bool[] hapticEnabled = new bool[byte.MaxValue]; + + private bool sendHaptic(byte position, ushort amplitude, ushort period, ushort count = 0) { var haptic = new SDCHapticPacket() { @@ -20,6 +22,9 @@ namespace SteamController.Devices count = count }; + Log.TraceLine("STEAM: Haptic: pos={0}, amplitude={1}, period={2}, count={3}", + position, amplitude, period, count); + var bytes = new byte[Marshal.SizeOf()]; var handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); try @@ -34,5 +39,16 @@ namespace SteamController.Devices return false; } } + + public bool SetHaptic(byte position, ushort amplitude, ushort period, ushort count = 0) + { + // do not send repeated haptic queries if was disabled + bool enabled = amplitude != 0 && period != 0; + if (!hapticEnabled[position] && !enabled) + return false; + hapticEnabled[position] = enabled; + + return sendHaptic(position, amplitude, period, count); + } } } diff --git a/SteamController/Profiles/X360RumbleProfile.cs b/SteamController/Profiles/X360RumbleProfile.cs index 95da882..912f259 100644 --- a/SteamController/Profiles/X360RumbleProfile.cs +++ b/SteamController/Profiles/X360RumbleProfile.cs @@ -23,14 +23,12 @@ namespace SteamController.Profiles if (context.X360.FeedbackLargeMotor.HasValue) { - Log.TraceLine("X360: Feedback Large: {0}", context.X360.FeedbackLargeMotor.Value); context.Steam.SetHaptic( 1, GetHapticAmplitude(context.X360.FeedbackLargeMotor), RumbleSettings.Period, FeedbackCount); } if (context.X360.FeedbackSmallMotor.HasValue) { - Log.TraceLine("X360: Feedback Small: {0}", context.X360.FeedbackSmallMotor.Value); context.Steam.SetHaptic( 0, GetHapticAmplitude(context.X360.FeedbackSmallMotor), RumbleSettings.Period, FeedbackCount); }