More log messages. Tweak DisconnectBT. Other minor changes.

This commit is contained in:
Travis Nickles 2017-05-01 02:29:19 -07:00
parent cd5a77359a
commit d37e0709c0
4 changed files with 66 additions and 29 deletions

View File

@ -106,6 +106,8 @@ namespace DS4Windows
if (showlog) if (showlog)
LogDebug(Properties.Resources.Starting); LogDebug(Properties.Resources.Starting);
LogDebug("Connection to Scp Virtual Bus established");
DS4Devices.isExclusiveMode = getUseExclusiveMode(); DS4Devices.isExclusiveMode = getUseExclusiveMode();
if (showlog) if (showlog)
{ {
@ -120,9 +122,10 @@ namespace DS4Windows
//int ind = 0; //int ind = 0;
DS4LightBar.defaultLight = false; DS4LightBar.defaultLight = false;
//foreach (DS4Device device in devices) //foreach (DS4Device device in devices)
for (int i = 0, devCount = devices.Count(); i < devCount; i++) for (int i = 0, devCount = devices.Count(); i < devCount; i++)
{ {
DS4Device device = devices.ElementAt<DS4Device>(i); DS4Device device = devices.ElementAt(i);
if (showlog) if (showlog)
LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")"); LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
@ -135,10 +138,14 @@ namespace DS4Windows
device.LightBarColor = getMainColor(i); device.LightBarColor = getMainColor(i);
if (!getDInputOnly(i)) if (!getDInputOnly(i))
{
LogDebug("Plugging in X360 Controller #" + (x360Bus.FirstController + i));
x360Bus.Plugin(i); x360Bus.Plugin(i);
}
device.Report += this.On_Report; device.Report += this.On_Report;
TouchPadOn(i, device); TouchPadOn(i, device);
device.StartUpdate();
//string filename = ProfilePath[ind]; //string filename = ProfilePath[ind];
//ind++; //ind++;
if (showlog) if (showlog)
@ -197,11 +204,11 @@ namespace DS4Windows
{ {
if (DS4Controllers[i] != null) if (DS4Controllers[i] != null)
{ {
if (DCBTatStop && !DS4Controllers[i].isCharging() && showlog) if (DCBTatStop && !DS4Controllers[i].isCharging())
{ {
if (DS4Controllers[i].getConnectionType() == ConnectionType.BT) if (DS4Controllers[i].getConnectionType() == ConnectionType.BT)
{ {
DS4Controllers[i].DisconnectBT(); DS4Controllers[i].DisconnectBT(true);
} }
else if (DS4Controllers[i].getConnectionType() == ConnectionType.SONYWA) else if (DS4Controllers[i].getConnectionType() == ConnectionType.SONYWA)
{ {
@ -216,6 +223,7 @@ namespace DS4Windows
DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]); DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]);
System.Threading.Thread.Sleep(50); System.Threading.Thread.Sleep(50);
} }
CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change. CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
x360Bus.Unplug(i); x360Bus.Unplug(i);
anyUnplugged = true; anyUnplugged = true;
@ -250,25 +258,27 @@ namespace DS4Windows
{ {
// Do first run check for Quick Charge checks. Needed so old device will // Do first run check for Quick Charge checks. Needed so old device will
// be removed before performing another controller scan // be removed before performing another controller scan
if (getQuickCharge())
{
for (int i = 0, devlen = DS4Controllers.Length; i < devlen; i++) for (int i = 0, devlen = DS4Controllers.Length; i < devlen; i++)
{ {
DS4Device device = DS4Controllers[i]; DS4Device device = DS4Controllers[i];
if (device != null) if (device != null)
{ {
if (getQuickCharge() && device.getConnectionType() == ConnectionType.BT && if (device.getConnectionType() == ConnectionType.BT && device.isCharging())
device.isCharging())
{ {
device.DisconnectBT(); device.DisconnectBT();
} }
} }
} }
}
DS4Devices.findControllers(); DS4Devices.findControllers();
IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers(); IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers();
//foreach (DS4Device device in devices) //foreach (DS4Device device in devices)
for (int i = 0, devlen = devices.Count(); i < devlen; i++) for (int i = 0, devlen = devices.Count(); i < devlen; i++)
{ {
DS4Device device = devices.ElementAt<DS4Device>(i); DS4Device device = devices.ElementAt(i);
if (device.isDisconnectingStatus()) if (device.isDisconnectingStatus())
continue; continue;
@ -302,8 +312,13 @@ namespace DS4Windows
device.LightBarColor = getMainColor(Index); device.LightBarColor = getMainColor(Index);
device.Report += this.On_Report; device.Report += this.On_Report;
if (!getDInputOnly(Index)) if (!getDInputOnly(Index))
{
LogDebug("Plugging in X360 Controller #" + (x360Bus.FirstController + Index));
x360Bus.Plugin(Index); x360Bus.Plugin(Index);
}
TouchPadOn(Index, device); TouchPadOn(Index, device);
device.StartUpdate();
//string filename = Path.GetFileName(ProfilePath[Index]); //string filename = Path.GetFileName(ProfilePath[Index]);
if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml")) if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml"))
@ -664,7 +679,7 @@ namespace DS4Windows
} }
} }
public void EasterTime(int ind) /*public void EasterTime(int ind)
{ {
DS4State cState = CurrentState[ind]; DS4State cState = CurrentState[ind];
DS4StateExposed eState = ExposedState[ind]; DS4StateExposed eState = ExposedState[ind];
@ -743,6 +758,7 @@ namespace DS4Windows
else if (!pb) else if (!pb)
buttonsdown[ind] = false; buttonsdown[ind] = false;
} }
*/
public string GetInputkeys(int ind) public string GetInputkeys(int ind)
{ {

View File

@ -922,6 +922,7 @@ namespace DS4Windows
else if (btnStartStop.Text == Properties.Resources.StopText) else if (btnStartStop.Text == Properties.Resources.StopText)
{ {
blankControllerTab();
Program.rootHub.Stop(log); Program.rootHub.Stop(log);
hotkeysTimer.Stop(); hotkeysTimer.Stop();
btnStartStop.Text = Properties.Resources.StartText; btnStartStop.Text = Properties.Resources.StartText;
@ -938,7 +939,7 @@ namespace DS4Windows
bool skipHotplug = false; bool skipHotplug = false;
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
if (runHotPlug && !skipHotplug) if (runHotPlug)
{ {
try try
{ {
@ -1933,12 +1934,14 @@ namespace DS4Windows
e.Cancel = true; e.Cancel = true;
return; return;
} }
if (cBCloseMini.Checked && !contextclose) if (cBCloseMini.Checked && !contextclose)
{ {
this.WindowState = FormWindowState.Minimized; this.WindowState = FormWindowState.Minimized;
e.Cancel = true; e.Cancel = true;
return; return;
} }
if (systemShutdown) if (systemShutdown)
// Reset the variable because the user might cancel the // Reset the variable because the user might cancel the
// shutdown. // shutdown.
@ -1946,6 +1949,7 @@ namespace DS4Windows
systemShutdown = false; systemShutdown = false;
DS4LightBar.shuttingdown = true; DS4LightBar.shuttingdown = true;
} }
if (oldsize == new System.Drawing.Size(0, 0)) if (oldsize == new System.Drawing.Size(0, 0))
{ {
FormWidth = this.Width; FormWidth = this.Width;
@ -1956,9 +1960,11 @@ namespace DS4Windows
FormWidth = oldsize.Width; FormWidth = oldsize.Width;
FormHeight = oldsize.Height; FormHeight = oldsize.Height;
} }
if (!String.IsNullOrEmpty(appdatapath)) if (!String.IsNullOrEmpty(appdatapath))
{ {
Save(); Save();
blankControllerTab();
Program.rootHub.Stop(); Program.rootHub.Stop();
} }
} }

View File

@ -727,7 +727,7 @@ namespace DS4Windows
{ {
if (conType == ConnectionType.BT) if (conType == ConnectionType.BT)
{ {
if (DisconnectBT()) if (DisconnectBT(true))
return; // all done return; // all done
} }
else if (conType == ConnectionType.SONYWA) else if (conType == ConnectionType.SONYWA)
@ -837,7 +837,7 @@ namespace DS4Windows
} }
} }
public bool DisconnectBT() public bool DisconnectBT(bool callRemoval = false)
{ {
if (Mac != null) if (Mac != null)
{ {
@ -855,11 +855,15 @@ namespace DS4Windows
long lbtAddr = BitConverter.ToInt64(btAddr, 0); long lbtAddr = BitConverter.ToInt64(btAddr, 0);
bool success = false;
// Wait for output report to be written
lock (outputReport)
{
NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS p = new NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS(); NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS p = new NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS();
p.dwSize = Marshal.SizeOf(typeof(NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS)); p.dwSize = Marshal.SizeOf(typeof(NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS));
IntPtr searchHandle = NativeMethods.BluetoothFindFirstRadio(ref p, ref btHandle); IntPtr searchHandle = NativeMethods.BluetoothFindFirstRadio(ref p, ref btHandle);
int bytesReturned = 0; int bytesReturned = 0;
bool success = false;
while (!success && btHandle != IntPtr.Zero) while (!success && btHandle != IntPtr.Zero)
{ {
success = NativeMethods.DeviceIoControl(btHandle, IOCTL_BTH_DISCONNECT_DEVICE, ref lbtAddr, 8, IntPtr.Zero, 0, ref bytesReturned, IntPtr.Zero); success = NativeMethods.DeviceIoControl(btHandle, IOCTL_BTH_DISCONNECT_DEVICE, ref lbtAddr, 8, IntPtr.Zero, 0, ref bytesReturned, IntPtr.Zero);
@ -873,14 +877,18 @@ namespace DS4Windows
NativeMethods.BluetoothFindRadioClose(searchHandle); NativeMethods.BluetoothFindRadioClose(searchHandle);
Console.WriteLine("Disconnect successful: " + success); Console.WriteLine("Disconnect successful: " + success);
}
success = true; // XXX return value indicates failure, but it still works? success = true; // XXX return value indicates failure, but it still works?
if (success) if (success)
{ {
IsDisconnecting = true; IsDisconnecting = true;
StopOutputUpdate(); StopOutputUpdate();
if (Removal != null) if (callRemoval)
Removal(this, EventArgs.Empty); {
Removal?.Invoke(this, EventArgs.Empty);
}
} }
return success; return success;
@ -1040,5 +1048,10 @@ namespace DS4Windows
{ {
return Mac; return Mac;
} }
public void removeReportHandlers()
{
this.Report = null;
}
} }
} }

View File

@ -23,6 +23,7 @@ namespace DS4Windows
{ {
deviceInstanceId = deviceInstanceId.Remove(deviceInstanceId.Length - 1); deviceInstanceId = deviceInstanceId.Remove(deviceInstanceId.Length - 1);
} }
return deviceInstanceId; return deviceInstanceId;
} }
@ -102,7 +103,6 @@ namespace DS4Windows
ds4Device.Removal += On_Removal; ds4Device.Removal += On_Removal;
Devices.Add(ds4Device.MacAddress, ds4Device); Devices.Add(ds4Device.MacAddress, ds4Device);
DevicePaths.Add(hDevice.DevicePath); DevicePaths.Add(hDevice.DevicePath);
ds4Device.StartUpdate();
} }
} }
} }
@ -216,6 +216,8 @@ namespace DS4Windows
throw new Exception("Error enabling device, error code = " + Marshal.GetLastWin32Error()); throw new Exception("Error enabling device, error code = " + Marshal.GetLastWin32Error());
} }
System.Threading.Thread.Sleep(50);
NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet); NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet);
} }
} }