mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-23 23:21:49 +01:00
parent
a6adf886dc
commit
da3efd2589
@ -431,15 +431,16 @@ namespace DS4Windows
|
||||
for (int i = 0, arlength = DS4Controllers.Length; ind == -1 && i < arlength; i++)
|
||||
if (DS4Controllers[i] != null && device.MacAddress == DS4Controllers[i].MacAddress)
|
||||
ind = i;
|
||||
|
||||
if (ind != -1)
|
||||
{
|
||||
bool removingStatus = false;
|
||||
lock (device.removeLocker)
|
||||
{
|
||||
if (!DS4Controllers[ind].IsRemoving)
|
||||
if (!device.IsRemoving)
|
||||
{
|
||||
removingStatus = true;
|
||||
DS4Controllers[ind].IsRemoving = true;
|
||||
device.IsRemoving = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,12 +449,13 @@ namespace DS4Windows
|
||||
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)
|
||||
if (device.Battery <= 20 &&
|
||||
device.ConnectionType == ConnectionType.BT && !device.Charging)
|
||||
removed += ". " + Properties.Resources.ChargeController;
|
||||
LogDebug(removed);
|
||||
Log.LogToTray(removed);
|
||||
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
|
||||
device.IsRemoved = true;
|
||||
DS4Controllers[ind] = null;
|
||||
touchPad[ind] = null;
|
||||
lag[ind] = false;
|
||||
|
@ -157,8 +157,36 @@ namespace DS4Windows
|
||||
|
||||
public HidDevice HidDevice => hDevice;
|
||||
public bool IsExclusive => HidDevice.IsExclusive;
|
||||
public bool IsDisconnecting { get; private set; }
|
||||
public bool IsRemoving { get; set; }
|
||||
private bool isDisconnecting = false;
|
||||
public bool IsDisconnecting
|
||||
{
|
||||
get { return isDisconnecting; }
|
||||
private set
|
||||
{
|
||||
this.isDisconnecting = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool isRemoving = false;
|
||||
public bool IsRemoving
|
||||
{
|
||||
get { return isRemoving; }
|
||||
set
|
||||
{
|
||||
this.isRemoving = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool isRemoved = false;
|
||||
public bool IsRemoved
|
||||
{
|
||||
get { return isRemoved; }
|
||||
set
|
||||
{
|
||||
this.isRemoved = value;
|
||||
}
|
||||
}
|
||||
|
||||
public object removeLocker = new object();
|
||||
|
||||
public string MacAddress => Mac;
|
||||
@ -491,7 +519,7 @@ namespace DS4Windows
|
||||
Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + Marshal.GetLastWin32Error());
|
||||
sendOutputReport(true); // Kick Windows into noticing the disconnection.
|
||||
StopOutputUpdate();
|
||||
IsDisconnecting = true;
|
||||
isDisconnecting = true;
|
||||
if (Removal != null)
|
||||
Removal(this, EventArgs.Empty);
|
||||
return;
|
||||
@ -507,7 +535,7 @@ namespace DS4Windows
|
||||
{
|
||||
Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + Marshal.GetLastWin32Error());
|
||||
StopOutputUpdate();
|
||||
IsDisconnecting = true;
|
||||
isDisconnecting = true;
|
||||
if (Removal != null)
|
||||
Removal(this, EventArgs.Empty);
|
||||
return;
|
||||
@ -613,6 +641,11 @@ namespace DS4Windows
|
||||
} */
|
||||
|
||||
bool ds4Idle = cState.FrameCounter == pState.FrameCounter;
|
||||
if (!ds4Idle)
|
||||
{
|
||||
isRemoved = false;
|
||||
}
|
||||
|
||||
if (conType == ConnectionType.USB)
|
||||
{
|
||||
lastActive = utcNow;
|
||||
@ -621,7 +654,7 @@ namespace DS4Windows
|
||||
{
|
||||
bool shouldDisconnect = false;
|
||||
int idleTime = idleTimeout;
|
||||
if (idleTime > 0)
|
||||
if (!isRemoved && idleTime > 0)
|
||||
{
|
||||
bool idleInput = isDS4Idle();
|
||||
if (idleInput)
|
||||
@ -649,8 +682,7 @@ namespace DS4Windows
|
||||
}
|
||||
else if (conType == ConnectionType.SONYWA)
|
||||
{
|
||||
if (DisconnectDongle())
|
||||
return; // all done
|
||||
DisconnectDongle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -792,23 +824,28 @@ namespace DS4Windows
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool DisconnectDongle(bool remove=false)
|
||||
public bool DisconnectDongle(bool remove = false)
|
||||
{
|
||||
bool result = false;
|
||||
byte[] disconnectReport = new byte[65];
|
||||
disconnectReport[0] = 0xe2;
|
||||
disconnectReport[1] = 0x02;
|
||||
for (int i = 2; i < 65; i++)
|
||||
disconnectReport[i] = 0;
|
||||
Array.Clear(disconnectReport, 2, 63);
|
||||
//for (int i = 2; i < 65; i++)
|
||||
// disconnectReport[i] = 0;
|
||||
|
||||
result = hDevice.WriteFeatureReport(disconnectReport);
|
||||
if (result && remove)
|
||||
{
|
||||
IsDisconnecting = true;
|
||||
isDisconnecting = true;
|
||||
StopOutputUpdate();
|
||||
if (Removal != null)
|
||||
Removal(this, EventArgs.Empty);
|
||||
}
|
||||
else if (result && !remove)
|
||||
{
|
||||
isRemoved = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user