Minor optimizations

This commit is contained in:
Travis Nickles 2017-07-12 08:04:37 -05:00
parent 9da0255529
commit 6f069482a2
5 changed files with 33 additions and 62 deletions

View File

@ -36,8 +36,8 @@ namespace DS4Windows
public virtual void sixaxisMoved(SixAxisEventArgs arg)
{
int deltaX = 0, deltaY = 0;
deltaX = -arg.sixAxis.gyroXFull;
deltaY = -arg.sixAxis.gyroYFull;
deltaX = -arg.sixAxis.gyroYawFull;
deltaY = -arg.sixAxis.gyroPitchFull;
//Console.WriteLine(arg.sixAxis.deltaX);
gyroSmooth = Global.getGyroSmoothing(deviceNumber);

View File

@ -1167,7 +1167,7 @@ namespace DS4Windows
public double[] rainbow = { 0, 0, 0, 0, 0 };
public int[] flashAt = { 0, 0, 0, 0, 0 };
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[] rsOutCurveMode = { 0, 0, 0, 0, 0 };
@ -2440,7 +2440,7 @@ namespace DS4Windows
int.TryParse(Item.InnerText, out temp);
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); }
catch { lsOutCurveMode[device] = 0; missingSetting = true; }
@ -3449,7 +3449,7 @@ namespace DS4Windows
rainbow[device] = 0;
flashAt[device] = 0;
mouseAccel[device] = true;
btPollRate[device] = 0;
btPollRate[device] = 4;
m_LowLeds[device] = new DS4Color(Color.Black);

View File

@ -1701,7 +1701,7 @@ namespace DS4Windows
private void Profile_Changed_Menu(object sender, ToolStripItemClickedEventArgs e)
{
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 != tS.DropDownItems[tS.DropDownItems.Count - 1]) //if +New Profile not selected
@ -2223,6 +2223,9 @@ namespace DS4Windows
blankControllerTab();
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)

View File

@ -133,7 +133,6 @@ namespace DS4Windows
private byte[] accel = new byte[6];
private byte[] gyro = new byte[6];
private byte[] inputReport;
//private byte[] inputReport2;
private byte[] btInputReport = null;
private byte[] outputReportBuffer, outputReport;
private readonly DS4Touchpad touchpad = null;
@ -164,7 +163,7 @@ namespace DS4Windows
public event EventHandler<EventArgs> Removal = null;
public event EventHandler<EventArgs> SyncChange = null;
public event EventHandler<EventArgs> SerialChange = null;
public event EventHandler<EventArgs> PublishRemoval = null;
//public event EventHandler<EventArgs> PublishRemoval = null;
public HidDevice HidDevice => hDevice;
public bool IsExclusive => HidDevice.IsExclusive;
@ -415,7 +414,6 @@ namespace DS4Windows
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];
if (conType == ConnectionType.USB)
@ -668,8 +666,6 @@ namespace DS4Windows
{
oldCharging = charging;
currerror = string.Empty;
curTimeDouble = sw.Elapsed.TotalMilliseconds;
curtime = sw.ElapsedMilliseconds;
if (tempLatencyCount >= 50)
{
@ -677,12 +673,9 @@ namespace DS4Windows
tempLatencyCount--;
}
lastTimeElapsed = curtime - oldtime;
lastTimeElapsedDouble = (curTimeDouble - oldTimeDouble);
latencyQueue.Enqueue(this.lastTimeElapsed);
tempLatencyCount++;
oldtime = curtime;
oldTimeDouble = curTimeDouble;
Latency = latencyQueue.Average();
if (conType == ConnectionType.BT)
@ -691,7 +684,6 @@ namespace DS4Windows
//HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT);
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(btInputReport);
timeoutEvent = false;
//HidDevice.ReadStatus res = hDevice.ReadFileOverlapped(btInputReport, READ_STREAM_TIMEOUT);
if (res == HidDevice.ReadStatus.Success)
{
Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length);
@ -705,7 +697,7 @@ namespace DS4Windows
else
{
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);
}
@ -730,7 +722,6 @@ namespace DS4Windows
//Array.Clear(inputReport, 0, inputReport.Length);
//HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT);
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(inputReport);
//HidDevice.ReadStatus res = hDevice.ReadFileOverlapped(inputReport, READ_STREAM_TIMEOUT);
if (res != HidDevice.ReadStatus.Success)
{
if (res == HidDevice.ReadStatus.WaitTimedOut)
@ -740,7 +731,7 @@ namespace DS4Windows
else
{
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);
}
@ -757,12 +748,17 @@ namespace DS4Windows
timeoutExecuted = true;
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)
{
//Received incorrect report, skip it
@ -996,7 +992,7 @@ namespace DS4Windows
//outputReportBuffer[1] = 0x80;
//outputReportBuffer[1] = 0x84;
outputReportBuffer[1] = (byte)(0x80 | btPollRate); // input report rate
// enable lightbar, rumble, flash
// enable rumble (0x01), lightbar (0x02), flash (0x04)
outputReportBuffer[3] = 0xf7;
outputReportBuffer[6] = rightLightFastRumble; // fast motor
outputReportBuffer[7] = leftHeavySlowRumble; // slow motor
@ -1009,7 +1005,7 @@ namespace DS4Windows
else
{
outputReportBuffer[0] = 0x05;
// enable lightbar, rumble, flash
// enable rumble (0x01), lightbar (0x02), flash (0x04)
outputReportBuffer[1] = 0xf7;
outputReportBuffer[4] = rightLightFastRumble; // fast motor
outputReportBuffer[5] = leftHeavySlowRumble; // slow motor

View File

@ -16,7 +16,7 @@ namespace DS4Windows
public class SixAxis
{
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 byte touchID;
public readonly SixAxis previousAxis;
@ -25,9 +25,9 @@ namespace DS4Windows
gyroX = X / 256;
gyroY = Y / 256;
gyroZ = Z / 256;
gyroXFull = X;
gyroYFull = Y;
gyroZFull = Z;
gyroYawFull = X;
gyroPitchFull = Y;
gyroRollFull = Z;
accelX = aX / 64;
accelY = aY / 64;
@ -56,42 +56,14 @@ namespace DS4Windows
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state)
{
//bool touchPadIsDown = sensors.TouchButton;
/*if (!PacketChanged(data, touchPacketOffset) && touchPadIsDown == lastTouchPadIsDown)
{
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 currentX = (short)((ushort)(gyro[3] << 8) | gyro[2]); // Gyro Yaw
int currentY = (short)((ushort)(gyro[1] << 8) | gyro[0]); // Gyro Pitch
int currentZ = (short)((ushort)(gyro[5] << 8) | gyro[4]); // Gyro Roll
int AccelX = (short)((ushort)(accel[1] << 8) | accel[0]); // Accel Pitch
int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]); // Accel Roll
int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]); // Accel Yaw
int AccelX = (short)((ushort)(accel[1] << 8) | accel[0]);
int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]);
int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]);
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 (SixAccelMoved != null)