From fad0ddda26ceb53b66b60c84f90884ee7431fd17 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Tue, 21 Jan 2020 03:21:43 -0600 Subject: [PATCH] Make max output setting for LS and RS Maybe implement for other axes later --- DS4Windows/DS4Control/Mapping.cs | 29 +++++++++++-- DS4Windows/DS4Control/ProfilePropGroups.cs | 1 + DS4Windows/DS4Control/ScpUtil.cs | 19 +++++++++ DS4Windows/DS4Forms/ProfileEditor.xaml | 41 +++++++++++-------- .../ViewModels/ProfileSettingsViewModel.cs | 12 ++++++ 5 files changed, 81 insertions(+), 21 deletions(-) diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 65c25d5..dbb1591 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -630,8 +630,9 @@ namespace DS4Windows int lsDeadzone = lsMod.deadZone; int lsAntiDead = lsMod.antiDeadZone; int lsMaxZone = lsMod.maxZone; + double lsMaxOutput = lsMod.maxOutput; - if (lsDeadzone > 0 || lsAntiDead > 0 || lsMaxZone != 100) + if (lsDeadzone > 0 || lsAntiDead > 0 || lsMaxZone != 100 || lsMaxOutput != 100.0) { double lsSquared = Math.Pow(cState.LX - 128f, 2) + Math.Pow(cState.LY - 128f, 2); double lsDeadzoneSquared = Math.Pow(lsDeadzone, 2); @@ -640,12 +641,13 @@ namespace DS4Windows dState.LX = 128; dState.LY = 128; } - else if ((lsDeadzone > 0 && lsSquared > lsDeadzoneSquared) || lsAntiDead > 0 || lsMaxZone != 100) + else if ((lsDeadzone > 0 && lsSquared > lsDeadzoneSquared) || lsAntiDead > 0 || lsMaxZone != 100 || lsMaxOutput != 100.0) { double r = Math.Atan2(-(dState.LY - 128.0), (dState.LX - 128.0)); double maxXValue = dState.LX >= 128.0 ? 127.0 : -128; double maxYValue = dState.LY >= 128.0 ? 127.0 : -128; double ratio = lsMaxZone / 100.0; + double maxOutRatio = lsMaxOutput / 100.0; double maxZoneXNegValue = (ratio * -128) + 128; double maxZoneXPosValue = (ratio * 127) + 128; @@ -677,6 +679,14 @@ namespace DS4Windows tempOutputY = (currentY - 128.0) / maxZoneY; } + if (lsMaxOutput != 100.0) + { + double maxOutXRatio = Math.Abs(Math.Cos(r)) * maxOutRatio; + double maxOutYRatio = Math.Abs(Math.Sin(r)) * maxOutRatio; + tempOutputX = Math.Min(Math.Max(tempOutputX, 0.0), maxOutXRatio); + tempOutputY = Math.Min(Math.Max(tempOutputY, 0.0), maxOutYRatio); + } + double tempLsXAntiDeadPercent = 0.0, tempLsYAntiDeadPercent = 0.0; if (lsAntiDead > 0) { @@ -712,7 +722,9 @@ namespace DS4Windows int rsDeadzone = rsMod.deadZone; int rsAntiDead = rsMod.antiDeadZone; int rsMaxZone = rsMod.maxZone; - if (rsDeadzone > 0 || rsAntiDead > 0 || rsMaxZone != 100) + double rsMaxOutput = rsMod.maxOutput; + + if (rsDeadzone > 0 || rsAntiDead > 0 || rsMaxZone != 100 || rsMaxOutput != 100.0) { double rsSquared = Math.Pow(cState.RX - 128.0, 2) + Math.Pow(cState.RY - 128.0, 2); double rsDeadzoneSquared = Math.Pow(rsDeadzone, 2); @@ -721,12 +733,13 @@ namespace DS4Windows dState.RX = 128; dState.RY = 128; } - else if ((rsDeadzone > 0 && rsSquared > rsDeadzoneSquared) || rsAntiDead > 0 || rsMaxZone != 100) + else if ((rsDeadzone > 0 && rsSquared > rsDeadzoneSquared) || rsAntiDead > 0 || rsMaxZone != 100 || rsMaxOutput != 100.0) { double r = Math.Atan2(-(dState.RY - 128.0), (dState.RX - 128.0)); double maxXValue = dState.RX >= 128.0 ? 127 : -128; double maxYValue = dState.RY >= 128.0 ? 127 : -128; double ratio = rsMaxZone / 100.0; + double maxOutRatio = rsMaxOutput / 100.0; double maxZoneXNegValue = (ratio * -128.0) + 128.0; double maxZoneXPosValue = (ratio * 127.0) + 128.0; @@ -760,6 +773,14 @@ namespace DS4Windows tempOutputY = (currentY - 128.0) / maxZoneY; } + if (rsMaxOutput != 100.0) + { + double maxOutXRatio = Math.Abs(Math.Cos(r)) * maxOutRatio; + double maxOutYRatio = Math.Abs(Math.Sin(r)) * maxOutRatio; + tempOutputX = Math.Min(Math.Max(tempOutputX, 0.0), maxOutXRatio); + tempOutputY = Math.Min(Math.Max(tempOutputY, 0.0), maxOutYRatio); + } + double tempRsXAntiDeadPercent = 0.0, tempRsYAntiDeadPercent = 0.0; if (rsAntiDead > 0) { diff --git a/DS4Windows/DS4Control/ProfilePropGroups.cs b/DS4Windows/DS4Control/ProfilePropGroups.cs index 4bc2c69..7ed77cc 100644 --- a/DS4Windows/DS4Control/ProfilePropGroups.cs +++ b/DS4Windows/DS4Control/ProfilePropGroups.cs @@ -15,6 +15,7 @@ namespace DS4Windows public int deadZone; public int antiDeadZone; public int maxZone = 100; + public double maxOutput = 100.0; } public class TriggerDeadZoneZInfo diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index e6c4244..9d2d9b7 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -2488,6 +2488,8 @@ namespace DS4Windows XmlNode xmlRSAD = m_Xdoc.CreateNode(XmlNodeType.Element, "RSAntiDeadZone", null); xmlRSAD.InnerText = rsModInfo[device].antiDeadZone.ToString(); Node.AppendChild(xmlRSAD); XmlNode xmlLSMaxZone = m_Xdoc.CreateNode(XmlNodeType.Element, "LSMaxZone", null); xmlLSMaxZone.InnerText = lsModInfo[device].maxZone.ToString(); Node.AppendChild(xmlLSMaxZone); XmlNode xmlRSMaxZone = m_Xdoc.CreateNode(XmlNodeType.Element, "RSMaxZone", null); xmlRSMaxZone.InnerText = rsModInfo[device].maxZone.ToString(); Node.AppendChild(xmlRSMaxZone); + XmlNode xmlLSMaxOutput = m_Xdoc.CreateNode(XmlNodeType.Element, "LSMaxOutput", null); xmlLSMaxOutput.InnerText = lsModInfo[device].maxOutput.ToString(); Node.AppendChild(xmlLSMaxOutput); + XmlNode xmlRSMaxOutput = m_Xdoc.CreateNode(XmlNodeType.Element, "RSMaxOutput", null); xmlRSMaxOutput.InnerText = rsModInfo[device].maxOutput.ToString(); Node.AppendChild(xmlRSMaxOutput); XmlNode xmlLSRotation = m_Xdoc.CreateNode(XmlNodeType.Element, "LSRotation", null); xmlLSRotation.InnerText = Convert.ToInt32(LSRotation[device] * 180.0 / Math.PI).ToString(); Node.AppendChild(xmlLSRotation); XmlNode xmlRSRotation = m_Xdoc.CreateNode(XmlNodeType.Element, "RSRotation", null); xmlRSRotation.InnerText = Convert.ToInt32(RSRotation[device] * 180.0 / Math.PI).ToString(); Node.AppendChild(xmlRSRotation); @@ -3271,6 +3273,22 @@ namespace DS4Windows } catch { rsModInfo[device].maxZone = 100; missingSetting = true; } + try + { + Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LSMaxOutput"); double temp = 100.0; + temp = double.Parse(Item.InnerText); + lsModInfo[device].maxOutput = Math.Min(Math.Max(temp, 0.0), 100.0); + } + catch { lsModInfo[device].maxOutput = 100.0; missingSetting = true; } + + try + { + Item = m_Xdoc.SelectSingleNode("/" + rootname + "/RSMaxOutput"); double temp = 100.0; + temp = double.Parse(Item.InnerText); + rsModInfo[device].maxOutput = Math.Min(Math.Max(temp, 0.0), 100.0); + } + catch { rsModInfo[device].maxOutput = 100; missingSetting = true; } + try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/SXDeadZone"); double.TryParse(Item.InnerText, out SXDeadzone[device]); } catch { SXDeadzone[device] = 0.02; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/SZDeadZone"); double.TryParse(Item.InnerText, out SZDeadzone[device]); } @@ -4747,6 +4765,7 @@ namespace DS4Windows lsModInfo[device].deadZone = rsModInfo[device].deadZone = 10; lsModInfo[device].antiDeadZone = rsModInfo[device].antiDeadZone = 25; lsModInfo[device].maxZone = rsModInfo[device].maxZone = 100; + lsModInfo[device].maxOutput = rsModInfo[device].maxOutput = 100.0; l2ModInfo[device].antiDeadZone = r2ModInfo[device].antiDeadZone = 0; l2ModInfo[device].maxZone = r2ModInfo[device].maxZone = 100; LSRotation[device] = 0.0; diff --git a/DS4Windows/DS4Forms/ProfileEditor.xaml b/DS4Windows/DS4Forms/ProfileEditor.xaml index 434684d..acc1b56 100644 --- a/DS4Windows/DS4Forms/ProfileEditor.xaml +++ b/DS4Windows/DS4Forms/ProfileEditor.xaml @@ -309,6 +309,7 @@ + @@ -332,14 +333,20 @@ -