Allow disconnect routines to work with Sony Dongle.

The main routine was made by aspalmer.
This commit is contained in:
Travis Nickles 2017-04-05 18:37:38 -07:00
parent bfbcc15df5
commit 5c74a00d90
5 changed files with 58 additions and 6 deletions

View File

@ -173,7 +173,16 @@ namespace DS4Windows
if (DS4Controllers[i] != null) if (DS4Controllers[i] != null)
{ {
if (DCBTatStop && !DS4Controllers[i].Charging && showlog) if (DCBTatStop && !DS4Controllers[i].Charging && showlog)
{
if (DS4Controllers[i].ConnectionType == ConnectionType.BT)
{
DS4Controllers[i].DisconnectBT(); DS4Controllers[i].DisconnectBT();
}
else if (DS4Controllers[i].ConnectionType == ConnectionType.SONYWA)
{
DS4Controllers[i].DisconnectDongle();
}
}
else else
{ {
DS4LightBar.forcelight[i] = false; DS4LightBar.forcelight[i] = false;

View File

@ -863,7 +863,7 @@ namespace DS4Windows
{ {
case "USB": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.USB; toolTip1.SetToolTip(statPB[Index], ""); break; 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 "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; default: statPB[Index].Visible = false; toolTip1.SetToolTip(statPB[Index], ""); break;
} }
Batteries[Index].Text = Program.rootHub.getDS4Battery(Index); Batteries[Index].Text = Program.rootHub.getDS4Battery(Index);
@ -911,6 +911,10 @@ namespace DS4Windows
int i = Int32.Parse(((PictureBox)sender).Tag.ToString()); 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) if (e.Button == System.Windows.Forms.MouseButtons.Right && Program.rootHub.getDS4Status(i) == "BT" && !Program.rootHub.DS4Controllers[i].Charging)
Program.rootHub.DS4Controllers[i].DisconnectBT(); 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) private void Enable_Controls(int device, bool on)

View File

@ -270,15 +270,22 @@ namespace DS4Windows
hDevice = hidDevice; hDevice = hidDevice;
conType = HidConnectionType(hDevice); conType = HidConnectionType(hDevice);
Mac = hDevice.readSerial(); Mac = hDevice.readSerial();
if (conType == ConnectionType.USB) if (conType == ConnectionType.USB || conType == ConnectionType.SONYWA)
{ {
inputReport = new byte[64]; inputReport = new byte[64];
inputReport2 = new byte[64]; inputReport2 = new byte[64];
outputReport = new byte[hDevice.Capabilities.OutputReportByteLength]; outputReport = new byte[hDevice.Capabilities.OutputReportByteLength];
outputReportBuffer = new byte[hDevice.Capabilities.OutputReportByteLength]; outputReportBuffer = new byte[hDevice.Capabilities.OutputReportByteLength];
if (conType == ConnectionType.USB)
{
warnInterval = WARN_INTERVAL_USB; warnInterval = WARN_INTERVAL_USB;
} }
else else
{
warnInterval = WARN_INTERVAL_BT;
}
}
else
{ {
btInputReport = new byte[BT_INPUT_REPORT_LENGTH]; btInputReport = new byte[BT_INPUT_REPORT_LENGTH];
inputReport = new byte[btInputReport.Length - 2]; inputReport = new byte[btInputReport.Length - 2];
@ -752,6 +759,26 @@ namespace DS4Windows
return false; 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(); private DS4HapticState testRumble = new DS4HapticState();
public void setRumble(byte rightLightFastMotor, byte leftHeavySlowMotor) public void setRumble(byte rightLightFastMotor, byte leftHeavySlowMotor)
{ {

View File

@ -83,7 +83,9 @@ namespace DS4Windows
} }
if (hDevice.IsOpen) 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 continue; // happens when the BT endpoint already is open and the USB is plugged into the same host
else else
{ {

View File

@ -110,6 +110,17 @@ namespace DS4Windows
return NativeMethods.HidD_GetInputReport(safeReadHandle, data, data.Length); 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) private static HidDeviceAttributes GetDeviceAttributes(SafeFileHandle hidHandle)
{ {
@ -266,7 +277,6 @@ namespace DS4Windows
fileStream = new FileStream(safeReadHandle, FileAccess.ReadWrite, inputBuffer.Length, true); fileStream = new FileStream(safeReadHandle, FileAccess.ReadWrite, inputBuffer.Length, true);
if (!safeReadHandle.IsInvalid && fileStream.CanRead) if (!safeReadHandle.IsInvalid && fileStream.CanRead)
{ {
Task<int> readTask = fileStream.ReadAsync(inputBuffer, 0, inputBuffer.Length); Task<int> readTask = fileStream.ReadAsync(inputBuffer, 0, inputBuffer.Length);
readTask.Wait(timeout); readTask.Wait(timeout);
if (readTask.Result > 0) if (readTask.Result > 0)