From 44501c24de1cb9db8ce37526fa72099e0d58f3cc Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Wed, 26 Apr 2017 18:39:33 -0700 Subject: [PATCH] Revert back to old disconnect bluetooth behavior --- DS4Windows/DS4Control/Mapping.cs | 2 +- DS4Windows/DS4Library/DS4Device.cs | 23 +++++++++++------------ DS4Windows/DS4Library/DS4Devices.cs | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index d6b83dc..7cec265 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -1571,7 +1571,7 @@ namespace DS4Windows ConnectionType deviceConn = d.getConnectionType(); if (deviceConn == ConnectionType.BT) { - d.DisconnectBT(false); + d.DisconnectBT(); } //foreach (DS4Controls dc in action.trigger) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index cf0ddb2..b890ca5 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -726,7 +726,7 @@ namespace DS4Windows { if (conType == ConnectionType.BT) { - if (DisconnectBT(false)) + if (DisconnectBT()) return; // all done } else if (conType == ConnectionType.SONYWA) @@ -835,7 +835,7 @@ namespace DS4Windows } } - public bool DisconnectBT(bool allThreadsQuit = true) + public bool DisconnectBT() { if (Mac != null) { @@ -850,6 +850,7 @@ namespace DS4Windows //parse hex byte in reverse order btAddr[5 - i] = Convert.ToByte(sbytes[i], 16); } + long lbtAddr = BitConverter.ToInt64(btAddr, 0); NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS p = new NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS(); @@ -862,30 +863,27 @@ namespace DS4Windows success = NativeMethods.DeviceIoControl(btHandle, IOCTL_BTH_DISCONNECT_DEVICE, ref lbtAddr, 8, IntPtr.Zero, 0, ref bytesReturned, IntPtr.Zero); NativeMethods.CloseHandle(btHandle); if (!success) + { if (!NativeMethods.BluetoothFindNextRadio(searchHandle, ref btHandle)) btHandle = IntPtr.Zero; - + } } + NativeMethods.BluetoothFindRadioClose(searchHandle); Console.WriteLine("Disconnect successful: " + success); success = true; // XXX return value indicates failure, but it still works? - if(success) + if (success) { IsDisconnecting = true; - if (allThreadsQuit) - { - StopUpdate(); - } - else - { - StopOutputUpdate(); - } + StopOutputUpdate(); if (Removal != null) Removal(this, EventArgs.Empty); } + return success; } + return false; } @@ -902,6 +900,7 @@ namespace DS4Windows { isDisconnecting = true; StopOutputUpdate(); + if (Removal != null) Removal(this, EventArgs.Empty); } diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index 5354ab5..8b3570b 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -26,7 +26,7 @@ namespace DS4Windows return deviceInstanceId; } - //enumerates ds4 controllers in the system + // enumerates ds4 controllers in the system public static void findControllers() { lock (Devices)