mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-22 17:29:18 +01:00
Fixed issue with an unreleased lock blocking device removal. Fixed chance for duplicate log entries for device removal.
Resolves issue #7.
This commit is contained in:
parent
a2fb603d72
commit
a0cff7ba30
@ -423,20 +423,33 @@ namespace DS4Windows
|
||||
ind = i;
|
||||
if (ind != -1)
|
||||
{
|
||||
CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
|
||||
x360Bus.Unplug(ind);
|
||||
string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind +1).ToString());
|
||||
if (DS4Controllers[ind].Battery <= 20 &&
|
||||
DS4Controllers[ind].ConnectionType == ConnectionType.BT && !DS4Controllers[ind].Charging)
|
||||
removed += ". " + Properties.Resources.ChargeController;
|
||||
LogDebug(removed);
|
||||
Log.LogToTray(removed);
|
||||
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
|
||||
DS4Controllers[ind] = null;
|
||||
touchPad[ind] = null;
|
||||
lag[ind] = false;
|
||||
inWarnMonitor[ind] = false;
|
||||
ControllerStatusChanged(this);
|
||||
bool removingStatus = false;
|
||||
lock (device.removeLocker)
|
||||
{
|
||||
if (!DS4Controllers[ind].IsRemoving)
|
||||
{
|
||||
removingStatus = true;
|
||||
DS4Controllers[ind].IsRemoving = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (removingStatus)
|
||||
{
|
||||
CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
|
||||
x360Bus.Unplug(ind);
|
||||
string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString());
|
||||
if (DS4Controllers[ind].Battery <= 20 &&
|
||||
DS4Controllers[ind].ConnectionType == ConnectionType.BT && !DS4Controllers[ind].Charging)
|
||||
removed += ". " + Properties.Resources.ChargeController;
|
||||
LogDebug(removed);
|
||||
Log.LogToTray(removed);
|
||||
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
|
||||
DS4Controllers[ind] = null;
|
||||
touchPad[ind] = null;
|
||||
lag[ind] = false;
|
||||
inWarnMonitor[ind] = false;
|
||||
ControllerStatusChanged(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool[] lag = { false, false, false, false };
|
||||
|
@ -153,6 +153,8 @@ namespace DS4Windows
|
||||
public HidDevice HidDevice => hDevice;
|
||||
public bool IsExclusive => HidDevice.IsExclusive;
|
||||
public bool IsDisconnecting { get; private set; }
|
||||
public bool IsRemoving { get; set; }
|
||||
public object removeLocker = new object();
|
||||
|
||||
public string MacAddress => Mac;
|
||||
|
||||
@ -651,6 +653,7 @@ namespace DS4Windows
|
||||
outputReportBuffer[10] = ledFlashOff; //flash off duration
|
||||
outputReportBuffer[19] = outputReportBuffer[20] = Convert.ToByte(audio.Volume);
|
||||
}
|
||||
bool quitOutputThread = false;
|
||||
lock (outputReport)
|
||||
{
|
||||
if (synchronous)
|
||||
@ -662,7 +665,7 @@ namespace DS4Windows
|
||||
if (!writeOutput())
|
||||
{
|
||||
Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered synchronous write failure: " + Marshal.GetLastWin32Error());
|
||||
StopOutputUpdate();
|
||||
quitOutputThread = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
@ -683,6 +686,11 @@ namespace DS4Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (quitOutputThread)
|
||||
{
|
||||
StopOutputUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisconnectBT()
|
||||
|
Loading…
Reference in New Issue
Block a user