Remove reliance on plug return status

Plug change can be delayed but still be successful.
Possibly related to issue #147.
This commit is contained in:
Travis Nickles 2018-03-21 17:43:30 -05:00
parent 3c94a872aa
commit 3b33caf247
2 changed files with 13 additions and 57 deletions

View File

@ -179,17 +179,9 @@ namespace DS4Windows
int xinputIndex = x360Bus.FirstController + i; int xinputIndex = x360Bus.FirstController + i;
LogDebug("Plugging in X360 Controller #" + xinputIndex); LogDebug("Plugging in X360 Controller #" + xinputIndex);
bool xinputResult = x360Bus.Plugin(i); bool xinputResult = x360Bus.Plugin(i);
if (xinputResult)
{
LogDebug("X360 Controller # " + xinputIndex + " connected"); LogDebug("X360 Controller # " + xinputIndex + " connected");
useDInputOnly[i] = false; useDInputOnly[i] = false;
} }
else
{
LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
useDInputOnly[i] = true;
}
}
device.Report += this.On_Report; device.Report += this.On_Report;
TouchPadOn(i, device); TouchPadOn(i, device);
@ -369,17 +361,9 @@ namespace DS4Windows
int xinputIndex = x360Bus.FirstController + Index; int xinputIndex = x360Bus.FirstController + Index;
LogDebug("Plugging in X360 Controller #" + xinputIndex); LogDebug("Plugging in X360 Controller #" + xinputIndex);
bool xinputResult = x360Bus.Plugin(Index); bool xinputResult = x360Bus.Plugin(Index);
if (xinputResult)
{
LogDebug("X360 Controller # " + xinputIndex + " connected"); LogDebug("X360 Controller # " + xinputIndex + " connected");
useDInputOnly[Index] = false; useDInputOnly[Index] = false;
} }
else
{
LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
useDInputOnly[Index] = true;
}
}
TouchPadOn(Index, device); TouchPadOn(Index, device);
CheckProfileOptions(Index, device); CheckProfileOptions(Index, device);
@ -625,16 +609,9 @@ namespace DS4Windows
{ {
bool unplugResult = x360Bus.Unplug(ind); bool unplugResult = x360Bus.Unplug(ind);
int xinputIndex = x360Bus.FirstController + ind; int xinputIndex = x360Bus.FirstController + ind;
if (unplugResult)
{
LogDebug("X360 Controller # " + xinputIndex + " unplugged"); LogDebug("X360 Controller # " + xinputIndex + " unplugged");
useDInputOnly[ind] = true; useDInputOnly[ind] = true;
} }
else
{
LogDebug("X360 Controller # " + xinputIndex + " failed to unplug");
}
}
} }
else else
{ {
@ -643,17 +620,9 @@ namespace DS4Windows
int xinputIndex = x360Bus.FirstController + ind; int xinputIndex = x360Bus.FirstController + ind;
LogDebug("Plugging in X360 Controller #" + xinputIndex); LogDebug("Plugging in X360 Controller #" + xinputIndex);
bool xinputResult = x360Bus.Plugin(ind); bool xinputResult = x360Bus.Plugin(ind);
if (xinputResult)
{
LogDebug("X360 Controller # " + xinputIndex + " connected"); LogDebug("X360 Controller # " + xinputIndex + " connected");
useDInputOnly[ind] = false; useDInputOnly[ind] = false;
} }
else
{
LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
useDInputOnly[ind] = true;
}
}
} }
} }
} }
@ -688,15 +657,8 @@ namespace DS4Windows
{ {
bool unplugResult = x360Bus.Unplug(ind); bool unplugResult = x360Bus.Unplug(ind);
int xinputIndex = x360Bus.FirstController + ind; int xinputIndex = x360Bus.FirstController + ind;
if (unplugResult)
{
LogDebug("X360 Controller # " + xinputIndex + " unplugged"); LogDebug("X360 Controller # " + xinputIndex + " unplugged");
} }
else
{
LogDebug("X360 Controller # " + xinputIndex + " failed to unplug");
}
}
string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString()); string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString());
if (device.getBattery() <= 20 && if (device.getBattery() <= 20 &&

View File

@ -2844,21 +2844,15 @@ namespace DS4Windows
if (xinputStatus && xinputPlug) if (xinputStatus && xinputPlug)
{ {
bool xinputResult = control.x360Bus.Plugin(device); bool xinputResult = control.x360Bus.Plugin(device);
if (xinputResult)
{
int xinputIndex = control.x360Bus.FirstController + device; int xinputIndex = control.x360Bus.FirstController + device;
Log.LogToGui("X360 Controller # " + xinputIndex + " connected", false); Log.LogToGui("X360 Controller # " + xinputIndex + " connected", false);
} }
}
else if (xinputStatus && !xinputPlug) else if (xinputStatus && !xinputPlug)
{ {
bool xinputResult = control.x360Bus.Unplug(device); bool xinputResult = control.x360Bus.Unplug(device);
if (xinputResult)
{
int xinputIndex = control.x360Bus.FirstController + device; int xinputIndex = control.x360Bus.FirstController + device;
Log.LogToGui("X360 Controller # " + xinputIndex + " unplugged", false); Log.LogToGui("X360 Controller # " + xinputIndex + " unplugged", false);
} }
}
tempDev.setRumble(0, 0); tempDev.setRumble(0, 0);
}); });