Fix process starting issue when activating exclusive mode

Only one hotplug request should be processed at a time now.
Hopefully this fixes issues with devices staying disabled
This commit is contained in:
Travis Nickles 2017-05-01 11:28:07 -07:00
parent 4ce52da612
commit 400ba4f293
3 changed files with 44 additions and 16 deletions

View File

@ -208,10 +208,14 @@ namespace DS4Windows
{
if (DS4Controllers[i].getConnectionType() == ConnectionType.BT)
{
DS4Controllers[i].DisconnectBT(true);
DS4Device device = DS4Controllers[i];
device.StopUpdate();
device.DisconnectBT(true);
}
else if (DS4Controllers[i].getConnectionType() == ConnectionType.SONYWA)
{
DS4Device device = DS4Controllers[i];
device.StopUpdate();
DS4Controllers[i].DisconnectDongle(true);
}
}
@ -270,7 +274,13 @@ namespace DS4Windows
{
if (device.getConnectionType() == ConnectionType.BT && device.isCharging())
{
device.DisconnectBT();
device.StopUpdate();
device.DisconnectBT(true);
/*Task temp = Task.Delay(50).ContinueWith((t) => {
while (!device.IsRemoved) { System.Threading.Thread.Sleep(10); }
});
temp.Wait(100);
*/
}
}
}
@ -365,7 +375,7 @@ namespace DS4Windows
/* TODO: Check if this method is really necessary. If not, delete it. For now, it is not being used because
* input reports are read async with a timeout now. */
public void TimeoutConnection(DS4Device d)
/*public void TimeoutConnection(DS4Device d)
{
try
{
@ -390,6 +400,7 @@ namespace DS4Windows
Start(false);
}
}
*/
public string getDS4ControllerInfo(int index)
{
@ -682,6 +693,7 @@ namespace DS4Windows
}
}
/* TODO: Not used. Possible candidate for removal. Currently keeping for reference. */
/*public void EasterTime(int ind)
{
DS4State cState = CurrentState[ind];
@ -893,7 +905,8 @@ namespace DS4Windows
return result;
}
public DS4Controls GetInputkeysDS4(int ind)
/* TODO: Not used. Possible candidate for removal. Currently keeping for reference. */
/*public DS4Controls GetInputkeysDS4(int ind)
{
DS4State cState = CurrentState[ind];
DS4StateExposed eState = ExposedState[ind];
@ -1022,6 +1035,7 @@ namespace DS4Windows
return result;
}
*/
public bool[] touchreleased = { true, true, true, true }, touchslid = { false, false, false, false };
public byte[] oldtouchvalue = { 0, 0, 0, 0 };

View File

@ -937,6 +937,7 @@ namespace DS4Windows
//delegate void OldHotPlugDelegate();
bool skipHotplug = false;
bool inHotPlug = false;
protected override void WndProc(ref Message m)
{
if (runHotPlug)
@ -947,17 +948,7 @@ namespace DS4Windows
{
Int32 Type = m.WParam.ToInt32();
lock (this)
{
// Execute hotplug routine after a delay in time. Set flag so extra calls
// to WndProc will be ignored
skipHotplug = true;
System.Threading.Tasks.Task.Delay(50).ContinueWith((t) => InnerHotplug());
//OldHotPlugDelegate d = new OldHotPlugDelegate(InnerHotplug);
//this.BeginInvoke(d);
//skipHotplug = false;
//Program.rootHub.HotPlug();
}
InnerHotplug2();
}
}
catch { }
@ -984,6 +975,28 @@ namespace DS4Windows
}
}
protected async void InnerHotplug2()
{
if (inHotPlug)
{
await System.Threading.Tasks.Task.Run(() => { while (inHotPlug) { System.Threading.Thread.Sleep(50); } });
}
lock (this)
{
skipHotplug = true;
//System.Threading.Tasks.Task.Delay(50).ContinueWith((t) => InnerHotplug());
//System.Threading.Tasks.Task tempTask = System.Threading.Tasks.Task.Delay(50).ContinueWith((t) => { });
//tempTask.Wait();
//OldHotPlugDelegate d = new OldHotPlugDelegate(InnerHotplug);
//this.BeginInvoke(d);
//skipHotplug = false;
inHotPlug = true;
Program.rootHub.HotPlug();
inHotPlug = false;
}
}
protected void BatteryStatusUpdate(object sender, BatteryReportArgs args)
{
if (this.InvokeRequired)

View File

@ -68,6 +68,7 @@ namespace DS4Windows
startInfo.Verb = "runas";
startInfo.Arguments = "re-enabledevice " + devicePathToInstanceId(hDevice.DevicePath);
Process child = Process.Start(startInfo);
if (!child.WaitForExit(5000))
{
child.Kill();
@ -144,7 +145,7 @@ namespace DS4Windows
//foreach (DS4Device device in devices)
for (int i = 0, devCount = devices.Count(); i < devCount; i++)
{
DS4Device device = devices.ElementAt<DS4Device>(i);
DS4Device device = devices.ElementAt(i);
device.StopUpdate();
//device.runRemoval();
device.HidDevice.CloseDevice();