From b41a66922340839a2286329f8a854f943e830622 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 25 Mar 2017 16:32:45 -0700 Subject: [PATCH] Interpolate L2 and R2 based on dead zone values --- DS4Windows/DS4Control/Mapping.cs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 24b06ed..dbdf172 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -470,10 +470,33 @@ namespace DS4Windows dState.RX = (byte)(Math.Cos(r) * (127.5f + RSDeadzone[device]) + 127.5f); dState.RY = (byte)(Math.Sin(r) * (127.5f + RSDeadzone[device]) + 127.5f); } - if (L2Deadzone[device] > 0 && cState.L2 < L2Deadzone[device]) - dState.L2 = 0; - if (R2Deadzone[device] > 0 && cState.R2 < R2Deadzone[device]) - dState.R2 = 0; + + byte l2Deadzone = L2Deadzone[device]; + if (l2Deadzone > 0) + { + if (cState.L2 > l2Deadzone) + { + dState.L2 = (byte)(((cState.L2 - l2Deadzone) / (double)(255 - l2Deadzone)) * 255); + } + else + { + dState.L2 = 0; + } + } + + byte r2Deadzone = R2Deadzone[device]; + if (r2Deadzone > 0) + { + if (cState.R2 > r2Deadzone) + { + dState.R2 = (byte)(((cState.R2 - l2Deadzone) / (double)(255 - r2Deadzone)) * 255); + } + else + { + dState.R2 = 0; + } + } + if (LSSens[device] != 1) { dState.LX = (byte)Clamp(0, LSSens[device] * (dState.LX - 127) + 127, 255);