public bool Stop(bool showlog = true)
{
if (running)
{
running = false;
if (showlog)
{
LogDebug(Properties.Resources.StoppingX360);
}
bool anyUnplugged = false;
for (int i = 0; i < DS4Controllers.Length; i++)
{
if (DS4Controllers[i] != null)
{
if (DCBTatStop && !DS4Controllers[i].Charging && showlog)
{
DS4Controllers[i].DisconnectBT();
}
else
{
DS4LightBar.forcelight[i] = false;
DS4LightBar.forcedFlash[i] = 0;
DS4LightBar.defualtLight = true;
DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]);
System.Threading.Thread.Sleep(50);
}
CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
x360Bus.Unplug(i);
anyUnplugged = true;
DS4Controllers[i] = null;
touchPad[i] = null;
}
}
if (anyUnplugged)
{
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
}
x360Bus.UnplugAll();
x360Bus.Stop();
if (showlog)
{
LogDebug(Properties.Resources.StoppingDS4);
}
DS4Devices.stopControllers();
if (showlog)
{
LogDebug(Properties.Resources.StoppedDS4Windows);
}
ControllerStatusChanged(this);
}
return(true);
}