diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 8bdb234..ae3c141 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -153,13 +153,13 @@ namespace DS4Windows device.Report += this.On_Report; TouchPadOn(i, device); - device.setIdleTimeout(getIdleDisconnectTimeout(i)); + CheckProfileOptions(i, device, true); device.StartUpdate(); //string filename = ProfilePath[ind]; //ind++; if (showlog) { - if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml")) + if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml")) { string prolog = Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", ProfilePath[i]); LogDebug(prolog); @@ -343,12 +343,11 @@ namespace DS4Windows } TouchPadOn(Index, device); - device.setIdleTimeout(getIdleDisconnectTimeout(Index)); CheckProfileOptions(Index, device); device.StartUpdate(); //string filename = Path.GetFileName(ProfilePath[Index]); - if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml")) + if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml")) { string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]); LogDebug(prolog); @@ -370,7 +369,18 @@ namespace DS4Windows return true; } - private void CheckProfileOptions(int ind, DS4Device device) + private void CheckProfileOptions(int ind, DS4Device device, bool startUp=false) + { + device.setIdleTimeout(getIdleDisconnectTimeout(ind)); + device.setBTPollRate(getBTPollRate(ind)); + + if (!startUp) + { + CheckLauchProfileOption(ind, device); + } + } + + private void CheckLauchProfileOption(int ind, DS4Device device) { string programPath = LaunchProgram[ind]; if (programPath != string.Empty) diff --git a/DS4Windows/DS4Control/DS4LightBar.cs b/DS4Windows/DS4Control/DS4LightBar.cs index 134723e..415a099 100644 --- a/DS4Windows/DS4Control/DS4LightBar.cs +++ b/DS4Windows/DS4Control/DS4LightBar.cs @@ -34,11 +34,6 @@ namespace DS4Windows public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState, DS4StateExposed eState, Mouse tp) { - /* - * TODO: Remove more property usage and use explicit getter methods instead. - * Testing in proper optimized release builds shows that it is - * still necessary to reduce lag. - */ DS4Color color; if (!defaultLight && !forcelight[deviceNum]) { diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index ba46cee..71a14aa 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -1890,6 +1890,7 @@ namespace DS4Windows } } } + untriggeraction[device] = null; LoadProfile(device, false, ctrl); } diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 02dd30e..83a4ec7 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -721,6 +721,12 @@ namespace DS4Windows return m_Config.mouseAccel[device]; } + public static int[] BTPollRate => m_Config.btPollRate; + public static int getBTPollRate(int index) + { + return m_Config.btPollRate[index]; + } + public static string[] LaunchProgram => m_Config.launchProgram; public static string[] ProfilePath => m_Config.profilePath; public static bool[] DistanceProfiles = m_Config.distanceProfiles; @@ -1047,6 +1053,7 @@ namespace DS4Windows public double[] rainbow = { 0, 0, 0, 0, 0 }; public int[] flashAt = { 0, 0, 0, 0, 0 }; public bool[] mouseAccel = { true, true, true, true, true }; + public int[] btPollRate = { 0, 0, 0, 0, 0 }; public DS4Color[] m_LowLeds = new DS4Color[] { new DS4Color(Color.Black), @@ -1317,6 +1324,7 @@ namespace DS4Windows XmlNode xmlLSC = m_Xdoc.CreateNode(XmlNodeType.Element, "LSCurve", null); xmlLSC.InnerText = lsCurve[device].ToString(); Node.AppendChild(xmlLSC); XmlNode xmlRSC = m_Xdoc.CreateNode(XmlNodeType.Element, "RSCurve", null); xmlRSC.InnerText = rsCurve[device].ToString(); Node.AppendChild(xmlRSC); XmlNode xmlProfileActions = m_Xdoc.CreateNode(XmlNodeType.Element, "ProfileActions", null); xmlProfileActions.InnerText = string.Join("/", profileActions[device]); Node.AppendChild(xmlProfileActions); + XmlNode xmlBTPollRate = m_Xdoc.CreateNode(XmlNodeType.Element, "BTPollRate", null); xmlBTPollRate.InnerText = btPollRate[device].ToString(); Node.AppendChild(xmlBTPollRate); XmlNode NodeControl = m_Xdoc.CreateNode(XmlNodeType.Element, "Control", null); XmlNode Key = m_Xdoc.CreateNode(XmlNodeType.Element, "Key", null); @@ -1823,7 +1831,9 @@ namespace DS4Windows return "Unbound"; } - public Boolean LoadProfile(int device, bool launchprogram, ControlService control, string propath = "", bool xinputChange = true) + /* TODO: Explicitly reset profile values back to default before loading new profile. */ + public bool LoadProfile(int device, bool launchprogram, ControlService control, + string propath = "", bool xinputChange = true) { Boolean Loaded = true; Dictionary customMapKeyTypes = new Dictionary(); @@ -1854,11 +1864,13 @@ namespace DS4Windows rootname = "ScpControl"; missingSetting = true; } + if (device < 4) { DS4LightBar.forcelight[device] = false; DS4LightBar.forcedFlash[device] = 0; } + try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/flushHIDQueue"); Boolean.TryParse(Item.InnerText, out flushHIDQueue[device]); } catch { missingSetting = true; }//rootname = } @@ -1915,6 +1927,7 @@ namespace DS4Windows colors = Item.InnerText.Split(','); else colors = new string[0]; + m_LowLeds[device].red = byte.Parse(colors[0]); m_LowLeds[device].green = byte.Parse(colors[1]); m_LowLeds[device].blue = byte.Parse(colors[2]); @@ -1923,11 +1936,11 @@ namespace DS4Windows if (m_Xdoc.SelectSingleNode("/" + rootname + "/LowColor") == null) { //Old method of color saving - try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LowRed"); Byte.TryParse(Item.InnerText, out m_LowLeds[device].red); } + try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LowRed"); byte.TryParse(Item.InnerText, out m_LowLeds[device].red); } catch { missingSetting = true; } - try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LowGreen"); Byte.TryParse(Item.InnerText, out m_LowLeds[device].green); } + try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LowGreen"); byte.TryParse(Item.InnerText, out m_LowLeds[device].green); } catch { missingSetting = true; } - try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LowBlue"); Byte.TryParse(Item.InnerText, out m_LowLeds[device].blue); } + try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LowBlue"); byte.TryParse(Item.InnerText, out m_LowLeds[device].blue); } catch { missingSetting = true; } } //New method for saving color @@ -1982,45 +1995,45 @@ namespace DS4Windows try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/RightTriggerMiddle"); byte.TryParse(Item.InnerText, out r2Deadzone[device]); } catch { missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/L2AntiDeadZone"); int.TryParse(Item.InnerText, out l2AntiDeadzone[device]); } - catch { missingSetting = true; } + catch { l2AntiDeadzone[device] = 0; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/R2AntiDeadZone"); int.TryParse(Item.InnerText, out r2AntiDeadzone[device]); } - catch { missingSetting = true; } + catch { r2AntiDeadzone[device] = 0; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/L2MaxZone"); int temp = 100; int.TryParse(Item.InnerText, out temp); l2Maxzone[device] = Math.Min(Math.Max(temp, 0), 100); } - catch { missingSetting = true; } + catch { l2Maxzone[device] = 100; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/R2MaxZone"); int temp = 100; int.TryParse(Item.InnerText, out temp); r2Maxzone[device] = Math.Min(Math.Max(temp, 0), 100); } - catch { missingSetting = true; } + catch { r2Maxzone[device] = 100; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/ButtonMouseSensitivity"); int.TryParse(Item.InnerText, out buttonMouseSensitivity[device]); } catch { missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/Rainbow"); double.TryParse(Item.InnerText, out rainbow[device]); } catch { rainbow[device] = 0; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LSDeadZone"); int.TryParse(Item.InnerText, out LSDeadzone[device]); } - catch { missingSetting = true; } + catch { LSDeadzone[device] = 0; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/RSDeadZone"); int.TryParse(Item.InnerText, out RSDeadzone[device]); } - catch { missingSetting = true; } + catch { RSDeadzone[device] = 0; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LSAntiDeadZone"); int.TryParse(Item.InnerText, out LSAntiDeadzone[device]); } - catch { missingSetting = true; } + catch { LSAntiDeadzone[device] = 0; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/RSAntiDeadZone"); int.TryParse(Item.InnerText, out RSAntiDeadzone[device]); } - catch { missingSetting = true; } + catch { RSAntiDeadzone[device] = 0; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LSMaxZone"); int temp = 100; int.TryParse(Item.InnerText, out temp); LSMaxzone[device] = Math.Min(Math.Max(temp, 0), 100); } - catch { missingSetting = true; } + catch { LSMaxzone[device] = 100; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/RSMaxZone"); int temp = 100; int.TryParse(Item.InnerText, out temp); RSMaxzone[device] = Math.Min(Math.Max(temp, 0), 100); } - catch { missingSetting = true; } + catch { RSMaxzone[device] = 100; missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/SXDeadZone"); double.TryParse(Item.InnerText, out SXDeadzone[device]); } catch { missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/SZDeadZone"); double.TryParse(Item.InnerText, out SZDeadzone[device]); } @@ -2049,6 +2062,7 @@ namespace DS4Windows catch { missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/MouseAcceleration"); bool.TryParse(Item.InnerText, out mouseAccel[device]); } catch { missingSetting = true; } + int shiftM = 0; if (m_Xdoc.SelectSingleNode("/" + rootname + "/ShiftModifier") != null) int.TryParse(m_Xdoc.SelectSingleNode("/" + rootname + "/ShiftModifier").InnerText, out shiftM); @@ -2101,54 +2115,60 @@ namespace DS4Windows Item = m_Xdoc.SelectSingleNode("/" + rootname + "/DinputOnly"); bool.TryParse(Item.InnerText, out dinputOnly[device]); } - catch { missingSetting = true; } + catch { dinputOnly[device] = false; missingSetting = true; } + bool oldUseDInputOnly = Global.useDInputOnly[device]; Global.useDInputOnly[device] = dinputOnly[device]; // Only change xinput devices under certain conditions. Avoid // performing this upon program startup before loading devices. if (xinputChange) { - bool changed = false; if (device < 4) { + //bool changed = false; DS4Device tempDevice = control.DS4Controllers[device]; - if (dinputOnly[device] == true) + + if (dinputOnly[device] != oldUseDInputOnly) { - bool xinputResult = control.x360Bus.Unplug(device); - if (xinputResult) + if (dinputOnly[device] == true) { - int xinputIndex = control.x360Bus.FirstController + device; - Log.LogToGui("X360 Controller # " + xinputIndex + " unplugged", false); - Global.useDInputOnly[device] = false; + bool xinputResult = control.x360Bus.Unplug(device); + if (xinputResult) + { + int xinputIndex = control.x360Bus.FirstController + device; + Log.LogToGui("X360 Controller # " + xinputIndex + " unplugged", false); + Global.useDInputOnly[device] = true; + } + + //changed = true; + } + else if (tempDevice != null && tempDevice.IsAlive()) + { + bool xinputResult = control.x360Bus.Plugin(device); + if (xinputResult) + { + int xinputIndex = control.x360Bus.FirstController + device; + Log.LogToGui("X360 Controller # " + xinputIndex + " connected", false); + Global.useDInputOnly[device] = false; + } + + //changed = true; } - changed = true; - } - else if (tempDevice != null && tempDevice.IsAlive()) - { - bool xinputResult = control.x360Bus.Plugin(device); - if (xinputResult) + /*if (changed) { - int xinputIndex = control.x360Bus.FirstController + device; - Log.LogToGui("X360 Controller # " + xinputIndex + " connected", false); - Global.useDInputOnly[device] = true; + System.Threading.Thread.Sleep(Global.XINPUT_UNPLUG_SETTLE_TIME); } - - changed = true; + */ } } - - if (changed) - { - System.Threading.Thread.Sleep(Global.XINPUT_UNPLUG_SETTLE_TIME); - } } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/StartTouchpadOff"); - Boolean.TryParse(Item.InnerText, out startTouchpadOff[device]); + bool.TryParse(Item.InnerText, out startTouchpadOff[device]); if (startTouchpadOff[device] == true) control.StartTPOff(device); } catch { startTouchpadOff[device] = false; missingSetting = true; } @@ -2171,6 +2191,14 @@ namespace DS4Windows catch { missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/RSCurve"); int.TryParse(Item.InnerText, out rsCurve[device]); } catch { missingSetting = true; } + try { + Item = m_Xdoc.SelectSingleNode("/" + rootname + "/BTPollRate"); + int temp = 0; + int.TryParse(Item.InnerText, out temp); + btPollRate[device] = (temp >= 0 && temp <= 16) ? temp : 0; + } + catch { btPollRate[device] = 0; missingSetting = true; } + try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/ProfileActions"); @@ -2373,12 +2401,29 @@ namespace DS4Windows this.shiftCustomMapMacros[device] = shiftCustomMapMacros; this.shiftCustomMapExtras[device] = shiftCustomMapExtras; }*/ + // Only add missing settings if the actual load was graceful if (missingSetting && Loaded)// && buttons != null) SaveProfile(device, profilepath); containsCustomAction[device] = HasCustomActions(device); containsCustomExtras[device] = HasCustomExtras(device); + + // If a device exists, make sure to transfer relevant profile device + // options to device instance + if (device < 4) + { + DS4Device tempDev = control.DS4Controllers[device]; + if (tempDev != null) + { + tempDev.queueEvent(() => + { + tempDev.setIdleTimeout(idleDisconnectTimeout[device]); + tempDev.setBTPollRate(btPollRate[device]); + }); + } + } + return Loaded; } diff --git a/DS4Windows/DS4Forms/Options.Designer.cs b/DS4Windows/DS4Forms/Options.Designer.cs index 4d5f414..4b31b35 100644 --- a/DS4Windows/DS4Forms/Options.Designer.cs +++ b/DS4Windows/DS4Forms/Options.Designer.cs @@ -114,6 +114,8 @@ this.bnSwipeRight = new System.Windows.Forms.Button(); this.lbSwipeRight = new System.Windows.Forms.Label(); this.gBOther = new System.Windows.Forms.GroupBox(); + this.btPollRateLabel = new System.Windows.Forms.Label(); + this.btPollRateComboBox = new System.Windows.Forms.ComboBox(); this.enableTouchToggleCheckbox = new System.Windows.Forms.CheckBox(); this.cBDinput = new System.Windows.Forms.CheckBox(); this.pBProgram = new System.Windows.Forms.PictureBox(); @@ -1162,6 +1164,8 @@ // gBOther // this.gBOther.BackColor = System.Drawing.Color.WhiteSmoke; + this.gBOther.Controls.Add(this.btPollRateLabel); + this.gBOther.Controls.Add(this.btPollRateComboBox); this.gBOther.Controls.Add(this.enableTouchToggleCheckbox); this.gBOther.Controls.Add(this.cBDinput); this.gBOther.Controls.Add(this.pBProgram); @@ -1181,6 +1185,38 @@ this.gBOther.Name = "gBOther"; this.gBOther.TabStop = false; // + // btPollRateLabel + // + resources.ApplyResources(this.btPollRateLabel, "btPollRateLabel"); + this.btPollRateLabel.Name = "btPollRateLabel"; + // + // btPollRateComboBox + // + this.btPollRateComboBox.BackColor = System.Drawing.SystemColors.Window; + this.btPollRateComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.btPollRateComboBox.FormattingEnabled = true; + this.btPollRateComboBox.Items.AddRange(new object[] { + resources.GetString("btPollRateComboBox.Items"), + resources.GetString("btPollRateComboBox.Items1"), + resources.GetString("btPollRateComboBox.Items2"), + resources.GetString("btPollRateComboBox.Items3"), + resources.GetString("btPollRateComboBox.Items4"), + resources.GetString("btPollRateComboBox.Items5"), + resources.GetString("btPollRateComboBox.Items6"), + resources.GetString("btPollRateComboBox.Items7"), + resources.GetString("btPollRateComboBox.Items8"), + resources.GetString("btPollRateComboBox.Items9"), + resources.GetString("btPollRateComboBox.Items10"), + resources.GetString("btPollRateComboBox.Items11"), + resources.GetString("btPollRateComboBox.Items12"), + resources.GetString("btPollRateComboBox.Items13"), + resources.GetString("btPollRateComboBox.Items14"), + resources.GetString("btPollRateComboBox.Items15"), + resources.GetString("btPollRateComboBox.Items16")}); + resources.ApplyResources(this.btPollRateComboBox, "btPollRateComboBox"); + this.btPollRateComboBox.Name = "btPollRateComboBox"; + this.btPollRateComboBox.SelectedIndexChanged += new System.EventHandler(this.btPollRateComboBox_SelectedIndexChanged); + // // enableTouchToggleCheckbox // resources.ApplyResources(this.enableTouchToggleCheckbox, "enableTouchToggleCheckbox"); @@ -3793,5 +3829,7 @@ private System.Windows.Forms.NumericUpDown nUDL2Maxzone; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label btPollRateLabel; + private System.Windows.Forms.ComboBox btPollRateComboBox; } } \ No newline at end of file diff --git a/DS4Windows/DS4Forms/Options.cs b/DS4Windows/DS4Forms/Options.cs index 7b1a345..d6fc561 100644 --- a/DS4Windows/DS4Forms/Options.cs +++ b/DS4Windows/DS4Forms/Options.cs @@ -82,19 +82,19 @@ namespace DS4Windows b.Text = ""; } - foreach (System.Windows.Forms.Control control in Controls) + foreach (Control control in Controls) { if (control.HasChildren) { - foreach (System.Windows.Forms.Control ctrl in control.Controls) + foreach (Control ctrl in control.Controls) { if (ctrl.HasChildren) { - foreach (System.Windows.Forms.Control ctrl2 in ctrl.Controls) + foreach (Control ctrl2 in ctrl.Controls) { if (ctrl2.HasChildren) { - foreach (System.Windows.Forms.Control ctrl3 in ctrl2.Controls) + foreach (Control ctrl3 in ctrl2.Controls) ctrl3.MouseHover += Items_MouseHover; } @@ -313,10 +313,11 @@ namespace DS4Windows DS4Color cColor = ChargingColor[device]; btnChargingColor.BackColor = Color.FromArgb(cColor.red, cColor.green, cColor.blue); - if (FlashType[device] > cBFlashType.Items.Count - 1) + byte tempFlashType = FlashType[device]; + if (tempFlashType > cBFlashType.Items.Count - 1) cBFlashType.SelectedIndex = 0; else - cBFlashType.SelectedIndex = FlashType[device]; + cBFlashType.SelectedIndex = tempFlashType; DS4Color fColor = FlashColor[device]; if (fColor.Equals(new DS4Color { red = 0, green = 0, blue = 0 })) @@ -352,10 +353,13 @@ namespace DS4Windows full = HuetoRGB(reg.GetHue(), reg.GetBrightness(), reg); lowColorChooserButton.BackColor = Color.FromArgb((alphacolor > 205 ? 255 : (alphacolor + 50)), full); nUDRainbow.Value = (decimal)Rainbow[device]; - if (ChargingType[device] > cBWhileCharging.Items.Count - 1) + int tempWhileCharging = ChargingType[device]; + if (tempWhileCharging > cBWhileCharging.Items.Count - 1) cBWhileCharging.SelectedIndex = 0; else - cBWhileCharging.SelectedIndex = ChargingType[device]; + cBWhileCharging.SelectedIndex = tempWhileCharging; + + btPollRateComboBox.SelectedIndex = getBTPollRate(device); try { @@ -579,6 +583,7 @@ namespace DS4Windows { cBFlashType.SelectedIndex = 0; cBWhileCharging.SelectedIndex = 0; + btPollRateComboBox.SelectedIndex = 0; rBTPMouse.Checked = true; rBSAControls.Checked = true; ToggleRainbow(false); @@ -663,59 +668,6 @@ namespace DS4Windows saving = false; } - /* TODO: Possibly remove. Currently not used. */ - /*private string getDS4ControlsByName(DS4Controls key) - { - switch (key) - { - case DS4Controls.Share: return "bnShare"; - case DS4Controls.L3: return "bnL3"; - case DS4Controls.R3: return "bnR3"; - case DS4Controls.Options: return "bnOptions"; - case DS4Controls.DpadUp: return "bnUp"; - case DS4Controls.DpadRight: return "bnRight"; - case DS4Controls.DpadDown: return "bnDown"; - case DS4Controls.DpadLeft: return "bnLeft"; - - case DS4Controls.L1: return "bnL1"; - case DS4Controls.R1: return "bnR1"; - case DS4Controls.Triangle: return "bnTriangle"; - case DS4Controls.Circle: return "bnCircle"; - case DS4Controls.Cross: return "bnCross"; - case DS4Controls.Square: return "bnSquare"; - - case DS4Controls.PS: return "bnPS"; - case DS4Controls.LXNeg: return "bnLSLeft"; - case DS4Controls.LYNeg: return "bnLSUp"; - case DS4Controls.RXNeg: return "bnRSLeft"; - case DS4Controls.RYNeg: return "bnRSUp"; - - case DS4Controls.LXPos: return "bnLSRight"; - case DS4Controls.LYPos: return "bnLSDown"; - case DS4Controls.RXPos: return "bnRSRight"; - case DS4Controls.RYPos: return "bnRSDown"; - case DS4Controls.L2: return "bnL2"; - case DS4Controls.R2: return "bnR2"; - - case DS4Controls.TouchLeft: return "bnTouchLeft"; - case DS4Controls.TouchMulti: return "bnTouchMulti"; - case DS4Controls.TouchUpper: return "bnTouchUpper"; - case DS4Controls.TouchRight: return "bnTouchRight"; - case DS4Controls.GyroXPos: return "bnGyroXP"; - case DS4Controls.GyroXNeg: return "bnGyroXN"; - case DS4Controls.GyroZPos: return "bnGyroZP"; - case DS4Controls.GyroZNeg: return "bnGyroZN"; - - case DS4Controls.SwipeUp: return "bnSwipeUp"; - case DS4Controls.SwipeDown: return "bnSwipeDown"; - case DS4Controls.SwipeLeft: return "bnSwipeLeft"; - case DS4Controls.SwipeRight: return "bnSwipeRight"; - } - - return ""; - } - */ - public void LoadActions(bool newp) { lVActions.Items.Clear(); @@ -1296,6 +1248,7 @@ namespace DS4Windows else FlashColor[device] = new DS4Color(Color.Black); + BTPollRate[device] = btPollRateComboBox.SelectedIndex; L2Deadzone[device] = (byte)Math.Round((nUDL2.Value * 255), 0); R2Deadzone[device] = (byte)Math.Round((nUDR2.Value * 255), 0); L2AntiDeadzone[device] = (int)(nUDL2AntiDead.Value * 100); @@ -1683,21 +1636,32 @@ namespace DS4Windows if (btnRumbleHeavyTest.Text == Properties.Resources.StopText) Program.rootHub.setRumble(0, 0, (int)nUDSixaxis.Value - 1); + if (saving) + { + if (device < 4) + { + DS4Device tempDev = Program.rootHub.DS4Controllers[device]; + if (tempDev != null) + { + int discon = getIdleDisconnectTimeout(device); + int btCurrentIndex = btPollRateComboBox.SelectedIndex; + tempDev.queueEvent(() => + { + tempDev.setIdleTimeout(discon); + if (btCurrentIndex >= 0) + { + tempDev.setBTPollRate(btCurrentIndex); + } + }); + } + } + } + inputtimer.Stop(); sixaxisTimer.Stop(); root.OptionsClosed(); Visible = false; e.Cancel = true; - - if (device < 4) - { - DS4Device tempDev = Program.rootHub.DS4Controllers[device]; - if (tempDev != null) - { - int discon = getIdleDisconnectTimeout(device); - tempDev.queueEvent(() => { tempDev.setIdleTimeout(discon); }); - } - } } private void cBSlide_CheckedChanged(object sender, EventArgs e) @@ -2246,6 +2210,8 @@ namespace DS4Windows case "bnSwipeDown": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break; case "bnL3": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break; case "bnR3": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break; + case "btPollRateLabel": root.lbLastMessage.Text = Properties.Resources.BTPollRate; break; + case "btPollRateComboBox": root.lbLastMessage.Text = Properties.Resources.BTPollRate; break; default: root.lbLastMessage.Text = Properties.Resources.HoverOverItems; break; } @@ -2754,6 +2720,12 @@ namespace DS4Windows R2Maxzone[device] = (int)(nUDR2Maxzone.Value * 100); } + private void btPollRateComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + int currentIndex = btPollRateComboBox.SelectedIndex; + BTPollRate[device] = currentIndex; + } + private void Options_Resize(object sender, EventArgs e) { fLPSettings.AutoScroll = false; diff --git a/DS4Windows/DS4Forms/Options.resx b/DS4Windows/DS4Forms/Options.resx index bd88953..939f2a2 100644 --- a/DS4Windows/DS4Forms/Options.resx +++ b/DS4Windows/DS4Forms/Options.resx @@ -625,7 +625,7 @@ gBOther - 11 + 13 True @@ -781,7 +781,7 @@ gBOther - 14 + 16 115, 64 @@ -802,7 +802,7 @@ gBOther - 9 + 11 105, 29 @@ -859,7 +859,7 @@ gBOther - 13 + 15 4, 18 @@ -1285,7 +1285,7 @@ gBOther - 12 + 14 30, 3 @@ -1911,6 +1911,108 @@ 1 + + True + + + NoControl + + + 10, 227 + + + 67, 13 + + + 259 + + + BT Poll Rate + + + btPollRateLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + gBOther + + + 0 + + + Full (1 ms) + + + 1000 Hz (1 ms) + + + 500 Hz (2 ms) + + + 333 Hz (3 ms) + + + 250 Hz (4 ms) + + + 200 Hz (5 ms) + + + 166 Hz (6 ms) + + + 142 Hz (7 ms) + + + 125 Hz (8 ms) + + + 111 Hz (9 ms) + + + 100 Hz (10 ms) + + + 90 Hz (11 ms) + + + 83 Hz (12 ms) + + + 76 Hz (13 ms) + + + 71 Hz (14 ms) + + + 66 Hz (15 ms) + + + 62 Hz (16 ms) + + + 85, 224 + + + 121, 21 + + + 258 + + + btPollRateComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + gBOther + + + 1 + True @@ -1942,7 +2044,7 @@ gBOther - 0 + 2 True @@ -1975,7 +2077,7 @@ gBOther - 1 + 3 NoControl @@ -2002,7 +2104,7 @@ gBOther - 2 + 4 True @@ -2036,7 +2138,7 @@ with profile gBOther - 3 + 5 Zoom @@ -2069,7 +2171,7 @@ with profile gBOther - 4 + 6 True @@ -2099,7 +2201,7 @@ with profile gBOther - 5 + 7 True @@ -2132,7 +2234,7 @@ with profile gBOther - 6 + 8 85, 95 @@ -2153,7 +2255,7 @@ with profile gBOther - 7 + 9 True @@ -2186,7 +2288,7 @@ with profile gBOther - 8 + 10 True @@ -2219,13 +2321,13 @@ with profile gBOther - 10 + 12 281, 221 - 272, 236 + 272, 256 247 @@ -3518,7 +3620,7 @@ with profile 3, 3, 3, 3 - 438, 448 + 438, 455 2 @@ -5618,7 +5720,7 @@ with profile 3, 3, 3, 3 - 438, 448 + 438, 455 0 @@ -5663,7 +5765,7 @@ with profile 0, 66 - 438, 382 + 438, 389 13 @@ -5852,7 +5954,7 @@ with profile 0, 0 - 438, 448 + 438, 455 15 @@ -5873,7 +5975,7 @@ with profile 4, 22 - 438, 448 + 438, 455 3 @@ -5900,7 +6002,7 @@ with profile 0, 0 - 446, 474 + 446, 481 253 @@ -7310,7 +7412,7 @@ with profile 2, 2, 2, 2 - 564, 474 + 564, 481 254 @@ -7472,7 +7574,7 @@ with profile True - 1010, 474 + 1010, 481 4, 4, 4, 4 @@ -7778,7 +7880,7 @@ with profile advColorDialog - DS4Windows.AdvancedColorDialog, DS4Windows, Version=1.4.69.0, Culture=neutral, PublicKeyToken=null + DS4Windows.AdvancedColorDialog, DS4Windows, Version=1.4.70.0, Culture=neutral, PublicKeyToken=null Options diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 6aa3aaa..077ed85 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -330,6 +330,34 @@ namespace DS4Windows return ledFlashOff; } + // Specify the poll rate interval used for the DS4 hardware when + // connected via Bluetooth + private int btPollRate = 0; + public int BTPollRate + { + get { return btPollRate; } + set + { + if (btPollRate != value && value >= 0 && value <= 16) + { + btPollRate = value; + } + } + } + + public int getBTPollRate() + { + return btPollRate; + } + + public void setBTPollRate(int value) + { + if (btPollRate != value && value >= 0 && value <= 16) + { + btPollRate = value; + } + } + public DS4Touchpad Touchpad { get { return touchpad; } } public DS4SixAxis SixAxis { get { return sixAxis; } } @@ -806,12 +834,14 @@ namespace DS4Windows lock (eventQueueLock) { Action tempAct = null; - //while (eventQueue.TryDequeue(out tempAct)) for (int actInd = 0, actLen = eventQueue.Count; actInd < actLen; actInd++) + //foreach (Action tempAct in eventQueue) { tempAct = eventQueue.Dequeue(); tempAct.Invoke(); } + + //eventQueue.Clear(); } } } @@ -829,7 +859,9 @@ namespace DS4Windows if (conType == ConnectionType.BT) { outputReportBuffer[0] = 0x11; - outputReportBuffer[1] = 0x80; + //outputReportBuffer[1] = 0x80; + //outputReportBuffer[1] = 0x84; + outputReportBuffer[1] = (byte)(0x80 | btPollRate); outputReportBuffer[3] = 0xff; outputReportBuffer[6] = rightLightFastRumble; //fast motor outputReportBuffer[7] = leftHeavySlowRumble; //slow motor diff --git a/DS4Windows/Properties/Resources.Designer.cs b/DS4Windows/Properties/Resources.Designer.cs index 2f2b429..5e41435 100644 --- a/DS4Windows/Properties/Resources.Designer.cs +++ b/DS4Windows/Properties/Resources.Designer.cs @@ -211,6 +211,15 @@ namespace DS4Windows.Properties { } } + /// + /// Looks up a localized string similar to Determines the poll rate used for the DS4 hardware when connected via Bluetooth. + /// + internal static string BTPollRate { + get { + return ResourceManager.GetString("BTPollRate", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cannot move files to new location, Please rename the DS4Tool folder to "DS4Windows". /// diff --git a/DS4Windows/Properties/Resources.resx b/DS4Windows/Properties/Resources.resx index 537f0e0..0ee6d82 100644 --- a/DS4Windows/Properties/Resources.resx +++ b/DS4Windows/Properties/Resources.resx @@ -781,4 +781,7 @@ You need to run DS4Windows as the Administrator in order to activate this mode. + + Determines the poll rate used for the DS4 hardware when connected via Bluetooth + \ No newline at end of file