Test minor change of usb device removal

This commit is contained in:
Travis Nickles 2017-05-01 03:40:37 -07:00
parent d35ba4db98
commit 4ce52da612
3 changed files with 13 additions and 4 deletions

View File

@ -221,6 +221,7 @@ namespace DS4Windows
DS4LightBar.forcedFlash[i] = 0; DS4LightBar.forcedFlash[i] = 0;
DS4LightBar.defaultLight = true; DS4LightBar.defaultLight = true;
DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]); DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]);
DS4Controllers[i].IsRemoved = true;
System.Threading.Thread.Sleep(50); System.Threading.Thread.Sleep(50);
} }
@ -229,6 +230,8 @@ namespace DS4Windows
anyUnplugged = true; anyUnplugged = true;
DS4Controllers[i] = null; DS4Controllers[i] = null;
touchPad[i] = null; touchPad[i] = null;
lag[i] = false;
inWarnMonitor[i] = false;
} }
} }

View File

@ -161,6 +161,7 @@ namespace DS4Windows
} }
private bool exitOutputThread = false; private bool exitOutputThread = false;
private bool exitInputThread = false;
private object exitLocker = new object(); private object exitLocker = new object();
public event EventHandler<EventArgs> Report = null; public event EventHandler<EventArgs> Report = null;
public event EventHandler<EventArgs> Removal = null; public event EventHandler<EventArgs> Removal = null;
@ -421,7 +422,8 @@ namespace DS4Windows
{ {
try try
{ {
ds4Input.Abort(); exitInputThread = true;
//ds4Input.Abort();
ds4Input.Join(); ds4Input.Join();
} }
catch (Exception e) catch (Exception e)
@ -540,7 +542,7 @@ namespace DS4Windows
long oldtime = 0; long oldtime = 0;
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
while (true) while (!exitInputThread)
{ {
string currerror = string.Empty; string currerror = string.Empty;
long curtime = sw.ElapsedMilliseconds; long curtime = sw.ElapsedMilliseconds;
@ -1053,6 +1055,11 @@ namespace DS4Windows
return Mac; return Mac;
} }
public void runRemoval()
{
Removal?.Invoke(this, EventArgs.Empty);
}
public void removeReportHandlers() public void removeReportHandlers()
{ {
this.Report = null; this.Report = null;

View File

@ -146,6 +146,7 @@ namespace DS4Windows
{ {
DS4Device device = devices.ElementAt<DS4Device>(i); DS4Device device = devices.ElementAt<DS4Device>(i);
device.StopUpdate(); device.StopUpdate();
//device.runRemoval();
device.HidDevice.CloseDevice(); device.HidDevice.CloseDevice();
} }
@ -216,8 +217,6 @@ namespace DS4Windows
throw new Exception("Error enabling device, error code = " + Marshal.GetLastWin32Error()); throw new Exception("Error enabling device, error code = " + Marshal.GetLastWin32Error());
} }
System.Threading.Thread.Sleep(50);
NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet); NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet);
} }
} }