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