mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-26 02:54:20 +01:00
Allow disconnect routines to work with Sony Dongle.
The main routine was made by aspalmer.
This commit is contained in:
parent
bfbcc15df5
commit
5c74a00d90
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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<int> readTask = fileStream.ReadAsync(inputBuffer, 0, inputBuffer.Length);
|
||||
readTask.Wait(timeout);
|
||||
if (readTask.Result > 0)
|
||||
|
Loading…
Reference in New Issue
Block a user