From edeaa30b5901bead81efd0c7c0675c2b9e685fce Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Fri, 12 May 2017 07:48:58 -0700 Subject: [PATCH] Code clean up. Reset xinput mapping for more bound actions. --- .../{ControlSerivce.cs => ControlService.cs} | 145 +-------- DS4Windows/DS4Control/DS4LightBar.cs | 3 - DS4Windows/DS4Control/ITouchpadBehaviour.cs | 3 - DS4Windows/DS4Control/Mapping.cs | 13 +- DS4Windows/DS4Control/Mouse.cs | 4 - DS4Windows/DS4Control/MouseWheel.cs | 3 - DS4Windows/DS4Control/ScpUtil.cs | 79 ++++- DS4Windows/DS4Forms/KBM360.cs | 152 +++++++--- DS4Windows/DS4Forms/Options.Designer.cs | 285 +++++++++--------- DS4Windows/DS4Forms/Options.cs | 16 - DS4Windows/DS4Forms/Options.resx | 2 +- DS4Windows/DS4Library/DS4Device.cs | 55 ++-- DS4Windows/DS4Windows.csproj | 2 +- DS4Windows/HidLibrary/HidDevice.cs | 15 +- 14 files changed, 386 insertions(+), 391 deletions(-) rename DS4Windows/DS4Control/{ControlSerivce.cs => ControlService.cs} (86%) diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlService.cs similarity index 86% rename from DS4Windows/DS4Control/ControlSerivce.cs rename to DS4Windows/DS4Control/ControlService.cs index 64a0faa..225a2bc 100644 --- a/DS4Windows/DS4Control/ControlSerivce.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -127,7 +127,6 @@ namespace DS4Windows WarnExclusiveModeFailure(device); DS4Controllers[i] = device; - //device.Removal -= DS4Devices.On_Removal; device.Removal += this.On_DS4Removal; device.Removal += DS4Devices.On_Removal; touchPad[i] = new Mouse(i, device); @@ -190,7 +189,6 @@ namespace DS4Windows Log.LogToTray(logMessage); } - //ControllerStatusChanged(this); runHotPlug = true; return true; @@ -281,11 +279,6 @@ namespace DS4Windows { device.StopUpdate(); device.DisconnectBT(true); - /*Task temp = Task.Delay(50).ContinueWith((t) => { - while (!device.IsRemoved) { System.Threading.Thread.Sleep(10); } - }); - temp.Wait(100); - */ } } } @@ -323,7 +316,6 @@ namespace DS4Windows LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")"); WarnExclusiveModeFailure(device); DS4Controllers[Index] = device; - //device.Removal -= DS4Devices.On_Removal; device.Removal += this.On_DS4Removal; device.Removal += DS4Devices.On_Removal; touchPad[Index] = new Mouse(Index, device); @@ -367,8 +359,6 @@ namespace DS4Windows } } } - - //ControllerStatusChanged(this); } return true; @@ -551,7 +541,8 @@ namespace DS4Windows public bool[] lag = { false, false, false, false }; public bool[] inWarnMonitor = { false, false, false, false }; - //Called every time the new input report has arrived + + //Called every time a new input report has arrived protected virtual void On_Report(object sender, EventArgs e) { DS4Device device = (DS4Device)sender; @@ -801,138 +792,6 @@ namespace DS4Windows return result; } - /* TODO: Not used. Possible candidate for removal. Currently keeping for reference. */ - /*public DS4Controls GetInputkeysDS4(int ind) - { - DS4State cState = CurrentState[ind]; - DS4StateExposed eState = ExposedState[ind]; - Mouse tp = touchPad[ind]; - DS4Controls result = DS4Controls.None; - - if (DS4Controllers[ind] != null) - { - if (Mapping.getBoolButtonMapping(cState.Cross)) - { - result = DS4Controls.Cross; - } - else if (Mapping.getBoolButtonMapping(cState.Circle)) - { - result = DS4Controls.Circle; - } - else if (Mapping.getBoolButtonMapping(cState.Triangle)) - { - result = DS4Controls.Triangle; - } - else if (Mapping.getBoolButtonMapping(cState.Square)) - { - result = DS4Controls.Square; - } - else if (Mapping.getBoolButtonMapping(cState.L1)) - { - result = DS4Controls.L1; - } - else if (Mapping.getBoolTriggerMapping(cState.L2)) - { - result = DS4Controls.L2; - } - else if (Mapping.getBoolButtonMapping(cState.L3)) - { - result = DS4Controls.L3; - } - else if (Mapping.getBoolButtonMapping(cState.R1)) - { - result = DS4Controls.R1; - } - else if (Mapping.getBoolTriggerMapping(cState.R2)) - { - result = DS4Controls.R2; - } - else if (Mapping.getBoolButtonMapping(cState.R3)) - { - result = DS4Controls.R3; - } - else if (Mapping.getBoolButtonMapping(cState.DpadUp)) - { - result = DS4Controls.DpadUp; - } - else if (Mapping.getBoolButtonMapping(cState.DpadDown)) - { - result = DS4Controls.DpadDown; - } - else if (Mapping.getBoolButtonMapping(cState.DpadLeft)) - { - result = DS4Controls.DpadLeft; - } - else if (Mapping.getBoolButtonMapping(cState.DpadRight)) - { - result = DS4Controls.DpadRight; - } - else if (Mapping.getBoolButtonMapping(cState.Share)) - { - result = DS4Controls.Share; - } - else if (Mapping.getBoolButtonMapping(cState.Options)) - { - result = DS4Controls.Options; - } - else if (Mapping.getBoolButtonMapping(cState.PS)) - { - result = DS4Controls.PS; - } - else if (Mapping.getBoolAxisDirMapping(cState.LX, true)) - { - result = DS4Controls.LXPos; - } - else if (Mapping.getBoolAxisDirMapping(cState.LX, false)) - { - result = DS4Controls.LXNeg; - } - else if (Mapping.getBoolAxisDirMapping(cState.LY, true)) - { - result = DS4Controls.LYPos; - } - else if (Mapping.getBoolAxisDirMapping(cState.LY, false)) - { - result = DS4Controls.LYNeg; - } - else if (Mapping.getBoolAxisDirMapping(cState.RX, true)) - { - result = DS4Controls.RXPos; - } - else if (Mapping.getBoolAxisDirMapping(cState.RX, false)) - { - result = DS4Controls.RXNeg; - } - else if (Mapping.getBoolAxisDirMapping(cState.RY, true)) - { - result = DS4Controls.RYPos; - } - else if (Mapping.getBoolAxisDirMapping(cState.RY, false)) - { - result = DS4Controls.RYNeg; - } - else if (Mapping.getBoolTouchMapping(tp.leftDown)) - { - result = DS4Controls.TouchLeft; - } - else if (Mapping.getBoolTouchMapping(tp.rightDown)) - { - result = DS4Controls.TouchRight; - } - else if (Mapping.getBoolTouchMapping(tp.multiDown)) - { - result = DS4Controls.TouchMulti; - } - else if (Mapping.getBoolTouchMapping(tp.upperDown)) - { - result = DS4Controls.TouchUpper; - } - } - - return result; - } - */ - public bool[] touchreleased = { true, true, true, true }, touchslid = { false, false, false, false }; public byte[] oldtouchvalue = { 0, 0, 0, 0 }; public int[] oldscrollvalue = { 0, 0, 0, 0 }; diff --git a/DS4Windows/DS4Control/DS4LightBar.cs b/DS4Windows/DS4Control/DS4LightBar.cs index 74db736..134723e 100644 --- a/DS4Windows/DS4Control/DS4LightBar.cs +++ b/DS4Windows/DS4Control/DS4LightBar.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Drawing; using static System.Math; using static DS4Windows.Global; diff --git a/DS4Windows/DS4Control/ITouchpadBehaviour.cs b/DS4Windows/DS4Control/ITouchpadBehaviour.cs index 24a5ee7..d175391 100644 --- a/DS4Windows/DS4Control/ITouchpadBehaviour.cs +++ b/DS4Windows/DS4Control/ITouchpadBehaviour.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace DS4Windows { diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 3c2db73..ba46cee 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -886,13 +886,15 @@ namespace DS4Windows bool active = getBoolMapping2(device, dcs.control, cState, eState, tp, fieldMapping); if (active) { - resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping); PlayMacro(device, macroControl, string.Join("/", (int[])action), dcs.control, keyType); } else { EndMacro(device, macroControl, string.Join("/", (int[])action), dcs.control); } + + // erase default mappings for things that are remapped + resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping); } else if (actionType == DS4ControlSettings.ActionType.Key) { @@ -900,7 +902,6 @@ namespace DS4Windows ushort value = Convert.ToUInt16(action); if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) { - resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping); SyntheticState.KeyPresses kp; if (!deviceState.keyPresses.TryGetValue(value, out kp)) deviceState.keyPresses[value] = kp = new SyntheticState.KeyPresses(); @@ -923,6 +924,9 @@ namespace DS4Windows } else pressedonce[value] = false; + + // erase default mappings for things that are remapped + resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping); } else if (actionType == DS4ControlSettings.ActionType.Button) { @@ -1096,7 +1100,8 @@ namespace DS4Windows } } - resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping); // erase default mappings for things that are remapped + // erase default mappings for things that are remapped + resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping); } } @@ -3401,6 +3406,8 @@ namespace DS4Windows else if (controlType == DS4StateFieldMapping.ControlType.AxisDir) { fieldMap.axisdirs[controlNum] = 127; + int controlRelation = (controlNum % 2 == 0 ? controlNum - 1 : controlNum + 1); + fieldMap.axisdirs[controlRelation] = 127; } else if (controlType == DS4StateFieldMapping.ControlType.Trigger) { diff --git a/DS4Windows/DS4Control/Mouse.cs b/DS4Windows/DS4Control/Mouse.cs index 4221210..ede773e 100644 --- a/DS4Windows/DS4Control/Mouse.cs +++ b/DS4Windows/DS4Control/Mouse.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Runtime.InteropServices; namespace DS4Windows { diff --git a/DS4Windows/DS4Control/MouseWheel.cs b/DS4Windows/DS4Control/MouseWheel.cs index 5529337..e17ba13 100644 --- a/DS4Windows/DS4Control/MouseWheel.cs +++ b/DS4Windows/DS4Control/MouseWheel.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace DS4Windows { diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 1c9acfe..02dd30e 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace DS4Windows { [Flags] - public enum DS4KeyType : byte { None = 0, ScanCode = 1, Toggle = 2, Unbound = 4, Macro = 8, HoldMacro = 16, RepeatMacro = 32 }; //Increment by exponents of 2*, starting at 2^0 + public enum DS4KeyType : byte { None = 0, ScanCode = 1, Toggle = 2, Unbound = 4, Macro = 8, HoldMacro = 16, RepeatMacro = 32 }; // Increment by exponents of 2*, starting at 2^0 public enum Ds3PadId : byte { None = 0xFF, One = 0x00, Two = 0x01, Three = 0x02, Four = 0x03, All = 0x04 }; public enum DS4Controls : byte { None, LXNeg, LXPos, LYNeg, LYPos, RXNeg, RXPos, RYNeg, RYPos, L1, L2, L3, R1, R2, R3, Square, Triangle, Circle, Cross, DpadUp, DpadRight, DpadDown, DpadLeft, PS, TouchLeft, TouchUpper, TouchMulti, TouchRight, Share, Options, GyroXPos, GyroXNeg, GyroZPos, GyroZNeg, SwipeLeft, SwipeRight, SwipeUp, SwipeDown }; public enum X360Controls : byte { None, LXNeg, LXPos, LYNeg, LYPos, RXNeg, RXPos, RYNeg, RYPos, LB, LT, LS, RB, RT, RS, X, Y, B, A, DpadUp, DpadRight, DpadDown, DpadLeft, Guide, Back, Start, LeftMouse, RightMouse, MiddleMouse, FourthMouse, FifthMouse, WUP, WDOWN, MouseUp, MouseDown, MouseLeft, MouseRight, Unbound }; @@ -231,6 +231,7 @@ namespace DS4Windows X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None }; + // Create mapping array at runtime public static DS4Controls[] reverseX360ButtonMapping = new Func(() => { DS4Controls[] temp = new DS4Controls[defaultButtonMapping.Length]; @@ -252,6 +253,7 @@ namespace DS4Windows m_Config.m_Profile = appdatapath + "\\Profiles.xml"; m_Config.m_Actions = appdatapath + "\\Actions.xml"; } + /// /// Check if Admin Rights are needed to write in Appliplation Directory /// @@ -320,6 +322,7 @@ namespace DS4Windows set { m_Config.useExclusiveMode = value; } get { return m_Config.useExclusiveMode; } } + public static bool getUseExclusiveMode() { return m_Config.useExclusiveMode; @@ -336,83 +339,100 @@ namespace DS4Windows set { m_Config.CheckWhen = value; } get { return m_Config.CheckWhen; } } + public static int Notifications { set { m_Config.notifications = value; } get { return m_Config.notifications; } } + public static bool DCBTatStop { set { m_Config.disconnectBTAtStop = value; } get { return m_Config.disconnectBTAtStop; } } + public static bool SwipeProfiles { set { m_Config.swipeProfiles = value; } get { return m_Config.swipeProfiles; } } + public static bool DS4Mapping { set { m_Config.ds4Mapping = value; } get { return m_Config.ds4Mapping; } } + public static bool QuickCharge { set { m_Config.quickCharge = value; } get { return m_Config.quickCharge; } } + public static bool getQuickCharge() { return m_Config.quickCharge; } + public static int FirstXinputPort { set { m_Config.firstXinputPort = value; } get { return m_Config.firstXinputPort; } } + public static bool CloseMini { set { m_Config.closeMini = value; } get { return m_Config.closeMini; } } + public static bool StartMinimized { set { m_Config.startMinimized = value; } get { return m_Config.startMinimized; } } + public static int FormWidth { set { m_Config.formWidth = value; } get { return m_Config.formWidth;} } + public static int FormHeight { set { m_Config.formHeight = value; } get { return m_Config.formHeight; } } + public static bool DownloadLang { set { m_Config.downloadLang = value; } get { return m_Config.downloadLang; } } + public static bool FlashWhenLate { set { m_Config.flashWhenLate = value; } get { return m_Config.flashWhenLate; } } + public static bool getFlashWhenLate() { return m_Config.flashWhenLate; } + public static int FlashWhenLateAt { set { m_Config.flashWhenLateAt = value; } get { return m_Config.flashWhenLateAt; } } + public static int getFlashWhenLateAt() { return m_Config.flashWhenLateAt; } + public static bool UseWhiteIcon { set { m_Config.useWhiteIcon = value; } @@ -421,40 +441,48 @@ namespace DS4Windows // controller/profile specfic values public static int[] ButtonMouseSensitivity => m_Config.buttonMouseSensitivity; + public static byte[] RumbleBoost => m_Config.rumble; public static byte getRumbleBoost(int index) { return m_Config.rumble[index]; } + public static double[] Rainbow => m_Config.rainbow; public static double getRainbow(int index) { return m_Config.rainbow[index]; } + public static bool[] FlushHIDQueue => m_Config.flushHIDQueue; public static bool getFlushHIDQueue(int index) { return m_Config.flushHIDQueue[index]; } + public static bool[] EnableTouchToggle => m_Config.enableTouchToggle; public static bool getEnableTouchToggle(int index) { return m_Config.enableTouchToggle[index]; } + public static int[] IdleDisconnectTimeout => m_Config.idleDisconnectTimeout; public static int getIdleDisconnectTimeout(int index) { return m_Config.idleDisconnectTimeout[index]; } + public static byte[] TouchSensitivity => m_Config.touchSensitivity; public static byte[] getTouchSensitivity() { return m_Config.touchSensitivity; } + public static byte getTouchSensitivity(int index) { return m_Config.touchSensitivity[index]; } + public static byte[] FlashType => m_Config.flashType; public static byte getFlashType(int index) { @@ -472,51 +500,61 @@ namespace DS4Windows { return m_Config.ledAsBattery[index]; } + public static int[] ChargingType => m_Config.chargingType; public static int getChargingType(int index) { return m_Config.chargingType[index]; } + public static bool[] DinputOnly => m_Config.dinputOnly; public static bool getDInputOnly(int index) { return m_Config.dinputOnly[index]; } - public static bool[] StartTouchpadOff => m_Config.startTouchpadOff; + public static bool[] StartTouchpadOff => m_Config.startTouchpadOff; + public static bool[] UseTPforControls => m_Config.useTPforControls; public static bool getUseTPforControls(int index) { return m_Config.useTPforControls[index]; } + public static bool[] UseSAforMouse => m_Config.useSAforMouse; public static bool isUsingSAforMouse(int index) { return m_Config.useSAforMouse[index]; } + public static string[] SATriggers => m_Config.sATriggers; public static int[] GyroSensitivity => m_Config.gyroSensitivity; public static int[] GyroInvert => m_Config.gyroInvert; + public static DS4Color[] MainColor => m_Config.m_Leds; public static DS4Color getMainColor(int index) { return m_Config.m_Leds[index]; } + public static DS4Color[] LowColor => m_Config.m_LowLeds; public static DS4Color getLowColor(int index) { return m_Config.m_LowLeds[index]; } + public static DS4Color[] ChargingColor => m_Config.m_ChargingLeds; public static DS4Color getChargingColor(int index) { return m_Config.m_ChargingLeds[index]; } + public static DS4Color[] CustomColor => m_Config.m_CustomLeds; public static DS4Color getCustomColor(int index) { return m_Config.m_CustomLeds[index]; } + public static bool[] UseCustomLed => m_Config.useCustomLeds; public static bool getUseCustomLed(int index) { @@ -528,8 +566,10 @@ namespace DS4Windows { return m_Config.m_FlashLeds[index]; } + public static byte[] TapSensitivity => m_Config.tapSensitivity; - public static bool[] DoubleTap => m_Config.doubleTap; + public static bool[] DoubleTap => m_Config.doubleTap; + public static int[] ScrollSensitivity => m_Config.scrollSensitivity; public static int[] getScrollSensitivity() { @@ -548,128 +588,154 @@ namespace DS4Windows { return m_Config.l2Deadzone[index]; } + public static byte[] R2Deadzone => m_Config.r2Deadzone; public static byte getR2Deadzone(int index) { return m_Config.r2Deadzone[index]; } + public static double[] SXDeadzone => m_Config.SXDeadzone; public static double getSXDeadzone(int index) { return m_Config.SXDeadzone[index]; } + public static double[] SZDeadzone => m_Config.SZDeadzone; public static double getSZDeadzone(int index) { return m_Config.SZDeadzone[index]; } + public static int[] LSDeadzone => m_Config.LSDeadzone; public static int getLSDeadzone(int index) { return m_Config.LSDeadzone[index]; } + public static int[] RSDeadzone => m_Config.RSDeadzone; public static int getRSDeadzone(int index) { return m_Config.RSDeadzone[index]; } + public static int[] LSAntiDeadzone => m_Config.LSAntiDeadzone; public static int getLSAntiDeadzone(int index) { return m_Config.LSAntiDeadzone[index]; } + public static int[] RSAntiDeadzone => m_Config.RSAntiDeadzone; public static int getRSAntiDeadzone(int index) { return m_Config.RSAntiDeadzone[index]; } + public static int[] LSMaxzone => m_Config.LSMaxzone; public static int getLSMaxzone(int index) { return m_Config.LSMaxzone[index]; } + public static int[] RSMaxzone => m_Config.RSMaxzone; public static int getRSMaxzone(int index) { return m_Config.RSMaxzone[index]; } + public static int[] L2AntiDeadzone => m_Config.l2AntiDeadzone; public static int getL2AntiDeadzone(int index) { return m_Config.l2AntiDeadzone[index]; } + public static int[] R2AntiDeadzone => m_Config.r2AntiDeadzone; public static int getR2AntiDeadzone(int index) { return m_Config.r2AntiDeadzone[index]; } + public static int[] L2Maxzone => m_Config.l2Maxzone; public static int getL2Maxzone(int index) { return m_Config.l2Maxzone[index]; } + public static int[] R2Maxzone => m_Config.r2Maxzone; public static int getR2Maxzone(int index) { return m_Config.r2Maxzone[index]; } + public static int[] LSCurve => m_Config.lsCurve; public static int getLSCurve(int index) { return m_Config.lsCurve[index]; } + public static int[] RSCurve => m_Config.rsCurve; public static int getRSCurve(int index) { return m_Config.rsCurve[index]; } + public static double[] L2Sens => m_Config.l2Sens; public static double getL2Sens(int index) { return m_Config.l2Sens[index]; } + public static double[] R2Sens => m_Config.r2Sens; public static double getR2Sens(int index) { return m_Config.r2Sens[index]; } + public static double[] SXSens => m_Config.SXSens; public static double getSXSens(int index) { return m_Config.SXSens[index]; } + public static double[] SZSens => m_Config.SZSens; public static double getSZSens(int index) { return m_Config.SZSens[index]; } + public static double[] LSSens => m_Config.LSSens; public static double getLSSens(int index) { return m_Config.LSSens[index]; } + public static double[] RSSens => m_Config.RSSens; public static double getRSSens(int index) { return m_Config.RSSens[index]; } + public static bool[] MouseAccel => m_Config.mouseAccel; public static bool getMouseAccel(int device) { return m_Config.mouseAccel[device]; } + public static string[] LaunchProgram => m_Config.launchProgram; public static string[] ProfilePath => m_Config.profilePath; public static bool[] DistanceProfiles = m_Config.distanceProfiles; + public static List[] ProfileActions => m_Config.profileActions; public static int getProfileActionCount(int index) { return m_Config.profileActionCount[index]; } + public static void calculateProfileActionCount(int index) { m_Config.profileActionCount[index] = m_Config.profileActions[index].Count; } + public static List getProfileActions(int index) { return m_Config.profileActions[index]; @@ -681,6 +747,7 @@ namespace DS4Windows m_Config.containsCustomAction[deviceNum] = m_Config.HasCustomActions(deviceNum); m_Config.containsCustomExtras[deviceNum] = m_Config.HasCustomExtras(deviceNum); } + public static void UpdateDS4Extra(int deviceNum, string buttonName, bool shift, string exts) { m_Config.UpdateDS4CExtra(deviceNum, buttonName, shift, exts); @@ -699,10 +766,12 @@ namespace DS4Windows public static DS4ControlSettings getDS4CSetting(int deviceNum, DS4Controls control) => m_Config.getDS4CSetting(deviceNum, control); public static bool HasCustomActions(int deviceNum) => m_Config.HasCustomActions(deviceNum); public static bool HasCustomExtras(int deviceNum) => m_Config.HasCustomExtras(deviceNum); + public static bool containsCustomAction(int deviceNum) { return m_Config.containsCustomAction[deviceNum]; } + public static bool containsCustomExtras(int deviceNum) { return m_Config.containsCustomExtras[deviceNum]; @@ -744,8 +813,11 @@ namespace DS4Windows public static SpecialAction GetAction(string name) { foreach (SpecialAction sA in m_Config.actions) + { if (sA.name == name) return sA; + } + return new SpecialAction("null", "null", "null", "null"); } @@ -3063,6 +3135,7 @@ namespace DS4Windows public string extra; public bool pressRelease = false; public DS4KeyType keyType; + public SpecialAction(string name, string controls, string type, string details, double delay = 0, string extras = "") { this.name = name; diff --git a/DS4Windows/DS4Forms/KBM360.cs b/DS4Windows/DS4Forms/KBM360.cs index 84203e8..b388460 100644 --- a/DS4Windows/DS4Forms/KBM360.cs +++ b/DS4Windows/DS4Forms/KBM360.cs @@ -1,10 +1,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace DS4Windows @@ -25,7 +21,7 @@ namespace DS4Windows bool loading = true; private int alphacolor; private Color reg, full; - int bgc = 240; //Color of the form background, If greyscale color + int bgc = 240; // Color of the form background, If greyscale color private bool extraChanged; public KBM360(int deviceNum, Options ooo, Button buton) @@ -46,13 +42,22 @@ namespace DS4Windows btnDefault.Text = Properties.Resources.FallBack; } else if (button.Name.StartsWith("bn")) + { Text = Properties.Resources.SelectActionTitle.Replace("*action*", button.Name.Substring(2)); + } + foreach (Control control in Controls) + { if (control is Button) ((Button)control).Click += anybtn_Click; + } + foreach (Control control in pnl360Controls.Controls) + { if (control is Button) ((Button)control).Click += anybtn_Click; + } + if (button.Name.Contains("Touch") || button.Name.Contains("Swipe")) { btnMOUSEDOWN.Visible = false; @@ -60,6 +65,7 @@ namespace DS4Windows btnMOUSERIGHT.Visible = false; btnMOUSEUP.Visible = false; } + ActiveControl = lBMacroOn; guideText = btnGuide.Text; btnGuide.Text = ""; @@ -74,7 +80,9 @@ namespace DS4Windows InitializeComponent(); sA = ooo; button = buton; - Size = new Size(btnVolUp.Location.X + btnVolUp.Size.Width * 2, btnNUMENTER.Location.Y + btnNUMENTER.Size.Height * 2); + Size = new Size(btnVolUp.Location.X + btnVolUp.Size.Width * 2, + btnNUMENTER.Location.Y + btnNUMENTER.Size.Height * 2); + if (extras) { cBScanCode.Checked = button.Text.Contains("(SC)"); @@ -85,13 +93,17 @@ namespace DS4Windows cBScanCode.Visible = false; cBToggle.Visible = false; } + gBExtras.Visible = false; bnMacro.Visible = false; X360Label.Visible = false; Text = Properties.Resources.SelectActionTitle.Replace("*action*", "Trigger"); foreach (Control control in Controls) + { if (control is Button) ((Button)control).Click += anybtn_Click; + } + btnMOUSEDOWN.Visible = false; btnMOUSELEFT.Visible = false; btnMOUSERIGHT.Visible = false; @@ -130,20 +142,21 @@ namespace DS4Windows keyname = "How did you get here?"; } else */ - if (((Button)sender).Tag == null) - keyname = ((Button)sender).Text; - else if (((Button)sender).Tag.ToString().Contains("X360")) - keyname = ((Button)sender).Tag.ToString().Substring(4); - else if (((Button)sender).Tag != null && ushort.TryParse(((Button)sender).Tag.ToString(), out val)) + if (bn.Tag == null) + keyname = bn.Text; + else if (bn.Tag.ToString().Contains("X360")) + keyname = bn.Tag.ToString().Substring(4); + else if (bn.Tag != null && ushort.TryParse(bn.Tag.ToString(), out val)) keyname = ((Keys)val).ToString(); else - keyname = ((Button)sender).Tag.ToString(); + keyname = bn.Tag.ToString(); + object keytag; //ushort val; - if (((Button)sender).Tag != null && ((Button)sender).Tag.ToString().Contains("X360")) + if (bn.Tag != null && bn.Tag.ToString().Contains("X360")) { //keytag = ((Button)sender).Tag.ToString().Substring(4); - keytag = Global.getX360ControlsByName(((Button)sender).Tag.ToString().Substring(4)); + keytag = Global.getX360ControlsByName(bn.Tag.ToString().Substring(4)); DS4Controls psButton = Global.getDS4ControlsByName(button.Name); if ((X360Controls)keytag == Global.getDefaultX360ControlBinding(psButton) && !cBScanCode.Checked && !cBToggle.Checked && !rBShiftModifer.Checked) @@ -152,10 +165,10 @@ namespace DS4Windows keytag = null; } } - else if (((Button)sender).Tag != null && ushort.TryParse(((Button)sender).Tag.ToString(), out val)) + else if (bn.Tag != null && ushort.TryParse(bn.Tag.ToString(), out val)) keytag = val; else - keytag = ((Button)sender).Tag; + keytag = bn.Tag; lBMacroOn.Visible = false; string extras = GetExtras(); @@ -166,13 +179,18 @@ namespace DS4Windows bool scanavail = tagisint; bool toggleavil = tagisint; if (ops != null) - ops.ChangeButtonText(button, rBShiftModifer.Checked, tag, (scanavail ? cBScanCode.Checked : false), (toggleavil ? cBToggle.Checked : false), false, false, cBShiftButton.SelectedIndex); + { + ops.ChangeButtonText(button, rBShiftModifer.Checked, tag, + (scanavail ? cBScanCode.Checked : false), (toggleavil ? cBToggle.Checked : false), + false, false, cBShiftButton.SelectedIndex); + } else if (sA != null) { button.Text = keyname; button.Tag = keytag; button.ForeColor = Color.Black; } + this.Close(); } } @@ -182,6 +200,7 @@ namespace DS4Windows string t =(byte)nUDHeavy.Value + "," + (byte)nUDLight.Value + "," + (cBLightbar.Checked ? "1" + "," + tBRedBar.Value + "," + tBGreenBar.Value + "," + tBBlueBar.Value + "," + nUDLightFlash.Value: "0,0,0,0,0") + "," + (cBMouse.Checked ? "1" + "," + (byte)nUDMouse.Value : "0,0"); + return t; } @@ -243,13 +262,17 @@ namespace DS4Windows KeyValuePair tag = new KeyValuePair(e.KeyValue, extras); newaction = true; if (ops != null) - ops.ChangeButtonText(button, rBShiftModifer.Checked, tag, cBScanCode.Checked, cBToggle.Checked, false, false, cBShiftButton.SelectedIndex); + { + ops.ChangeButtonText(button, rBShiftModifer.Checked, tag, + cBScanCode.Checked, cBToggle.Checked, false, false, cBShiftButton.SelectedIndex); + } else if (sA != null) { button.Text = e.KeyCode.ToString(); button.Tag = e.KeyValue; button.ForeColor = Color.Black; } + this.Close(); } } @@ -263,22 +286,21 @@ namespace DS4Windows KeyValuePair tag = new KeyValuePair(e.KeyValue, extras); newaction = true; if (ops != null) - ops.ChangeButtonText(button, rBShiftModifer.Checked, tag, cBScanCode.Checked, cBToggle.Checked, false, false, cBShiftButton.SelectedIndex); + { + ops.ChangeButtonText(button, rBShiftModifer.Checked, tag, + cBScanCode.Checked, cBToggle.Checked, false, false, cBShiftButton.SelectedIndex); + } else if (sA != null) { button.Text = e.KeyCode.ToString(); button.Tag = e.KeyValue; button.ForeColor = Color.Black; } + this.Close(); } } - private void cbToggle_CheckedChanged(object sender, EventArgs e) - { - - } - private void btnMacro_Click(object sender, EventArgs e) { gBExtras.Controls.Add(cBScanCode); @@ -301,11 +323,14 @@ namespace DS4Windows case Keys.Up: case Keys.Down: return true; - case Keys.Shift | Keys.Right: - case Keys.Shift | Keys.Left: - case Keys.Shift | Keys.Up: - case Keys.Shift | Keys.Down: + + case (Keys.Shift | Keys.Right): + case (Keys.Shift | Keys.Left): + case (Keys.Shift | Keys.Up): + case (Keys.Shift | Keys.Down): return true; + + default: break; } return base.IsInputKey(keyData); } @@ -318,6 +343,7 @@ namespace DS4Windows case Keys.Right: case Keys.Up: case Keys.Down: + { if (e.Shift) { @@ -326,6 +352,8 @@ namespace DS4Windows { } break; + } + default: break; } } @@ -340,6 +368,7 @@ namespace DS4Windows int som = bgc + 11 * (int)(value * 0.0039215); tb.BackColor = Color.FromArgb(tb.Name.ToLower().Contains("red") ? som : sat, tb.Name.ToLower().Contains("green") ? som : sat, tb.Name.ToLower().Contains("blue") ? som : sat); } + alphacolor = Math.Max(tBRedBar.Value, Math.Max(tBGreenBar.Value, tBBlueBar.Value)); reg = Color.FromArgb(tBRedBar.Value, tBGreenBar.Value, tBBlueBar.Value); full = HuetoRGB(reg.GetHue(), reg.GetBrightness(), reg); @@ -378,6 +407,7 @@ namespace DS4Windows tBBlueBar.Value = advColorDialog.Color.B; extraChanged = true; } + if (device < 4) DS4LightBar.forcelight[device] = false; } @@ -416,8 +446,10 @@ namespace DS4Windows if (s[i] >= 'A' && s[i] <= 'Z') s = s.Insert(i, " "); } + if (s == "Guide") s = guideText; + return s; } @@ -431,6 +463,7 @@ namespace DS4Windows { if (!loading && extraChanged) Global.UpdateDS4Extra(device, button.Name, !rBShiftModifer.Checked, GetExtras()); + object tagO = Global.GetDS4Action(device, button.Name, rBShiftModifer.Checked); if (rBShiftModifer.Checked) btnDefault.Text = Properties.Resources.FallBack; @@ -443,8 +476,11 @@ namespace DS4Windows newaction = false; Highlight_Leave(null, null); foreach (Control control in Controls) + { if (control is Button) ((Button)control).BackColor = SystemColors.Control; + } + if (tagO != null) { if (tagO is int || tagO is ushort) @@ -452,19 +488,24 @@ namespace DS4Windows int tag = int.Parse(tagO.ToString()); int i; foreach (Control control in Controls) + { if (control is Button) + { if (int.TryParse(control.Tag?.ToString(), out i) && i == tag) { ((Button)control).BackColor = Color.LightGreen; break; } + } + } } else if (tagO is int[]) { int[] tag = (int[])tagO; - lBMacroOn.Visible = true; - foreach (int i in tag) - macrostag.Add(i); + lBMacroOn.Visible = true; + foreach (int i in tag) + macrostag.Add(i); + if (Global.GetDS4KeyType(device, button.Name, rBShiftModifer.Checked).HasFlag(DS4KeyType.HoldMacro)) macrorepeat = true; } @@ -472,25 +513,33 @@ namespace DS4Windows { string tag; if (tagO is X360Controls) - { tag = getX360ControlsByName((X360Controls)tagO); - } else tag = tagO.ToString(); + foreach (Control control in Controls) + { if (control is Button) + { if (control.Tag?.ToString() == tag) { ((Button)control).BackColor = Color.LightGreen; break; } + } + } + foreach (Control control in pnl360Controls.Controls) + { if (control is Button) + { if (control.Tag?.ToString().Substring(4) == tag) { Hightlight_Hover(((Button)control), null); break; } + } + } } } else @@ -504,22 +553,33 @@ namespace DS4Windows tag = getX360ControlsByName((X360Controls)tagO); else tag = tagO.ToString(); + foreach (Control control in Controls) + { if (control is Button) + { if (control.Tag != null && control.Tag.ToString().Contains("X360") ? control.Tag?.ToString().Substring(4) == tag : control.Tag?.ToString() == tag) { ((Button)control).BackColor = Color.LightGreen; break; } + } + } + foreach (Control control in pnl360Controls.Controls) + { if (control is Button) + { if (control.Tag?.ToString().Substring(4) == tag) { Hightlight_Hover(((Button)control), null); break; } + } + } } } + string dcExtras = Global.GetDS4Extra(device, button.Name, rBShiftModifer.Checked); string[] extras = null; if (!string.IsNullOrEmpty(dcExtras)) @@ -535,6 +595,7 @@ namespace DS4Windows if (int.TryParse(extras[0], out b)) nUDHeavy.Value = b; if (int.TryParse(extras[1], out b)) nUDLight.Value = b; if (int.TryParse(extras[2], out b)) + { if (b == 1) { cBLightbar.Checked = true; @@ -552,7 +613,10 @@ namespace DS4Windows nUDLightFlash.Value = 0; cBLightbar.Checked = false; } + } + if (int.TryParse(extras[7], out b)) + { if (b == 1) { cBMouse.Checked = true; @@ -563,7 +627,7 @@ namespace DS4Windows nUDMouse.Value = 25; cBMouse.Checked = false; } - + } } catch { @@ -627,34 +691,41 @@ namespace DS4Windows case X360Controls.MouseLeft: return "Mouse Left"; case X360Controls.MouseRight: return "Mouse Right"; case X360Controls.Unbound: return "Unbound"; + default: break; } + return "Unbound"; } private void bnTest_Click(object sender, EventArgs e) { + Button btn = (Button)sender; if (device < 4) - if (((Button)sender).Text == Properties.Resources.TestText) + { + if (btn.Text == Properties.Resources.TestText) { Program.rootHub.setRumble((byte)nUDHeavy.Value, (byte)nUDLight.Value, device); - ((Button)sender).Text = Properties.Resources.StopText; + btn.Text = Properties.Resources.StopText; } else { Program.rootHub.setRumble(0, 0, device); - ((Button)sender).Text = Properties.Resources.TestText; + btn.Text = Properties.Resources.TestText; } + } else - if (((Button)sender).Text == Properties.Resources.TestText) + { + if (btn.Text == Properties.Resources.TestText) { Program.rootHub.setRumble((byte)nUDHeavy.Value, (byte)nUDLight.Value, 0); - ((Button)sender).Text = Properties.Resources.StopText; + btn.Text = Properties.Resources.StopText; } else { Program.rootHub.setRumble(0, 0, 0); - ((Button)sender).Text = Properties.Resources.TestText; + btn.Text = Properties.Resources.TestText; } + } } private void ExtraChanged(object sender, EventArgs e) @@ -671,6 +742,7 @@ namespace DS4Windows else Program.rootHub.setRumble((byte)nUDHeavy.Value, (byte)nUDLight.Value, 0); } + extraChanged = true; } diff --git a/DS4Windows/DS4Forms/Options.Designer.cs b/DS4Windows/DS4Forms/Options.Designer.cs index e83efc3..4d5f414 100644 --- a/DS4Windows/DS4Forms/Options.Designer.cs +++ b/DS4Windows/DS4Forms/Options.Designer.cs @@ -266,6 +266,15 @@ this.label2 = new System.Windows.Forms.Label(); this.nUDLSAntiDead = new System.Windows.Forms.NumericUpDown(); this.label1 = new System.Windows.Forms.Label(); + this.maxZoneTabPage = new System.Windows.Forms.TabPage(); + this.nUDR2Maxzone = new System.Windows.Forms.NumericUpDown(); + this.nUDL2Maxzone = new System.Windows.Forms.NumericUpDown(); + this.label8 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.nUDRSMaxZone = new System.Windows.Forms.NumericUpDown(); + this.label6 = new System.Windows.Forms.Label(); + this.nUDLSMaxZone = new System.Windows.Forms.NumericUpDown(); + this.label5 = new System.Windows.Forms.Label(); this.fLPSettings = new System.Windows.Forms.FlowLayoutPanel(); this.gBGyro = new System.Windows.Forms.GroupBox(); this.rBSAControls = new System.Windows.Forms.RadioButton(); @@ -312,15 +321,6 @@ this.shareToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pSToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.alwaysOnToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.maxZoneTabPage = new System.Windows.Forms.TabPage(); - this.label5 = new System.Windows.Forms.Label(); - this.nUDLSMaxZone = new System.Windows.Forms.NumericUpDown(); - this.label6 = new System.Windows.Forms.Label(); - this.nUDRSMaxZone = new System.Windows.Forms.NumericUpDown(); - this.label7 = new System.Windows.Forms.Label(); - this.label8 = new System.Windows.Forms.Label(); - this.nUDL2Maxzone = new System.Windows.Forms.NumericUpDown(); - this.nUDR2Maxzone = new System.Windows.Forms.NumericUpDown(); this.advColorDialog = new DS4Windows.AdvancedColorDialog(); ((System.ComponentModel.ISupportInitialize)(this.nUDRainbow)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tBBlueBar)).BeginInit(); @@ -386,6 +386,11 @@ ((System.ComponentModel.ISupportInitialize)(this.nUDL2AntiDead)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDRSAntiDead)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDLSAntiDead)).BeginInit(); + this.maxZoneTabPage.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nUDR2Maxzone)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).BeginInit(); this.fLPSettings.SuspendLayout(); this.gBGyro.SuspendLayout(); this.pnlSAMouse.SuspendLayout(); @@ -398,11 +403,6 @@ ((System.ComponentModel.ISupportInitialize)(this.nUDSXS)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDSZS)).BeginInit(); this.cMGyroTriggers.SuspendLayout(); - this.maxZoneTabPage.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.nUDR2Maxzone)).BeginInit(); this.SuspendLayout(); // // lowColorChooserButton @@ -2759,6 +2759,128 @@ resources.ApplyResources(this.label1, "label1"); this.label1.Name = "label1"; // + // maxZoneTabPage + // + this.maxZoneTabPage.Controls.Add(this.nUDR2Maxzone); + this.maxZoneTabPage.Controls.Add(this.nUDL2Maxzone); + this.maxZoneTabPage.Controls.Add(this.label8); + this.maxZoneTabPage.Controls.Add(this.label7); + this.maxZoneTabPage.Controls.Add(this.nUDRSMaxZone); + this.maxZoneTabPage.Controls.Add(this.label6); + this.maxZoneTabPage.Controls.Add(this.nUDLSMaxZone); + this.maxZoneTabPage.Controls.Add(this.label5); + resources.ApplyResources(this.maxZoneTabPage, "maxZoneTabPage"); + this.maxZoneTabPage.Name = "maxZoneTabPage"; + this.maxZoneTabPage.UseVisualStyleBackColor = true; + // + // nUDR2Maxzone + // + this.nUDR2Maxzone.DecimalPlaces = 2; + this.nUDR2Maxzone.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + resources.ApplyResources(this.nUDR2Maxzone, "nUDR2Maxzone"); + this.nUDR2Maxzone.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nUDR2Maxzone.Name = "nUDR2Maxzone"; + this.nUDR2Maxzone.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nUDR2Maxzone.ValueChanged += new System.EventHandler(this.nUDR2Maxzone_ValueChanged); + // + // nUDL2Maxzone + // + this.nUDL2Maxzone.DecimalPlaces = 2; + this.nUDL2Maxzone.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + resources.ApplyResources(this.nUDL2Maxzone, "nUDL2Maxzone"); + this.nUDL2Maxzone.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nUDL2Maxzone.Name = "nUDL2Maxzone"; + this.nUDL2Maxzone.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nUDL2Maxzone.ValueChanged += new System.EventHandler(this.nUDL2Maxzone_ValueChanged); + // + // label8 + // + resources.ApplyResources(this.label8, "label8"); + this.label8.Name = "label8"; + // + // label7 + // + resources.ApplyResources(this.label7, "label7"); + this.label7.Name = "label7"; + // + // nUDRSMaxZone + // + this.nUDRSMaxZone.DecimalPlaces = 2; + this.nUDRSMaxZone.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + resources.ApplyResources(this.nUDRSMaxZone, "nUDRSMaxZone"); + this.nUDRSMaxZone.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nUDRSMaxZone.Name = "nUDRSMaxZone"; + this.nUDRSMaxZone.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nUDRSMaxZone.ValueChanged += new System.EventHandler(this.nUDRSMaxZone_ValueChanged); + // + // label6 + // + resources.ApplyResources(this.label6, "label6"); + this.label6.Name = "label6"; + // + // nUDLSMaxZone + // + this.nUDLSMaxZone.DecimalPlaces = 2; + this.nUDLSMaxZone.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + resources.ApplyResources(this.nUDLSMaxZone, "nUDLSMaxZone"); + this.nUDLSMaxZone.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nUDLSMaxZone.Name = "nUDLSMaxZone"; + this.nUDLSMaxZone.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.nUDLSMaxZone.ValueChanged += new System.EventHandler(this.nUDLSMaxZone_ValueChanged); + // + // label5 + // + resources.ApplyResources(this.label5, "label5"); + this.label5.Name = "label5"; + // // fLPSettings // resources.ApplyResources(this.fLPSettings, "fLPSettings"); @@ -3262,128 +3384,6 @@ resources.ApplyResources(this.alwaysOnToolStripMenuItem, "alwaysOnToolStripMenuItem"); this.alwaysOnToolStripMenuItem.CheckedChanged += new System.EventHandler(this.SATrigger_CheckedChanged); // - // maxZoneTabPage - // - this.maxZoneTabPage.Controls.Add(this.nUDR2Maxzone); - this.maxZoneTabPage.Controls.Add(this.nUDL2Maxzone); - this.maxZoneTabPage.Controls.Add(this.label8); - this.maxZoneTabPage.Controls.Add(this.label7); - this.maxZoneTabPage.Controls.Add(this.nUDRSMaxZone); - this.maxZoneTabPage.Controls.Add(this.label6); - this.maxZoneTabPage.Controls.Add(this.nUDLSMaxZone); - this.maxZoneTabPage.Controls.Add(this.label5); - resources.ApplyResources(this.maxZoneTabPage, "maxZoneTabPage"); - this.maxZoneTabPage.Name = "maxZoneTabPage"; - this.maxZoneTabPage.UseVisualStyleBackColor = true; - // - // label5 - // - resources.ApplyResources(this.label5, "label5"); - this.label5.Name = "label5"; - // - // nUDLSMaxZone - // - this.nUDLSMaxZone.DecimalPlaces = 2; - this.nUDLSMaxZone.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - resources.ApplyResources(this.nUDLSMaxZone, "nUDLSMaxZone"); - this.nUDLSMaxZone.Maximum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.nUDLSMaxZone.Name = "nUDLSMaxZone"; - this.nUDLSMaxZone.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.nUDLSMaxZone.ValueChanged += new System.EventHandler(this.nUDLSMaxZone_ValueChanged); - // - // label6 - // - resources.ApplyResources(this.label6, "label6"); - this.label6.Name = "label6"; - // - // nUDRSMaxZone - // - this.nUDRSMaxZone.DecimalPlaces = 2; - this.nUDRSMaxZone.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - resources.ApplyResources(this.nUDRSMaxZone, "nUDRSMaxZone"); - this.nUDRSMaxZone.Maximum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.nUDRSMaxZone.Name = "nUDRSMaxZone"; - this.nUDRSMaxZone.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.nUDRSMaxZone.ValueChanged += new System.EventHandler(this.nUDRSMaxZone_ValueChanged); - // - // label7 - // - resources.ApplyResources(this.label7, "label7"); - this.label7.Name = "label7"; - // - // label8 - // - resources.ApplyResources(this.label8, "label8"); - this.label8.Name = "label8"; - // - // nUDL2Maxzone - // - this.nUDL2Maxzone.DecimalPlaces = 2; - this.nUDL2Maxzone.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - resources.ApplyResources(this.nUDL2Maxzone, "nUDL2Maxzone"); - this.nUDL2Maxzone.Maximum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.nUDL2Maxzone.Name = "nUDL2Maxzone"; - this.nUDL2Maxzone.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.nUDL2Maxzone.ValueChanged += new System.EventHandler(this.nUDL2Maxzone_ValueChanged); - // - // nUDR2Maxzone - // - this.nUDR2Maxzone.DecimalPlaces = 2; - this.nUDR2Maxzone.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - resources.ApplyResources(this.nUDR2Maxzone, "nUDR2Maxzone"); - this.nUDR2Maxzone.Maximum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.nUDR2Maxzone.Name = "nUDR2Maxzone"; - this.nUDR2Maxzone.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.nUDR2Maxzone.ValueChanged += new System.EventHandler(this.nUDR2Maxzone_ValueChanged); - // // Options // resources.ApplyResources(this, "$this"); @@ -3395,7 +3395,6 @@ this.MinimizeBox = false; this.Name = "Options"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Options_FormClosing); - this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Options_Closed); this.Resize += new System.EventHandler(this.Options_Resize); ((System.ComponentModel.ISupportInitialize)(this.nUDRainbow)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.tBBlueBar)).EndInit(); @@ -3473,6 +3472,12 @@ ((System.ComponentModel.ISupportInitialize)(this.nUDL2AntiDead)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDRSAntiDead)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDLSAntiDead)).EndInit(); + this.maxZoneTabPage.ResumeLayout(false); + this.maxZoneTabPage.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nUDR2Maxzone)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).EndInit(); this.fLPSettings.ResumeLayout(false); this.gBGyro.ResumeLayout(false); this.gBGyro.PerformLayout(); @@ -3488,12 +3493,6 @@ ((System.ComponentModel.ISupportInitialize)(this.nUDSXS)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDSZS)).EndInit(); this.cMGyroTriggers.ResumeLayout(false); - this.maxZoneTabPage.ResumeLayout(false); - this.maxZoneTabPage.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.nUDR2Maxzone)).EndInit(); this.ResumeLayout(false); } diff --git a/DS4Windows/DS4Forms/Options.cs b/DS4Windows/DS4Forms/Options.cs index 1e1439a..60db84c 100644 --- a/DS4Windows/DS4Forms/Options.cs +++ b/DS4Windows/DS4Forms/Options.cs @@ -1690,22 +1690,6 @@ namespace DS4Windows e.Cancel = true; } - private void Options_Closed(object sender, FormClosedEventArgs e) - { - /*for (int i = 0; i < 4; i++) - LoadProfile(i, false, Program.rootHub); //Refreshes all profiles in case other controllers are using the same profile - if (olddinputcheck != cBDinput.Checked) - { - root.btnStartStop_Clicked(false); - root.btnStartStop_Clicked(false); - } - if (btnRumbleHeavyTest.Text == Properties.Resources.StopText) - Program.rootHub.setRumble(0, 0, (int)nUDSixaxis.Value - 1); - inputtimer.Stop(); - sixaxisTimer.Stop();*/ - //e.c - } - private void cBSlide_CheckedChanged(object sender, EventArgs e) { bool slideChecked = cBSlide.Checked; diff --git a/DS4Windows/DS4Forms/Options.resx b/DS4Windows/DS4Forms/Options.resx index 6c9bff1..bd88953 100644 --- a/DS4Windows/DS4Forms/Options.resx +++ b/DS4Windows/DS4Forms/Options.resx @@ -7778,7 +7778,7 @@ with profile advColorDialog - DS4Windows.AdvancedColorDialog, DS4Windows, Version=1.4.67.0, Culture=neutral, PublicKeyToken=null + DS4Windows.AdvancedColorDialog, DS4Windows, Version=1.4.69.0, Culture=neutral, PublicKeyToken=null Options diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index c04aeb7..bea8b97 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -4,15 +4,9 @@ using System.ComponentModel; using System.Threading; using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; using System.Diagnostics; -using System.Threading.Tasks; - using System.Linq; -using System.Text; -using System.IO; -using System.Collections; using System.Drawing; using DS4Windows.DS4Library; @@ -23,7 +17,7 @@ namespace DS4Windows public byte red; public byte green; public byte blue; - public DS4Color(System.Drawing.Color c) + public DS4Color(Color c) { red = c.R; green = c.G; @@ -508,7 +502,8 @@ namespace DS4Windows int thisError = Marshal.GetLastWin32Error(); if (lastError != thisError) { - Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered write failure: " + thisError); + Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered write failure: " + thisError); + Log.LogToGui(Mac.ToString() + " encountered write failure: " + thisError, true); lastError = thisError; } } @@ -579,7 +574,18 @@ namespace DS4Windows } else { - Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + Marshal.GetLastWin32Error()); + + if (res == HidDevice.ReadStatus.WaitTimedOut) + { + Log.LogToGui(Mac.ToString() + " disconnected due to timeout", true); + } + else + { + int winError = Marshal.GetLastWin32Error(); + Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError); + Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true); + } + sendOutputReport(true); // Kick Windows into noticing the disconnection. StopOutputUpdate(); isDisconnecting = true; @@ -588,10 +594,6 @@ namespace DS4Windows Removal?.Invoke(this, EventArgs.Empty); }), null); - /* - if (Removal != null) - Removal(this, EventArgs.Empty); - */ return; } @@ -603,7 +605,17 @@ namespace DS4Windows HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT); if (res != HidDevice.ReadStatus.Success) { - Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + Marshal.GetLastWin32Error()); + if (res == HidDevice.ReadStatus.WaitTimedOut) + { + Log.LogToGui(Mac.ToString() + " disconnected due to timeout", true); + } + else + { + int winError = Marshal.GetLastWin32Error(); + Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError); + Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true); + } + StopOutputUpdate(); isDisconnecting = true; uiContext.Send(new SendOrPostCallback(delegate (object state4) @@ -611,8 +623,6 @@ namespace DS4Windows Removal?.Invoke(this, EventArgs.Empty); }), null); - //if (Removal != null) - // Removal(this, EventArgs.Empty); return; } else @@ -756,6 +766,8 @@ namespace DS4Windows if (shouldDisconnect) { + Log.LogToGui(Mac.ToString() + " disconnecting due to idle disconnect", false); + if (conType == ConnectionType.BT) { if (DisconnectBT(true)) @@ -843,7 +855,9 @@ namespace DS4Windows { if (!writeOutput()) { - Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered synchronous write failure: " + Marshal.GetLastWin32Error()); + int winError = Marshal.GetLastWin32Error(); + Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered synchronous write failure: " + winError); + Log.LogToGui(Mac.ToString() + " encountered synchronous write failure: " + winError, true); quitOutputThread = true; } } @@ -927,8 +941,6 @@ namespace DS4Windows { Removal?.Invoke(this, EventArgs.Empty); }), null); - - //Removal?.Invoke(this, EventArgs.Empty); } } @@ -960,11 +972,6 @@ namespace DS4Windows { Removal?.Invoke(this, EventArgs.Empty); }), null); - - /* - if (Removal != null) - Removal(this, EventArgs.Empty); - */ } else if (result && !remove) { diff --git a/DS4Windows/DS4Windows.csproj b/DS4Windows/DS4Windows.csproj index 07dfdc7..eb4c434 100644 --- a/DS4Windows/DS4Windows.csproj +++ b/DS4Windows/DS4Windows.csproj @@ -99,7 +99,7 @@ - + diff --git a/DS4Windows/HidLibrary/HidDevice.cs b/DS4Windows/HidLibrary/HidDevice.cs index 536a89f..d2e8e33 100644 --- a/DS4Windows/HidLibrary/HidDevice.cs +++ b/DS4Windows/HidLibrary/HidDevice.cs @@ -304,14 +304,21 @@ namespace DS4Windows if (!safeReadHandle.IsInvalid && fileStream.CanRead) { Task readTask = fileStream.ReadAsync(inputBuffer, 0, inputBuffer.Length); - readTask.Wait(timeout); - if (readTask.Result > 0) + bool success = readTask.Wait(timeout); + if (success) { - return ReadStatus.Success; + if (readTask.Result > 0) + { + return ReadStatus.Success; + } + else + { + return ReadStatus.NoDataRead; + } } else { - return ReadStatus.NoDataRead; + return ReadStatus.WaitTimedOut; } }