Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rajkosto/DS4Windows into …
Browse files Browse the repository at this point in the history
…udpserver
  • Loading branch information
rajkosto committed Sep 18, 2017
2 parents c0f7d7c + 21f36c4 commit df7e8c3
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 115 deletions.
28 changes: 15 additions & 13 deletions DS4Windows/DS4Control/ControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ControlService
List<DS4Controls> dcs = new List<DS4Controls>();
bool[] held = new bool[DS4_CONTROLLER_COUNT];
int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 };
Thread tempThread;
//SoundPlayer sp = new SoundPlayer();
private UdpServer _udpServer;

Expand Down Expand Up @@ -110,12 +111,16 @@ public ControlService()
{
//sp.Stream = Properties.Resources.EE;
// Cause thread affinity to not be tied to main GUI thread
Thread x360Thread = new Thread(() => { x360Bus = new X360Device(); });
x360Thread.IsBackground = true;
x360Thread.Priority = ThreadPriority.Normal;
x360Thread.Name = "SCP Virtual Bus Thread";
x360Thread.Start();
while (!x360Thread.ThreadState.HasFlag(ThreadState.Stopped))
/*Task x360task = new Task(() => { Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; x360Bus = new X360Device(); });
x360task.Start();
while (!x360task.IsCompleted)
Thread.SpinWait(500);
*/
tempThread = new Thread(() => { x360Bus = new X360Device(); });
tempThread.Priority = ThreadPriority.AboveNormal;
tempThread.IsBackground = true;
tempThread.Start();
while (tempThread.IsAlive)
{
Thread.SpinWait(500);
}
Expand Down Expand Up @@ -298,7 +303,6 @@ public bool Start(object tempui, bool showlog = true)
}

runHotPlug = true;

return true;
}

Expand Down Expand Up @@ -872,9 +876,7 @@ protected virtual void On_Report(object sender, EventArgs e)
}

if (getEnableTouchToggle(ind))
{
CheckForTouchToggle(ind, cState, pState);
}

cState = Mapping.SetCurveAndDeadzone(ind, cState);

