diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlSerivce.cs index c4fb59a..f9bfc8f 100644 --- a/DS4Windows/DS4Control/ControlSerivce.cs +++ b/DS4Windows/DS4Control/ControlSerivce.cs @@ -173,7 +173,16 @@ namespace DS4Windows if (DS4Controllers[i] != null) { if (DCBTatStop && !DS4Controllers[i].Charging && showlog) - DS4Controllers[i].DisconnectBT(); + { + if (DS4Controllers[i].ConnectionType == ConnectionType.BT) + { + DS4Controllers[i].DisconnectBT(); + } + else if (DS4Controllers[i].ConnectionType == ConnectionType.SONYWA) + { + DS4Controllers[i].DisconnectDongle(); + } + } else { DS4LightBar.forcelight[i] = false; diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 655424f..887dfec 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -863,7 +863,7 @@ namespace DS4Windows { case "USB": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.USB; toolTip1.SetToolTip(statPB[Index], ""); break; case "BT": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.BT; toolTip1.SetToolTip(statPB[Index], "Right click to disconnect"); break; - case "SONYWA": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.DS4_Config_PS; toolTip1.SetToolTip(statPB[Index], ""); break; + case "SONYWA": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.BT; toolTip1.SetToolTip(statPB[Index], "Right click to disconnect"); break; default: statPB[Index].Visible = false; toolTip1.SetToolTip(statPB[Index], ""); break; } Batteries[Index].Text = Program.rootHub.getDS4Battery(Index); @@ -911,6 +911,10 @@ namespace DS4Windows int i = Int32.Parse(((PictureBox)sender).Tag.ToString()); if (e.Button == System.Windows.Forms.MouseButtons.Right && Program.rootHub.getDS4Status(i) == "BT" && !Program.rootHub.DS4Controllers[i].Charging) Program.rootHub.DS4Controllers[i].DisconnectBT(); + else if (e.Button == System.Windows.Forms.MouseButtons.Right && Program.rootHub.getDS4Status(i) == "SONYWA" && !Program.rootHub.DS4Controllers[i].Charging) + { + Program.rootHub.DS4Controllers[i].DisconnectDongle(); + } } private void Enable_Controls(int device, bool on) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 0ce1348..3b2a119 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -270,13 +270,20 @@ namespace DS4Windows hDevice = hidDevice; conType = HidConnectionType(hDevice); Mac = hDevice.readSerial(); - if (conType == ConnectionType.USB) + if (conType == ConnectionType.USB || conType == ConnectionType.SONYWA) { inputReport = new byte[64]; inputReport2 = new byte[64]; outputReport = new byte[hDevice.Capabilities.OutputReportByteLength]; outputReportBuffer = new byte[hDevice.Capabilities.OutputReportByteLength]; - warnInterval = WARN_INTERVAL_USB; + if (conType == ConnectionType.USB) + { + warnInterval = WARN_INTERVAL_USB; + } + else + { + warnInterval = WARN_INTERVAL_BT; + } } else { @@ -752,6 +759,26 @@ namespace DS4Windows return false; } + public bool DisconnectDongle() + { + bool result = false; + byte[] disconnectReport = new byte[65]; + disconnectReport[0] = 0xe2; + disconnectReport[1] = 0x02; + for (int i = 2; i < 65; i++) + disconnectReport[i] = 0; + result = hDevice.WriteFeatureReport(disconnectReport); + if (result) + { + IsDisconnecting = true; + StopUpdate(); + if (Removal != null) + Removal(this, EventArgs.Empty); + } + + return result; + } + private DS4HapticState testRumble = new DS4HapticState(); public void setRumble(byte rightLightFastMotor, byte leftHeavySlowMotor) { diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index ef316f8..58f8877 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -83,7 +83,9 @@ namespace DS4Windows } if (hDevice.IsOpen) { - if (Devices.ContainsKey(hDevice.readSerial())) + string serial = hDevice.readSerial(); + bool validSerial = !serial.Equals("00:00:00:00:00:00"); + if (Devices.ContainsKey(serial)) continue; // happens when the BT endpoint already is open and the USB is plugged into the same host else { diff --git a/DS4Windows/HidLibrary/HidDevice.cs b/DS4Windows/HidLibrary/HidDevice.cs index 5698a7a..a7a865d 100644 --- a/DS4Windows/HidLibrary/HidDevice.cs +++ b/DS4Windows/HidLibrary/HidDevice.cs @@ -110,6 +110,17 @@ namespace DS4Windows return NativeMethods.HidD_GetInputReport(safeReadHandle, data, data.Length); } + public bool WriteFeatureReport(byte[] data) + { + bool result = false; + if (IsOpen && safeReadHandle != null) + { + result = NativeMethods.HidD_SetFeature(safeReadHandle, data, data.Length); + } + + return result; + } + private static HidDeviceAttributes GetDeviceAttributes(SafeFileHandle hidHandle) { @@ -266,7 +277,6 @@ namespace DS4Windows fileStream = new FileStream(safeReadHandle, FileAccess.ReadWrite, inputBuffer.Length, true); if (!safeReadHandle.IsInvalid && fileStream.CanRead) { - Task readTask = fileStream.ReadAsync(inputBuffer, 0, inputBuffer.Length); readTask.Wait(timeout); if (readTask.Result > 0)