mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-23 01:39:17 +01:00
Minor optimizations
This commit is contained in:
parent
9da0255529
commit
6f069482a2
@ -36,8 +36,8 @@ namespace DS4Windows
|
|||||||
public virtual void sixaxisMoved(SixAxisEventArgs arg)
|
public virtual void sixaxisMoved(SixAxisEventArgs arg)
|
||||||
{
|
{
|
||||||
int deltaX = 0, deltaY = 0;
|
int deltaX = 0, deltaY = 0;
|
||||||
deltaX = -arg.sixAxis.gyroXFull;
|
deltaX = -arg.sixAxis.gyroYawFull;
|
||||||
deltaY = -arg.sixAxis.gyroYFull;
|
deltaY = -arg.sixAxis.gyroPitchFull;
|
||||||
//Console.WriteLine(arg.sixAxis.deltaX);
|
//Console.WriteLine(arg.sixAxis.deltaX);
|
||||||
|
|
||||||
gyroSmooth = Global.getGyroSmoothing(deviceNumber);
|
gyroSmooth = Global.getGyroSmoothing(deviceNumber);
|
||||||
|
@ -1167,7 +1167,7 @@ namespace DS4Windows
|
|||||||
public double[] rainbow = { 0, 0, 0, 0, 0 };
|
public double[] rainbow = { 0, 0, 0, 0, 0 };
|
||||||
public int[] flashAt = { 0, 0, 0, 0, 0 };
|
public int[] flashAt = { 0, 0, 0, 0, 0 };
|
||||||
public bool[] mouseAccel = { true, true, true, true, true };
|
public bool[] mouseAccel = { true, true, true, true, true };
|
||||||
public int[] btPollRate = { 0, 0, 0, 0, 0 };
|
public int[] btPollRate = { 4, 4, 4, 4, 4 };
|
||||||
public int[] lsOutCurveMode = { 0, 0, 0, 0, 0 };
|
public int[] lsOutCurveMode = { 0, 0, 0, 0, 0 };
|
||||||
public int[] rsOutCurveMode = { 0, 0, 0, 0, 0 };
|
public int[] rsOutCurveMode = { 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
@ -2440,7 +2440,7 @@ namespace DS4Windows
|
|||||||
int.TryParse(Item.InnerText, out temp);
|
int.TryParse(Item.InnerText, out temp);
|
||||||
btPollRate[device] = (temp >= 0 && temp <= 16) ? temp : 0;
|
btPollRate[device] = (temp >= 0 && temp <= 16) ? temp : 0;
|
||||||
}
|
}
|
||||||
catch { btPollRate[device] = 0; missingSetting = true; }
|
catch { btPollRate[device] = 4; missingSetting = true; }
|
||||||
|
|
||||||
try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LSOutputCurveMode"); lsOutCurveMode[device] = outputCurveId(Item.InnerText); }
|
try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/LSOutputCurveMode"); lsOutCurveMode[device] = outputCurveId(Item.InnerText); }
|
||||||
catch { lsOutCurveMode[device] = 0; missingSetting = true; }
|
catch { lsOutCurveMode[device] = 0; missingSetting = true; }
|
||||||
@ -3449,7 +3449,7 @@ namespace DS4Windows
|
|||||||
rainbow[device] = 0;
|
rainbow[device] = 0;
|
||||||
flashAt[device] = 0;
|
flashAt[device] = 0;
|
||||||
mouseAccel[device] = true;
|
mouseAccel[device] = true;
|
||||||
btPollRate[device] = 0;
|
btPollRate[device] = 4;
|
||||||
|
|
||||||
m_LowLeds[device] = new DS4Color(Color.Black);
|
m_LowLeds[device] = new DS4Color(Color.Black);
|
||||||
|
|
||||||
|
@ -1701,7 +1701,7 @@ namespace DS4Windows
|
|||||||
private void Profile_Changed_Menu(object sender, ToolStripItemClickedEventArgs e)
|
private void Profile_Changed_Menu(object sender, ToolStripItemClickedEventArgs e)
|
||||||
{
|
{
|
||||||
ToolStripMenuItem tS = (ToolStripMenuItem)sender;
|
ToolStripMenuItem tS = (ToolStripMenuItem)sender;
|
||||||
int tdevice = Int32.Parse(tS.Tag.ToString());
|
int tdevice = Convert.ToInt32(tS.Tag);
|
||||||
if (!(e.ClickedItem is ToolStripSeparator))
|
if (!(e.ClickedItem is ToolStripSeparator))
|
||||||
{
|
{
|
||||||
if (e.ClickedItem != tS.DropDownItems[tS.DropDownItems.Count - 1]) //if +New Profile not selected
|
if (e.ClickedItem != tS.DropDownItems[tS.DropDownItems.Count - 1]) //if +New Profile not selected
|
||||||
@ -2223,6 +2223,9 @@ namespace DS4Windows
|
|||||||
blankControllerTab();
|
blankControllerTab();
|
||||||
Program.rootHub.Stop();
|
Program.rootHub.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure to stop event generation routines. Should fix odd crashes on shutdown
|
||||||
|
Application.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cBSwipeProfiles_CheckedChanged(object sender, EventArgs e)
|
private void cBSwipeProfiles_CheckedChanged(object sender, EventArgs e)
|
||||||
|
@ -133,7 +133,6 @@ namespace DS4Windows
|
|||||||
private byte[] accel = new byte[6];
|
private byte[] accel = new byte[6];
|
||||||
private byte[] gyro = new byte[6];
|
private byte[] gyro = new byte[6];
|
||||||
private byte[] inputReport;
|
private byte[] inputReport;
|
||||||
//private byte[] inputReport2;
|
|
||||||
private byte[] btInputReport = null;
|
private byte[] btInputReport = null;
|
||||||
private byte[] outputReportBuffer, outputReport;
|
private byte[] outputReportBuffer, outputReport;
|
||||||
private readonly DS4Touchpad touchpad = null;
|
private readonly DS4Touchpad touchpad = null;
|
||||||
@ -164,7 +163,7 @@ namespace DS4Windows
|
|||||||
public event EventHandler<EventArgs> Removal = null;
|
public event EventHandler<EventArgs> Removal = null;
|
||||||
public event EventHandler<EventArgs> SyncChange = null;
|
public event EventHandler<EventArgs> SyncChange = null;
|
||||||
public event EventHandler<EventArgs> SerialChange = null;
|
public event EventHandler<EventArgs> SerialChange = null;
|
||||||
public event EventHandler<EventArgs> PublishRemoval = null;
|
//public event EventHandler<EventArgs> PublishRemoval = null;
|
||||||
|
|
||||||
public HidDevice HidDevice => hDevice;
|
public HidDevice HidDevice => hDevice;
|
||||||
public bool IsExclusive => HidDevice.IsExclusive;
|
public bool IsExclusive => HidDevice.IsExclusive;
|
||||||
@ -415,7 +414,6 @@ namespace DS4Windows
|
|||||||
if (conType == ConnectionType.USB || conType == ConnectionType.SONYWA)
|
if (conType == ConnectionType.USB || conType == ConnectionType.SONYWA)
|
||||||
{
|
{
|
||||||
inputReport = new byte[64];
|
inputReport = 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)
|
if (conType == ConnectionType.USB)
|
||||||
@ -668,8 +666,6 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
oldCharging = charging;
|
oldCharging = charging;
|
||||||
currerror = string.Empty;
|
currerror = string.Empty;
|
||||||
curTimeDouble = sw.Elapsed.TotalMilliseconds;
|
|
||||||
curtime = sw.ElapsedMilliseconds;
|
|
||||||
|
|
||||||
if (tempLatencyCount >= 50)
|
if (tempLatencyCount >= 50)
|
||||||
{
|
{
|
||||||
@ -677,12 +673,9 @@ namespace DS4Windows
|
|||||||
tempLatencyCount--;
|
tempLatencyCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTimeElapsed = curtime - oldtime;
|
|
||||||
lastTimeElapsedDouble = (curTimeDouble - oldTimeDouble);
|
|
||||||
latencyQueue.Enqueue(this.lastTimeElapsed);
|
latencyQueue.Enqueue(this.lastTimeElapsed);
|
||||||
tempLatencyCount++;
|
tempLatencyCount++;
|
||||||
oldtime = curtime;
|
|
||||||
oldTimeDouble = curTimeDouble;
|
|
||||||
Latency = latencyQueue.Average();
|
Latency = latencyQueue.Average();
|
||||||
|
|
||||||
if (conType == ConnectionType.BT)
|
if (conType == ConnectionType.BT)
|
||||||
@ -691,7 +684,6 @@ namespace DS4Windows
|
|||||||
//HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT);
|
//HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT);
|
||||||
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(btInputReport);
|
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(btInputReport);
|
||||||
timeoutEvent = false;
|
timeoutEvent = false;
|
||||||
//HidDevice.ReadStatus res = hDevice.ReadFileOverlapped(btInputReport, READ_STREAM_TIMEOUT);
|
|
||||||
if (res == HidDevice.ReadStatus.Success)
|
if (res == HidDevice.ReadStatus.Success)
|
||||||
{
|
{
|
||||||
Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length);
|
Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length);
|
||||||
@ -705,7 +697,7 @@ namespace DS4Windows
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int winError = Marshal.GetLastWin32Error();
|
int winError = Marshal.GetLastWin32Error();
|
||||||
Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError);
|
Console.WriteLine(Mac.ToString() + " " + DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError);
|
||||||
//Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true);
|
//Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,7 +722,6 @@ namespace DS4Windows
|
|||||||
//Array.Clear(inputReport, 0, inputReport.Length);
|
//Array.Clear(inputReport, 0, inputReport.Length);
|
||||||
//HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT);
|
//HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT);
|
||||||
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(inputReport);
|
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(inputReport);
|
||||||
//HidDevice.ReadStatus res = hDevice.ReadFileOverlapped(inputReport, READ_STREAM_TIMEOUT);
|
|
||||||
if (res != HidDevice.ReadStatus.Success)
|
if (res != HidDevice.ReadStatus.Success)
|
||||||
{
|
{
|
||||||
if (res == HidDevice.ReadStatus.WaitTimedOut)
|
if (res == HidDevice.ReadStatus.WaitTimedOut)
|
||||||
@ -740,7 +731,7 @@ namespace DS4Windows
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int winError = Marshal.GetLastWin32Error();
|
int winError = Marshal.GetLastWin32Error();
|
||||||
Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError);
|
Console.WriteLine(Mac.ToString() + " " + DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError);
|
||||||
//Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true);
|
//Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,12 +748,17 @@ namespace DS4Windows
|
|||||||
timeoutExecuted = true;
|
timeoutExecuted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//Array.Copy(inputReport2, 0, inputReport, 0, inputReport.Length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curTimeDouble = sw.Elapsed.TotalMilliseconds;
|
||||||
|
curtime = sw.ElapsedMilliseconds;
|
||||||
|
|
||||||
|
lastTimeElapsed = curtime - oldtime;
|
||||||
|
lastTimeElapsedDouble = (curTimeDouble - oldTimeDouble);
|
||||||
|
|
||||||
|
oldtime = curtime;
|
||||||
|
oldTimeDouble = curTimeDouble;
|
||||||
|
|
||||||
if (conType == ConnectionType.BT && btInputReport[0] != 0x11)
|
if (conType == ConnectionType.BT && btInputReport[0] != 0x11)
|
||||||
{
|
{
|
||||||
//Received incorrect report, skip it
|
//Received incorrect report, skip it
|
||||||
@ -996,7 +992,7 @@ namespace DS4Windows
|
|||||||
//outputReportBuffer[1] = 0x80;
|
//outputReportBuffer[1] = 0x80;
|
||||||
//outputReportBuffer[1] = 0x84;
|
//outputReportBuffer[1] = 0x84;
|
||||||
outputReportBuffer[1] = (byte)(0x80 | btPollRate); // input report rate
|
outputReportBuffer[1] = (byte)(0x80 | btPollRate); // input report rate
|
||||||
// enable lightbar, rumble, flash
|
// enable rumble (0x01), lightbar (0x02), flash (0x04)
|
||||||
outputReportBuffer[3] = 0xf7;
|
outputReportBuffer[3] = 0xf7;
|
||||||
outputReportBuffer[6] = rightLightFastRumble; // fast motor
|
outputReportBuffer[6] = rightLightFastRumble; // fast motor
|
||||||
outputReportBuffer[7] = leftHeavySlowRumble; // slow motor
|
outputReportBuffer[7] = leftHeavySlowRumble; // slow motor
|
||||||
@ -1009,7 +1005,7 @@ namespace DS4Windows
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
outputReportBuffer[0] = 0x05;
|
outputReportBuffer[0] = 0x05;
|
||||||
// enable lightbar, rumble, flash
|
// enable rumble (0x01), lightbar (0x02), flash (0x04)
|
||||||
outputReportBuffer[1] = 0xf7;
|
outputReportBuffer[1] = 0xf7;
|
||||||
outputReportBuffer[4] = rightLightFastRumble; // fast motor
|
outputReportBuffer[4] = rightLightFastRumble; // fast motor
|
||||||
outputReportBuffer[5] = leftHeavySlowRumble; // slow motor
|
outputReportBuffer[5] = leftHeavySlowRumble; // slow motor
|
||||||
|
@ -16,7 +16,7 @@ namespace DS4Windows
|
|||||||
public class SixAxis
|
public class SixAxis
|
||||||
{
|
{
|
||||||
public readonly int gyroX, gyroY, gyroZ, deltaX, deltaY, deltaZ, accelX, accelY, accelZ;
|
public readonly int gyroX, gyroY, gyroZ, deltaX, deltaY, deltaZ, accelX, accelY, accelZ;
|
||||||
public readonly int gyroXFull, gyroYFull, gyroZFull;
|
public readonly int gyroYawFull, gyroPitchFull, gyroRollFull;
|
||||||
public readonly int accelXFull, accelYFull, accelZFull;
|
public readonly int accelXFull, accelYFull, accelZFull;
|
||||||
public readonly byte touchID;
|
public readonly byte touchID;
|
||||||
public readonly SixAxis previousAxis;
|
public readonly SixAxis previousAxis;
|
||||||
@ -25,9 +25,9 @@ namespace DS4Windows
|
|||||||
gyroX = X / 256;
|
gyroX = X / 256;
|
||||||
gyroY = Y / 256;
|
gyroY = Y / 256;
|
||||||
gyroZ = Z / 256;
|
gyroZ = Z / 256;
|
||||||
gyroXFull = X;
|
gyroYawFull = X;
|
||||||
gyroYFull = Y;
|
gyroPitchFull = Y;
|
||||||
gyroZFull = Z;
|
gyroRollFull = Z;
|
||||||
|
|
||||||
accelX = aX / 64;
|
accelX = aX / 64;
|
||||||
accelY = aY / 64;
|
accelY = aY / 64;
|
||||||
@ -56,42 +56,14 @@ namespace DS4Windows
|
|||||||
|
|
||||||
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state)
|
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state)
|
||||||
{
|
{
|
||||||
//bool touchPadIsDown = sensors.TouchButton;
|
int currentX = (short)((ushort)(gyro[3] << 8) | gyro[2]); // Gyro Yaw
|
||||||
/*if (!PacketChanged(data, touchPacketOffset) && touchPadIsDown == lastTouchPadIsDown)
|
int currentY = (short)((ushort)(gyro[1] << 8) | gyro[0]); // Gyro Pitch
|
||||||
{
|
|
||||||
if (SixAxisUnchanged != null)
|
|
||||||
SixAxisUnchanged(this, EventArgs.Empty);
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
/* byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);
|
|
||||||
byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);*/
|
|
||||||
|
|
||||||
int currentX = (short)((ushort)(gyro[3] << 8) | gyro[2]); // Gyro Pitch
|
|
||||||
int currentY = (short)((ushort)(gyro[1] << 8) | gyro[0]); // Gyro Yaw
|
|
||||||
int currentZ = (short)((ushort)(gyro[5] << 8) | gyro[4]); // Gyro Roll
|
int currentZ = (short)((ushort)(gyro[5] << 8) | gyro[4]); // Gyro Roll
|
||||||
int AccelX = (short)((ushort)(accel[1] << 8) | accel[0]); // Accel Pitch
|
int AccelX = (short)((ushort)(accel[1] << 8) | accel[0]);
|
||||||
int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]); // Accel Roll
|
int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]);
|
||||||
int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]); // Accel Yaw
|
int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]);
|
||||||
|
|
||||||
SixAxisEventArgs args;
|
SixAxisEventArgs args;
|
||||||
//if (sensors.Touch1 || sensors.Touch2)
|
|
||||||
{
|
|
||||||
/* if (SixAxisMoved != null)
|
|
||||||
{
|
|
||||||
SixAxis sPrev, now;
|
|
||||||
sPrev = new SixAxis(lastGyroX, lastGyroY, lastGyroZ, lastAX,lastAY,lastAZ);
|
|
||||||
now = new SixAxis(currentX, currentY, currentZ, AccelX, AccelY, AccelZ, sPrev);
|
|
||||||
args = new SixAxisEventArgs(state.ReportTimeStamp, now);
|
|
||||||
SixAxisMoved(this, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastGyroX = currentX;
|
|
||||||
lastGyroY = currentY;
|
|
||||||
lastGyroZ = currentZ;
|
|
||||||
lastAX = AccelX;
|
|
||||||
lastAY = AccelY;
|
|
||||||
lastAZ = AccelZ;*/
|
|
||||||
}
|
|
||||||
if (AccelX != 0 || AccelY != 0 || AccelZ != 0)
|
if (AccelX != 0 || AccelY != 0 || AccelZ != 0)
|
||||||
{
|
{
|
||||||
if (SixAccelMoved != null)
|
if (SixAccelMoved != null)
|
||||||
|
Loading…
Reference in New Issue
Block a user