From 23ee6f9d8a95a0f18c067e25c06b52c6ef37a5ab Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 22 Apr 2017 00:26:44 -0700 Subject: [PATCH] Minor style changes and excess removed --- DS4Windows/DS4Control/ControlSerivce.cs | 62 ------------ DS4Windows/DS4Control/DS4StateFieldMapping.cs | 2 +- DS4Windows/DS4Control/ScpUtil.cs | 98 +++++++++++++++---- DS4Windows/DS4Library/DS4Device.cs | 4 + 4 files changed, 86 insertions(+), 80 deletions(-) diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlSerivce.cs index 6388312..5aa99b4 100644 --- a/DS4Windows/DS4Control/ControlSerivce.cs +++ b/DS4Windows/DS4Control/ControlSerivce.cs @@ -10,20 +10,6 @@ using System.Threading.Tasks; using static DS4Windows.Global; namespace DS4Windows { - /*public class DS4ControlInfo - { - public enum ControlType { Unknown = 0, Button, AxisDir, Trigger, Touch, GyroDir, SwipeDir } - public DS4Controls control = DS4Controls.None; - public ControlType mappedType = ControlType.Unknown; - - public DS4ControlInfo(DS4Controls control, ControlType mappedType) - { - this.control = control; - this.mappedType = mappedType; - } - } - */ - public class ControlService { public X360Device x360Bus; @@ -41,8 +27,6 @@ namespace DS4Windows private int eCode = 0; bool[] buttonsdown = { false, false, false, false }; List dcs = new List(); - //Dictionary controlInfoDir = - // new Dictionary(); bool[] held = new bool[DS4_CONTROLLER_COUNT]; int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 }; SoundPlayer sp = new SoundPlayer(); @@ -60,7 +44,6 @@ namespace DS4Windows sp.Stream = Properties.Resources.EE; x360Bus = new X360Device(); AddtoDS4List(); - //populateControlInfoDictionary(); for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++) { @@ -105,51 +88,6 @@ namespace DS4Windows dcs.Add(DS4Controls.SwipeRight); } - /*void populateControlInfoDictionary() - { - controlInfoDir.Add(DS4Controls.Cross, new DS4ControlInfo(DS4Controls.Cross, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.Circle, new DS4ControlInfo(DS4Controls.Circle, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.Square, new DS4ControlInfo(DS4Controls.Square, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.Triangle, new DS4ControlInfo(DS4Controls.Triangle, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.Options, new DS4ControlInfo(DS4Controls.Options, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.Share, new DS4ControlInfo(DS4Controls.Share, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.DpadUp, new DS4ControlInfo(DS4Controls.DpadUp, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.DpadDown, new DS4ControlInfo(DS4Controls.DpadDown, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.DpadLeft, new DS4ControlInfo(DS4Controls.DpadLeft, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.DpadRight, new DS4ControlInfo(DS4Controls.DpadRight, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.PS, new DS4ControlInfo(DS4Controls.PS, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.L1, new DS4ControlInfo(DS4Controls.L1, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.R1, new DS4ControlInfo(DS4Controls.R1, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.L2, new DS4ControlInfo(DS4Controls.L2, DS4ControlInfo.ControlType.Trigger)); - controlInfoDir.Add(DS4Controls.R2, new DS4ControlInfo(DS4Controls.R2, DS4ControlInfo.ControlType.Trigger)); - controlInfoDir.Add(DS4Controls.L3, new DS4ControlInfo(DS4Controls.L3, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.R3, new DS4ControlInfo(DS4Controls.R3, DS4ControlInfo.ControlType.Button)); - controlInfoDir.Add(DS4Controls.LXPos, new DS4ControlInfo(DS4Controls.LXPos, DS4ControlInfo.ControlType.AxisDir)); - controlInfoDir.Add(DS4Controls.LXNeg, new DS4ControlInfo(DS4Controls.LXNeg, DS4ControlInfo.ControlType.AxisDir)); - controlInfoDir.Add(DS4Controls.LYPos, new DS4ControlInfo(DS4Controls.LYPos, DS4ControlInfo.ControlType.AxisDir)); - controlInfoDir.Add(DS4Controls.LYNeg, new DS4ControlInfo(DS4Controls.LYNeg, DS4ControlInfo.ControlType.AxisDir)); - controlInfoDir.Add(DS4Controls.RXPos, new DS4ControlInfo(DS4Controls.RXPos, DS4ControlInfo.ControlType.AxisDir)); - controlInfoDir.Add(DS4Controls.RXNeg, new DS4ControlInfo(DS4Controls.RXNeg, DS4ControlInfo.ControlType.AxisDir)); - controlInfoDir.Add(DS4Controls.RYPos, new DS4ControlInfo(DS4Controls.RYPos, DS4ControlInfo.ControlType.AxisDir)); - controlInfoDir.Add(DS4Controls.RYNeg, new DS4ControlInfo(DS4Controls.RYNeg, DS4ControlInfo.ControlType.AxisDir)); - - controlInfoDir.Add(DS4Controls.SwipeUp, new DS4ControlInfo(DS4Controls.SwipeUp, DS4ControlInfo.ControlType.SwipeDir)); - controlInfoDir.Add(DS4Controls.SwipeDown, new DS4ControlInfo(DS4Controls.SwipeDown, DS4ControlInfo.ControlType.SwipeDir)); - controlInfoDir.Add(DS4Controls.SwipeLeft, new DS4ControlInfo(DS4Controls.SwipeLeft, DS4ControlInfo.ControlType.SwipeDir)); - controlInfoDir.Add(DS4Controls.SwipeRight, new DS4ControlInfo(DS4Controls.SwipeRight, DS4ControlInfo.ControlType.SwipeDir)); - - controlInfoDir.Add(DS4Controls.TouchLeft, new DS4ControlInfo(DS4Controls.TouchLeft, DS4ControlInfo.ControlType.Touch)); - controlInfoDir.Add(DS4Controls.TouchUpper, new DS4ControlInfo(DS4Controls.TouchUpper, DS4ControlInfo.ControlType.Touch)); - controlInfoDir.Add(DS4Controls.TouchMulti, new DS4ControlInfo(DS4Controls.TouchMulti, DS4ControlInfo.ControlType.Touch)); - controlInfoDir.Add(DS4Controls.TouchRight, new DS4ControlInfo(DS4Controls.TouchRight, DS4ControlInfo.ControlType.Touch)); - - controlInfoDir.Add(DS4Controls.GyroXPos, new DS4ControlInfo(DS4Controls.GyroXPos, DS4ControlInfo.ControlType.GyroDir)); - controlInfoDir.Add(DS4Controls.GyroXNeg, new DS4ControlInfo(DS4Controls.GyroXNeg, DS4ControlInfo.ControlType.GyroDir)); - controlInfoDir.Add(DS4Controls.GyroZPos, new DS4ControlInfo(DS4Controls.GyroZPos, DS4ControlInfo.ControlType.GyroDir)); - controlInfoDir.Add(DS4Controls.GyroZNeg, new DS4ControlInfo(DS4Controls.GyroZNeg, DS4ControlInfo.ControlType.GyroDir)); - } - */ - private async void WarnExclusiveModeFailure(DS4Device device) { if (DS4Devices.isExclusiveMode && !device.IsExclusive) diff --git a/DS4Windows/DS4Control/DS4StateFieldMapping.cs b/DS4Windows/DS4Control/DS4StateFieldMapping.cs index c79fdd1..582b03e 100644 --- a/DS4Windows/DS4Control/DS4StateFieldMapping.cs +++ b/DS4Windows/DS4Control/DS4StateFieldMapping.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace DS4Windows { - class DS4StateFieldMapping + public class DS4StateFieldMapping { public enum ControlType { Unknown = 0, Button, AxisDir, Trigger, Touch, GyroDir, SwipeDir } diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 0e5a5e3..8dfd6df 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -560,8 +560,11 @@ namespace DS4Windows public static int GetActionIndexOf(string name) { for (int i = 0, actionCount = m_Config.actions.Count; i < actionCount; i++) + { if (m_Config.actions[i].name == name) return i; + } + return -1; } @@ -798,7 +801,7 @@ namespace DS4Windows public bool[] mouseAccel = { true, true, true, true, true }; public DS4Color[] m_LowLeds = new DS4Color[] { - new DS4Color(Color.Black), + new DS4Color(Color.Black), new DS4Color(Color.Black), new DS4Color(Color.Black), new DS4Color(Color.Black), @@ -814,7 +817,7 @@ namespace DS4Windows }; public DS4Color[] m_ChargingLeds = new DS4Color[] { - new DS4Color(Color.Black), + new DS4Color(Color.Black), new DS4Color(Color.Black), new DS4Color(Color.Black), new DS4Color(Color.Black), @@ -822,7 +825,7 @@ namespace DS4Windows }; public DS4Color[] m_FlashLeds = new DS4Color[] { - new DS4Color(Color.Black), + new DS4Color(Color.Black), new DS4Color(Color.Black), new DS4Color(Color.Black), new DS4Color(Color.Black), @@ -831,7 +834,7 @@ namespace DS4Windows public bool[] useCustomLeds = new bool[] { false, false, false, false }; public DS4Color[] m_CustomLeds = new DS4Color[] { - new DS4Color(Color.Black), + new DS4Color(Color.Black), new DS4Color(Color.Black), new DS4Color(Color.Black), new DS4Color(Color.Black) @@ -891,8 +894,11 @@ namespace DS4Windows for (int i = 0; i < 5; i++) { foreach (DS4Controls dc in Enum.GetValues(typeof(DS4Controls))) + { if (dc != DS4Controls.None) ds4settings[i].Add(new DS4ControlSettings(dc)); + } + /*customMapKeyTypes[i] = new Dictionary(); customMapKeys[i] = new Dictionary(); customMapMacros[i] = new Dictionary(); @@ -904,6 +910,7 @@ namespace DS4Windows shiftCustomMapMacros[i] = new Dictionary(); shiftCustomMapButtons[i] = new Dictionary(); shiftCustomMapExtras[i] = new Dictionary();*/ + profileActions[i] = new List(); profileActions[i].Add("Disconnect Controller"); profileActionCount[i] = profileActions[i].Count; @@ -2490,12 +2497,18 @@ namespace DS4Windows dc = getDS4ControlsByName(buttonName); else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + + //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + { + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.control == dc) { dcs.UpdateSettings(shift, action, exts, kt, trigger); break; } + } } public void UpdateDS4CExtra(int deviceNum, string buttonName, bool shift, string exts) @@ -2505,15 +2518,22 @@ namespace DS4Windows dc = getDS4ControlsByName(buttonName); else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + + //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + { + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.control == dc) { if (shift) dcs.shiftExtras = exts; else dcs.extras = exts; + break; } + } } private void UpdateDS4CKeyType(int deviceNum, string buttonName, bool shift, DS4KeyType keyType) @@ -2523,15 +2543,22 @@ namespace DS4Windows dc = getDS4ControlsByName(buttonName); else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + + //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + { + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.control == dc) { if (shift) dcs.shiftKeyType = keyType; else dcs.keyType = keyType; + break; } + } } public object GetDS4Action(int deviceNum, string buttonName, bool shift) @@ -2541,7 +2568,12 @@ namespace DS4Windows dc = getDS4ControlsByName(buttonName); else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + + //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + { + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.control == dc) { if (shift) @@ -2549,6 +2581,8 @@ namespace DS4Windows else return dcs.action; } + } + return null; } @@ -2579,7 +2613,12 @@ namespace DS4Windows dc = getDS4ControlsByName(buttonName); else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + + //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + { + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.control == dc) { if (shift) @@ -2587,6 +2626,8 @@ namespace DS4Windows else return dcs.extras; } + } + return null; } @@ -2597,7 +2638,12 @@ namespace DS4Windows dc = getDS4ControlsByName(buttonName); else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + + //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + { + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.control == dc) { if (shift) @@ -2605,6 +2651,8 @@ namespace DS4Windows else return dcs.keyType; } + } + return DS4KeyType.None; } @@ -2615,9 +2663,16 @@ namespace DS4Windows dc = getDS4ControlsByName(buttonName); else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + + //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + { + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.control == dc) - return dcs.shiftTrigger; + return dcs.shiftTrigger; + } + return 0; } @@ -2641,9 +2696,16 @@ namespace DS4Windows dc = getDS4ControlsByName(buttonName); else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + + //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + { + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.control == dc) return dcs; + } + return null; } @@ -2663,9 +2725,10 @@ namespace DS4Windows public bool HasCustomActions(int deviceNum) { //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) - for (int i = 0, listLen = ds4settings[deviceNum].Count; i < listLen; i++) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) { - DS4ControlSettings dcs = ds4settings[deviceNum][i]; + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.action != null || dcs.shiftAction != null) return true; } @@ -2677,9 +2740,10 @@ namespace DS4Windows public bool HasCustomExtras(int deviceNum) { //foreach (DS4ControlSettings dcs in ds4settings[deviceNum]) - for (int i = 0, listLen = ds4settings[deviceNum].Count; i < listLen; i++) + List ds4settingsList = ds4settings[deviceNum]; + for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) { - DS4ControlSettings dcs = ds4settings[deviceNum][i]; + DS4ControlSettings dcs = ds4settingsList[i]; if (dcs.extras != null || dcs.shiftExtras != null) return true; } diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index f0aa31a..56f86a4 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -359,6 +359,7 @@ namespace DS4Windows outputReportBuffer = new byte[BT_OUTPUT_REPORT_LENGTH]; warnInterval = WARN_INTERVAL_BT; } + touchpad = new DS4Touchpad(); sixAxis = new DS4SixAxis(); } @@ -500,9 +501,11 @@ namespace DS4Windows { return priorInputReport30 != 0xff; } + private byte priorInputReport30 = 0xff; public double Latency = 0; public string error; + private void performDs4Input() { firstActive = DateTime.UtcNow; @@ -736,6 +739,7 @@ namespace DS4Windows { setTestRumble(); setHapticState(); + if (conType == ConnectionType.BT) { outputReportBuffer[0] = 0x11;