diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index f627044..18ac714 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -7,6 +7,7 @@ using System.Media; using System.Threading.Tasks; using System.Diagnostics; using static DS4Windows.Global; +using System.Threading; namespace DS4Windows { @@ -242,7 +243,7 @@ namespace DS4Windows CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change. x360Bus.Unplug(i); - useDInputOnly[i] = false; + useDInputOnly[i] = true; anyUnplugged = true; DS4Controllers[i] = null; touchPad[i] = null; @@ -634,7 +635,7 @@ namespace DS4Windows touchPad[ind] = null; lag[ind] = false; inWarnMonitor[ind] = false; - useDInputOnly[ind] = false; + useDInputOnly[ind] = true; System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME); OnControllerRemoved(this, ind); } @@ -671,9 +672,23 @@ namespace DS4Windows { int flashWhenLateAt = getFlashWhenLateAt(); if (!lag[ind] && device.Latency >= flashWhenLateAt) - LagFlashWarning(ind, true); + { + device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) + { + LagFlashWarning(ind, true); + }), null); + + //LagFlashWarning(ind, true); + } else if (lag[ind] && device.Latency < flashWhenLateAt) - LagFlashWarning(ind, false); + { + device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) + { + LagFlashWarning(ind, false); + }), null); + + //LagFlashWarning(ind, false); + } } else { @@ -691,11 +706,22 @@ namespace DS4Windows if (!device.firstReport && device.IsAlive()) { device.firstReport = true; - OnDeviceStatusChanged(this, ind); + device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) + { + OnDeviceStatusChanged(this, ind); + }), null); + + //OnDeviceStatusChanged(this, ind); + } else if (pState.Battery != cState.Battery || device.oldCharging != device.isCharging()) { - OnBatteryStatusChange(this, ind, cState.Battery, device.isCharging()); + device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) + { + OnBatteryStatusChange(this, ind, cState.Battery, device.isCharging()); + }), null); + + //OnBatteryStatusChange(this, ind, cState.Battery, device.isCharging()); } if (getEnableTouchToggle(ind)) diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 64a0cf3..d974b38 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -249,7 +249,7 @@ namespace DS4Windows public const int XINPUT_UNPLUG_SETTLE_TIME = 250; // Inhibit races that occur with the asynchronous teardown of ScpVBus -> X360 driver instance. public static string[] tempprofilename = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty }; public static bool[] tempprofileDistance = new bool[5] { false, false, false, false, false }; - public static bool[] useDInputOnly = new bool[5] { false, false, false, false, false }; + public static bool[] useDInputOnly = new bool[5] { true, true, true, true, true }; public static X360Controls[] defaultButtonMapping = { X360Controls.None, X360Controls.LXNeg, X360Controls.LXPos, X360Controls.LYNeg, X360Controls.LYPos, X360Controls.RXNeg, X360Controls.RXPos, X360Controls.RYNeg, X360Controls.RYPos, diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 084bf2c..f2d40e2 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -384,6 +384,11 @@ namespace DS4Windows } private SynchronizationContext uiContext = null; + public SynchronizationContext getUiContext() + { + return uiContext; + } + private Queue eventQueue = new Queue(); private object eventQueueLock = new object(); @@ -692,6 +697,7 @@ namespace DS4Windows Removal?.Invoke(this, EventArgs.Empty); }), null); + timeoutExecuted = true; return; } } @@ -722,6 +728,7 @@ namespace DS4Windows Removal?.Invoke(this, EventArgs.Empty); }), null); + timeoutExecuted = true; return; } else diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index ee6c2e0..ba7b2fc 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -109,7 +109,7 @@ namespace DS4Windows // Grab reference to exclusively opened HidDevice so device // stays hidden to other processes DisabledDevices.Add(hDevice); - DevicePaths.Add(hDevice.DevicePath); + //DevicePaths.Add(hDevice.DevicePath); } continue; @@ -184,7 +184,7 @@ namespace DS4Windows device.HidDevice.CloseDevice(); Devices.Remove(device.MacAddress); DevicePaths.Remove(device.HidDevice.DevicePath); - purgeHiddenExclusiveDevices(); + //purgeHiddenExclusiveDevices(); } } }