Expand Down Expand Up @@ -1025,19 +1027,19 @@ protected virtual void CheckForTouchToggle(int deviceID, DS4State cState, DS4Sta
oldscrollvalue[deviceID] = getScrollSensitivity(deviceID);
getTouchSensitivity()[deviceID] = 0;
getScrollSensitivity()[deviceID] = 0;
LogDebug(getTouchSensitivity(deviceID) > 0 ? Properties.Resources.TouchpadMovementOn :
LogDebug(oldtouchvalue[deviceID] > 0 ? Properties.Resources.TouchpadMovementOn :
Properties.Resources.TouchpadMovementOff);
Log.LogToTray(getTouchSensitivity(deviceID) > 0 ? Properties.Resources.TouchpadMovementOn :
Log.LogToTray(oldtouchvalue[deviceID] > 0 ? Properties.Resources.TouchpadMovementOn :
Properties.Resources.TouchpadMovementOff);
touchreleased[deviceID] = false;
}
else if (touchreleased[deviceID])
{
getTouchSensitivity()[deviceID] = oldtouchvalue[deviceID];
getScrollSensitivity()[deviceID] = oldscrollvalue[deviceID];
LogDebug(getTouchSensitivity(deviceID) > 0 ? Properties.Resources.TouchpadMovementOn :
LogDebug(oldtouchvalue[deviceID] > 0 ? Properties.Resources.TouchpadMovementOn :
Properties.Resources.TouchpadMovementOff);
Log.LogToTray(getTouchSensitivity(deviceID) > 0 ? Properties.Resources.TouchpadMovementOn :
Log.LogToTray(oldtouchvalue[deviceID] > 0 ? Properties.Resources.TouchpadMovementOn :
Properties.Resources.TouchpadMovementOff);
touchreleased[deviceID] = false;
}
Expand Down
41 changes: 21 additions & 20 deletions DS4Windows/DS4Control/MouseCursor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using System;

namespace DS4Windows
{
class MouseCursor
Expand Down Expand Up @@ -63,11 +64,11 @@ public virtual void sixaxisMoved(SixAxisEventArgs arg)
}
}

double tempAngle = System.Math.Atan2(-deltaY, deltaX);
double normX = System.Math.Abs(System.Math.Cos(tempAngle));
double normY = System.Math.Abs(System.Math.Sin(tempAngle));
int signX = System.Math.Sign(deltaX);
int signY = System.Math.Sign(deltaY);
double tempAngle = Math.Atan2(-deltaY, deltaX);
double normX = Math.Abs(Math.Cos(tempAngle));
double normY = Math.Abs(Math.Sin(tempAngle));
int signX = Math.Sign(deltaX);
int signY = Math.Sign(deltaY);

if (deltaX == 0 || (hRemainder > 0 != deltaX > 0))
{
Expand All @@ -79,10 +80,10 @@ public virtual void sixaxisMoved(SixAxisEventArgs arg)
vRemainder = 0.0;
}

int deadzoneX = (int)System.Math.Abs(normX * GYRO_MOUSE_DEADZONE);
int deadzoneY = (int)System.Math.Abs(normY * GYRO_MOUSE_DEADZONE);
int deadzoneX = (int)Math.Abs(normX * GYRO_MOUSE_DEADZONE);
int deadzoneY = (int)Math.Abs(normY * GYRO_MOUSE_DEADZONE);

if (System.Math.Abs(deltaX) > deadzoneX)
if (Math.Abs(deltaX) > deadzoneX)
{
deltaX -= signX * deadzoneX;
}
Expand All @@ -91,7 +92,7 @@ public virtual void sixaxisMoved(SixAxisEventArgs arg)
deltaX = 0;
}

if (System.Math.Abs(deltaY) > deadzoneY)
if (Math.Abs(deltaY) > deadzoneY)
{
deltaY -= signY * deadzoneY;
}
Expand Down Expand Up @@ -140,7 +141,7 @@ public virtual void sixaxisMoved(SixAxisEventArgs arg)
int idx = 0;
for (int i = 0; i < SMOOTH_BUFFER_LEN; i++)
{
idx = System.Math.Abs(smoothBufferTail - i - 1) % SMOOTH_BUFFER_LEN;
idx = Math.Abs(smoothBufferTail - i - 1) % SMOOTH_BUFFER_LEN;
x_out += xSmoothBuffer[idx] * currentWeight;
y_out += ySmoothBuffer[idx] * currentWeight;
finalWeight += currentWeight;
Expand Down Expand Up @@ -227,11 +228,11 @@ public void touchesMoved(TouchpadEventArgs arg, bool dragging, bool disableInver
}
}

double tempAngle = System.Math.Atan2(-deltaY, deltaX);
double normX = System.Math.Abs(System.Math.Cos(tempAngle));
double normY = System.Math.Abs(System.Math.Sin(tempAngle));
int signX = System.Math.Sign(deltaX);
int signY = System.Math.Sign(deltaY);
double tempAngle = Math.Atan2(-deltaY, deltaX);
double normX = Math.Abs(Math.Cos(tempAngle));
double normY = Math.Abs(Math.Sin(tempAngle));
int signX = Math.Sign(deltaX);
int signY = Math.Sign(deltaY);
double coefficient = Global.getTouchSensitivity(deviceNumber) * 0.01;
bool jitterCompenstation = Global.getTouchpadJitterCompensation(deviceNumber);

Expand All @@ -243,16 +244,16 @@ public void touchesMoved(TouchpadEventArgs arg, bool dragging, bool disableInver

if (jitterCompenstation)
{
double absX = System.Math.Abs(xMotion);
double absX = Math.Abs(xMotion);
if (absX <= normX * 0.4)
{
xMotion = signX * System.Math.Pow(absX / 0.4f, 1.44) * 0.4;
xMotion = signX * Math.Pow(absX / 0.4f, 1.44) * 0.4;
}

double absY = System.Math.Abs(yMotion);
double absY = Math.Abs(yMotion);
if (absY <= normY * 0.4)
{
yMotion = signY * System.Math.Pow(absY / 0.4f, 1.44) * 0.4;
yMotion = signY * Math.Pow(absY / 0.4f, 1.44) * 0.4;
}
}

Expand Down
Loading

0 comments on commit df7e8c3

Please sign in to comment.