From 474d8061fcd4ff8a211c9f8075c6fe4ce492ccb9 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 18 Aug 2018 02:35:23 -0500 Subject: [PATCH 1/7] Update url of alt build --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d69283d..e0ca3cc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ website at [ds4windows.com](http://ds4windows.com). - **[Main builds of DS4Windows](https://github.com/Ryochan7/DS4Windows/releases)** - Alternative builds: - - [UdpServer ViGEm build](http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.5_ViGEm_UdpServer_x64.zip) + - [UdpServer ViGEm build](http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.6_ViGEm_UdpServer_x64.zip) ## Requirements From ac9e2411ac06aba6dedf93023046c942937c321a Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 19 Aug 2018 14:03:55 -0500 Subject: [PATCH 2/7] Fix variable scope for swap profile routine Resolves issue #394 --- DS4Windows/DS4Forms/DS4Form.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 8edb4cf..fa9d9c2 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -535,30 +535,33 @@ namespace DS4Windows string slide = Program.rootHub.TouchpadSlide(i); if (slide == "left") { + int ind = i; this.BeginInvoke((System.Action)(() => { - if (cbs[i].SelectedIndex <= 0) - cbs[i].SelectedIndex = cbs[i].Items.Count - 2; + if (cbs[ind].SelectedIndex <= 0) + cbs[ind].SelectedIndex = cbs[ind].Items.Count - 2; else - cbs[i].SelectedIndex--; + cbs[ind].SelectedIndex--; })); } else if (slide == "right") { + int ind = i; this.BeginInvoke((System.Action)(() => { - if (cbs[i].SelectedIndex == cbs[i].Items.Count - 2) - cbs[i].SelectedIndex = 0; + if (cbs[ind].SelectedIndex == cbs[ind].Items.Count - 2) + cbs[ind].SelectedIndex = 0; else - cbs[i].SelectedIndex++; + cbs[ind].SelectedIndex++; })); } if (slide.Contains("t")) { + int ind = i; this.BeginInvoke((System.Action)(() => { - ShowNotification(this, Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", cbs[i].Text)); + ShowNotification(this, Properties.Resources.UsingProfile.Replace("*number*", (ind + 1).ToString()).Replace("*Profile name*", cbs[ind].Text)); })); } } From 6f5b17ac374ff81b216acf358c56aaed79ee7da3 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Mon, 20 Aug 2018 04:35:41 -0500 Subject: [PATCH 3/7] Remove ui thread from unplug routine Hotplug routine was starting before removal routine was being started. No blocking was happening anyway --- DS4Windows/DS4Control/ControlService.cs | 16 ++++++------- DS4Windows/DS4Forms/DS4Form.cs | 7 +++--- DS4Windows/DS4Library/DS4Device.cs | 30 ++++--------------------- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 75cf40b..0994918 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -381,6 +381,7 @@ namespace DS4Windows return unplugResult; } + private SynchronizationContext uiContext = null; public bool Start(object tempui, bool showlog = true) { if (x360Bus.Open() && x360Bus.Start()) @@ -391,6 +392,7 @@ namespace DS4Windows LogDebug("Connection to Scp Virtual Bus established"); DS4Devices.isExclusiveMode = getUseExclusiveMode(); + uiContext = tempui as SynchronizationContext; if (showlog) { LogDebug(Properties.Resources.SearchingController); @@ -424,7 +426,6 @@ namespace DS4Windows task.Start(); DS4Controllers[i] = device; - device.setUiContext(tempui as SynchronizationContext); device.Removal += this.On_DS4Removal; device.Removal += DS4Devices.On_Removal; device.SyncChange += this.On_SyncChange; @@ -618,7 +619,7 @@ namespace DS4Windows return true; } - public bool HotPlug(SynchronizationContext uiContext) + public bool HotPlug() { if (running) { @@ -655,7 +656,6 @@ namespace DS4Windows Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); }); task.Start(); DS4Controllers[Index] = device; - device.setUiContext(uiContext); device.Removal += this.On_DS4Removal; device.Removal += DS4Devices.On_Removal; device.SyncChange += this.On_SyncChange; @@ -1072,7 +1072,7 @@ namespace DS4Windows string devError = tempStrings[ind] = device.error; if (!string.IsNullOrEmpty(devError)) { - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) + uiContext?.Post(new SendOrPostCallback(delegate (object state) { LogDebug(devError); }), null); @@ -1084,7 +1084,7 @@ namespace DS4Windows if (!lag[ind] && device.Latency >= flashWhenLateAt) { lag[ind] = true; - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) + uiContext?.Post(new SendOrPostCallback(delegate (object state) { LagFlashWarning(ind, true); }), null); @@ -1092,7 +1092,7 @@ namespace DS4Windows else if (lag[ind] && device.Latency < flashWhenLateAt) { lag[ind] = false; - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) + uiContext?.Post(new SendOrPostCallback(delegate (object state) { LagFlashWarning(ind, false); }), null); @@ -1115,7 +1115,7 @@ namespace DS4Windows if (device.firstReport && device.IsAlive()) { device.firstReport = false; - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) + uiContext?.Post(new SendOrPostCallback(delegate (object state) { OnDeviceStatusChanged(this, ind); }), null); @@ -1124,7 +1124,7 @@ namespace DS4Windows { byte tempBattery = currentBattery[ind] = cState.Battery; bool tempCharging = charging[ind] = device.isCharging(); - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) + uiContext?.Post(new SendOrPostCallback(delegate (object state) { OnBatteryStatusChange(this, ind, tempBattery, tempCharging); }), null); diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index fa9d9c2..3b4348e 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -1010,11 +1010,10 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question hotplugCounter++; } - var uiContext = SynchronizationContext.Current; if (!inHotPlug) { inHotPlug = true; - TaskRunner.Run(() => { Thread.Sleep(1500); InnerHotplug2(uiContext); }); + TaskRunner.Run(() => { Thread.Sleep(1500); InnerHotplug2(); }); } } } @@ -1028,7 +1027,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question base.WndProc(ref m); } - private void InnerHotplug2(SynchronizationContext uiContext) + private void InnerHotplug2() { inHotPlug = true; @@ -1040,7 +1039,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question while (loopHotplug == true) { - Program.rootHub.HotPlug(uiContext); + Program.rootHub.HotPlug(); //TaskRunner.Run(() => { Program.rootHub.HotPlug(uiContext); }); lock (hotplugCounterLock) { diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index db239f7..560894b 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -392,16 +392,6 @@ namespace DS4Windows return result; } - private SynchronizationContext uiContext = null; - public SynchronizationContext getUiContext() - { - return uiContext; - } - public void setUiContext(SynchronizationContext uiContext) - { - this.uiContext = uiContext; - } - private Queue eventQueue = new Queue(); private object eventQueueLock = new object(); @@ -808,10 +798,7 @@ namespace DS4Windows sendOutputReport(true, true); // Kick Windows into noticing the disconnection. StopOutputUpdate(); isDisconnecting = true; - uiContext.Send(new SendOrPostCallback(delegate (object state4) - { - Removal?.Invoke(this, EventArgs.Empty); - }), null); + Removal?.Invoke(this, EventArgs.Empty); timeoutExecuted = true; return; @@ -838,10 +825,7 @@ namespace DS4Windows StopOutputUpdate(); isDisconnecting = true; - uiContext.Send(new SendOrPostCallback(delegate (object state4) - { - Removal?.Invoke(this, EventArgs.Empty); - }), null); + Removal?.Invoke(this, EventArgs.Empty); timeoutExecuted = true; return; @@ -1292,10 +1276,7 @@ namespace DS4Windows if (callRemoval) { - uiContext.Send(new SendOrPostCallback(delegate (object state) - { - Removal?.Invoke(this, EventArgs.Empty); - }), null); + Removal?.Invoke(this, EventArgs.Empty); //System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); }); } @@ -1327,10 +1308,7 @@ namespace DS4Windows { isDisconnecting = true; - uiContext.Send(new SendOrPostCallback(delegate (object state4) - { - Removal?.Invoke(this, EventArgs.Empty); - }), null); + Removal?.Invoke(this, EventArgs.Empty); //System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); }); //Removal?.Invoke(this, EventArgs.Empty); From 92550de1ce449cd9833105498e1bb7fe83a1da5d Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Mon, 20 Aug 2018 04:36:48 -0500 Subject: [PATCH 4/7] Updated TODO file --- TODO.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index eb8eec2..3876e29 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,9 @@ # TODO * ~~Perform some final cleanup and release version 1.5~~ -* Attempt to remove reliance on the main thread when disconnecting a device. -Currently used to delay hotplug routine +* ~~Attempt to remove reliance on the main thread when disconnecting a device. +Currently used to delay hotplug routine~~ +* Look into newer version of HidGuardian * Look into distributing profile properties around various objects rather than using a lot of getters to obtain properties each poll. It will complicate the architecture a little bit but hopefully From ac360c426dcd6253676eff0199cb53a3cca22f7d Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Mon, 20 Aug 2018 13:14:34 -0500 Subject: [PATCH 5/7] Fixed issue with SONYWA connections having invalid calibration data --- DS4Windows/DS4Library/DS4Device.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 560894b..4a58fc8 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -436,7 +436,7 @@ namespace DS4Windows warnInterval = WARN_INTERVAL_BT; audio = new DS4Audio(); micAudio = new DS4Audio(DS4Library.CoreAudio.DataFlow.Capture); - synced = isValidSerial(); + runCalib = synced = isValidSerial(); } } else @@ -1000,7 +1000,7 @@ namespace DS4Windows bool controllerSynced = inputReport[31] == 0; if (controllerSynced != synced) { - synced = controllerSynced; + runCalib = synced = controllerSynced; SyncChange?.Invoke(this, EventArgs.Empty); sendOutputReport(true, true); } From f2de4bc87d787d6ce75229101bca276f880c7255 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Fri, 24 Aug 2018 15:17:13 -0500 Subject: [PATCH 6/7] Change timer behavior Using the Stop method is not enough apparently --- DS4Windows/DS4Forms/DS4Form.cs | 71 +++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 3b4348e..6ae5f7f 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -246,7 +246,7 @@ namespace DS4Windows */ //tabProfiles.Controls.Add(opt); - autoProfilesTimer.Elapsed += CheckAutoProfiles; + //autoProfilesTimer.Elapsed += CheckAutoProfiles; autoProfilesTimer.Interval = 1000; autoProfilesTimer.AutoReset = false; @@ -268,11 +268,12 @@ namespace DS4Windows Enable_Controls(3, false); btnStartStop.Text = Properties.Resources.StartText; - hotkeysTimer.Elapsed += Hotkeys; + //hotkeysTimer.Elapsed += Hotkeys; hotkeysTimer.AutoReset = false; if (SwipeProfiles) { - hotkeysTimer.Start(); + ChangeHotkeysStatus(true); + //hotkeysTimer.Start(); } startToolStripMenuItem.Text = btnStartStop.Text; @@ -434,6 +435,34 @@ namespace DS4Windows lbLastMessage.ForeColor = SystemColors.GrayText; } + private void ChangeAutoProfilesStatus(bool state) + { + if (state) + { + autoProfilesTimer.Elapsed += CheckAutoProfiles; + autoProfilesTimer.Start(); + } + else + { + autoProfilesTimer.Stop(); + autoProfilesTimer.Elapsed -= CheckAutoProfiles; + } + } + + private void ChangeHotkeysStatus(bool state) + { + if (state) + { + hotkeysTimer.Elapsed += Hotkeys; + hotkeysTimer.Start(); + } + else + { + hotkeysTimer.Stop(); + hotkeysTimer.Elapsed -= Hotkeys; + } + } + private void blankControllerTab() { for (int Index = 0, PadsLen = Pads.Length; @@ -602,8 +631,10 @@ namespace DS4Windows turnOffTemp = true; if (btnStartStop.Text == Properties.Resources.StopText) { - autoProfilesTimer.Stop(); - hotkeysTimer.Stop(); + //autoProfilesTimer.Stop(); + //hotkeysTimer.Stop(); + ChangeAutoProfilesStatus(false); + ChangeHotkeysStatus(false); this.Invoke((System.Action)(() => { this.changingService = true; @@ -617,8 +648,10 @@ namespace DS4Windows this.Invoke((System.Action)(() => { - hotkeysTimer.Start(); - autoProfilesTimer.Start(); + //hotkeysTimer.Start(); + ChangeHotkeysStatus(true); + ChangeAutoProfilesStatus(true); + //autoProfilesTimer.Start(); })); } } @@ -691,11 +724,13 @@ namespace DS4Windows bool timerEnabled = autoProfilesTimer.Enabled; if (pathCount > 0 && !timerEnabled) { - autoProfilesTimer.Start(); + ChangeAutoProfilesStatus(true); + //autoProfilesTimer.Start(); } else if (pathCount == 0 && timerEnabled) { - autoProfilesTimer.Stop(); + //autoProfilesTimer.Stop(); + ChangeAutoProfilesStatus(false); } } @@ -942,12 +977,14 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question { if (SwipeProfiles && !hotkeysTimer.Enabled) { - hotkeysTimer.Start(); + ChangeHotkeysStatus(true); + //hotkeysTimer.Start(); } if (programpaths.Count > 0 && !autoProfilesTimer.Enabled) { - autoProfilesTimer.Start(); + ChangeAutoProfilesStatus(true); + //autoProfilesTimer.Start(); } startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StopText; @@ -966,8 +1003,10 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question private void ServiceShutdownFinish() { - hotkeysTimer.Stop(); - autoProfilesTimer.Stop(); + ChangeAutoProfilesStatus(false); + ChangeHotkeysStatus(false); + //hotkeysTimer.Stop(); + //autoProfilesTimer.Stop(); startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StartText; blankControllerTab(); populateFullNotifyText(); @@ -2154,11 +2193,13 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question bool timerEnabled = hotkeysTimer.Enabled; if (swipe && !timerEnabled) { - hotkeysTimer.Start(); + ChangeHotkeysStatus(true); + //hotkeysTimer.Start(); } else if (!swipe && timerEnabled) { - hotkeysTimer.Stop(); + ChangeHotkeysStatus(false); + //hotkeysTimer.Stop(); } } From 0ce20cdfc83e9c4c71490deb0ecbc31b1cb20a76 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Fri, 24 Aug 2018 15:22:31 -0500 Subject: [PATCH 7/7] Version 1.5.7 --- DS4Windows/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DS4Windows/Properties/AssemblyInfo.cs b/DS4Windows/Properties/AssemblyInfo.cs index c360ca1..afdc6ab 100644 --- a/DS4Windows/Properties/AssemblyInfo.cs +++ b/DS4Windows/Properties/AssemblyInfo.cs @@ -33,7 +33,7 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.6")] -[assembly: AssemblyFileVersion("1.5.6")] +[assembly: AssemblyVersion("1.5.7")] +[assembly: AssemblyFileVersion("1.5.7")] [assembly: NeutralResourcesLanguage("en")]