Skip to content
This repository has been archived by the owner on Oct 24, 2021. It is now read-only.

Serguei #7

Open
wants to merge 20 commits into
base: jay
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3065353
Started work on a WPF version. Right now it's just a skeleton applica…
SergueiFedorov Feb 6, 2015
345a985
Adding the WCF stuff. Didn't get commited for some rason
SergueiFedorov Feb 6, 2015
b1d0a39
Starting the cleanup process
SergueiFedorov Feb 6, 2015
316bdfa
Revert "Started work on a WPF version. Right now it's just a skeleton…
SergueiFedorov Feb 6, 2015
fe462c2
Running through the options file and wrapping things into utility fun…
SergueiFedorov Feb 6, 2015
693d52a
Cleaned up the way the curves are processed. Needs to be moved into i…
SergueiFedorov Feb 6, 2015
789f4f1
Finished cleaning up ControllerReadout_Tick for now. Will revisit
SergueiFedorov Feb 6, 2015
c5e17be
Cleaned up the color bars. Could be cleaned up a little more
SergueiFedorov Feb 6, 2015
7e68b81
Cleaned up deadzone events
SergueiFedorov Feb 6, 2015
69567f6
More deadzone cleanup
SergueiFedorov Feb 6, 2015
b7ffbb3
Moved some of the redundent code into a utility class
SergueiFedorov Feb 6, 2015
1729280
Slowly starting to refactor the profile save into a consolidated system
SergueiFedorov Feb 6, 2015
6ee665a
Redid the way the system checks for auto profiles on start
SergueiFedorov Feb 6, 2015
6bceb51
Forgot to add a few files
SergueiFedorov Feb 6, 2015
e68232f
Cleaning all the serialization. It's not so easy to keep the same for…
SergueiFedorov Feb 7, 2015
933b696
Cleaned up the save system for profiles a little bit. It needs seriou…
SergueiFedorov Feb 7, 2015
f7074e1
Created a latency timer class. It is a circular buffer that replaces …
SergueiFedorov Feb 8, 2015
f22871a
Moving things around to be more organized. Messages are now pushed in…
SergueiFedorov Feb 8, 2015
a3b71ab
Removing the temporary key. It wasn't supposed to get commited to beg…
SergueiFedorov Feb 8, 2015
25f0eae
Moving DS4Library development into the DS4Library-Development branch
SergueiFedorov Feb 10, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions DS4Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Reflection;
using System.Media;
using DS4Control.Enums;
namespace DS4Control
{
public class Control
Expand Down Expand Up @@ -444,23 +445,40 @@ protected virtual void On_Report(object sender, EventArgs e)
{
if (Global.getFlushHIDQueue(ind))
device.FlushHID();
if (!string.IsNullOrEmpty(device.error))

//This shouldn't be altering the collection from outside.
//something to fix
while (device.currentErrors.Count() > 0)
{
LogDebug(device.error);
LogDebug(device.currentErrors[0]);
device.currentErrors.RemoveAt(0);
}

device.getExposedState(ExposedState[ind], CurrentState[ind]);
DS4State cState = CurrentState[ind];
device.getPreviousState(PreviousState[ind]);
DS4State pState = PreviousState[ind];

if (pState.Battery != cState.Battery)
{
Global.ControllerStatusChanged(this);
}

CheckForHotkeys(ind, cState, pState);
if (eastertime)
{
EasterTime(ind);
}

GetInputkeys(ind);

if (Global.getLSCurve(ind) + Global.getRSCurve(ind) + Global.getLSDeadzone(ind) + Global.getRSDeadzone(ind) +
Global.getL2Deadzone(ind) + Global.getR2Deadzone(ind) > 0) //if a curve or deadzone is in place
Global.getL2Deadzone(ind) + Global.getR2Deadzone(ind) > 0)
{
//if a curve or deadzone is in place
cState = Mapping.SetCurveAndDeadzone(ind, cState);
}

if (!recordingMacro && (!string.IsNullOrEmpty(Global.tempprofilename[ind]) ||
Global.getHasCustomKeysorButtons(ind) || Global.getHasShiftCustomKeysorButtons(ind) || Global.GetProfileActions(ind).Count > 0))
{
Expand Down Expand Up @@ -733,7 +751,9 @@ protected virtual void CheckForHotkeys(int deviceID, DS4State cState, DS4State p
}
}
else
touchreleased[deviceID] = true;
{
touchreleased[deviceID] = true;
}
}

public virtual void StartTPOff(int deviceID)
Expand All @@ -746,8 +766,8 @@ public virtual void StartTPOff(int deviceID)
Global.setScrollSensitivity(deviceID, 0);
}
}
public virtual string TouchpadSlide(int ind)

public virtual string TouchpadSlideString(int ind)
{
DS4State cState = CurrentState[ind];
string slidedir = "none";
Expand All @@ -771,6 +791,32 @@ public virtual string TouchpadSlide(int ind)
}
return slidedir;
}

public virtual TouchpadSlideDirections TouchpadSlideEnum(int ind)
{
DS4State cState = CurrentState[ind];
TouchpadSlideDirections slidedir = TouchpadSlideDirections.none;
if (DS4Controllers[ind] != null)
if (cState.Touch2)
if (DS4Controllers[ind] != null)
if (touchPad[ind].slideright && !touchslid[ind])
{
slidedir = TouchpadSlideDirections.right;
touchslid[ind] = true;
}
else if (touchPad[ind].slideleft && !touchslid[ind])
{
slidedir = TouchpadSlideDirections.left;
touchslid[ind] = true;
}
else if (!touchPad[ind].slideleft && !touchPad[ind].slideright)
{
slidedir = TouchpadSlideDirections.none;
touchslid[ind] = false;
}
return slidedir;
}

public virtual void LogDebug(String Data, bool warning = false)
{
Console.WriteLine(System.DateTime.Now.ToString("G") + "> " + Data);
Expand Down
5 changes: 5 additions & 0 deletions DS4Control/DS4Control.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Enums\TouchpadSlideDirections.cs" />
<Compile Include="Log.cs" />
<Compile Include="MouseCursor.cs" />
<Compile Include="MouseWheel.cs" />
Expand All @@ -57,6 +58,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Tools\XMLFile.cs" />
<Compile Include="X360Device.cs">
<SubType>Component</SubType>
</Compile>
Expand All @@ -79,6 +81,9 @@
<DependentUpon>ScpHub.cs</DependentUpon>
</Compile>
<Compile Include="ScpUtil.cs" />
<Compile Include="XML FIles\ControlXML.cs" />
<Compile Include="XML FIles\KeyXML.cs" />
<Compile Include="XML FIles\ProfileXML.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DS4Library\DS4Library.csproj">
Expand Down
15 changes: 15 additions & 0 deletions DS4Control/Enums/TouchpadSlideDirections.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DS4Control.Enums
{
public enum TouchpadSlideDirections
{
none = 0,
right,
left
}
}
128 changes: 98 additions & 30 deletions DS4Control/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void SavePrevious(bool performClear)
public static DateTime oldnow = DateTime.UtcNow;
private static bool pressagain = false;
private static int wheel = 0, keyshelddown = 0;

public static void Commit(int device)
{
SyntheticState state = deviceState[device];
Expand Down Expand Up @@ -329,20 +330,59 @@ static double TValue(double value1, double value2, double percent)
return value1 * percent + value2 * (1 - percent);
}

private static void ProccessCurveState(int curve, DS4State cState, DS4State dState)
{
int x = cState.LX;
int y = cState.LY;

float max = x + y;
double curvex;
double curvey;
//curve = Global.getLSCurve(device);
double multimax = TValue(382.5, max, curve);
double multimin = TValue(127.5, max, curve);
if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f))
{
curvex = (x > 127.5f ? Math.Min(x, (x / max) * multimax) : Math.Max(x, (x / max) * multimin));
curvey = (y > 127.5f ? Math.Min(y, (y / max) * multimax) : Math.Max(y, (y / max) * multimin));
//btnLSTrack.Location = new Point((int)(dpix * curvex / 2.09 + lbLSTrack.Location.X), (int)(dpiy * curvey / 2.09 + lbLSTrack.Location.Y));
}
else
{
if (x < 127.5f)
{
curvex = Math.Min(x, (x / max) * multimax);
curvey = Math.Min(y, (-(y / max) * multimax + 510));
}
else
{
curvex = Math.Min(x, (-(x / max) * multimax + 510));
curvey = Math.Min(y, (y / max) * multimax);
}
}

dState.LX = (byte)Math.Round(curvex, 0);
dState.LY = (byte)Math.Round(curvey, 0);
}

public static DS4State SetCurveAndDeadzone(int device, DS4State cState)
{
//Copy constructor...
DS4State dState = new DS4State(cState);
int x;
int y;

//int x;
//int y;
int curve;
if (Global.getLSCurve(device) > 0)
if ((curve = Global.getLSCurve(device)) > 0)
{

/*
x = cState.LX;
y = cState.LY;
float max = x + y;
double curvex;
double curvey;
curve = Global.getLSCurve(device);
//curve = Global.getLSCurve(device);
double multimax = TValue(382.5, max, curve);
double multimin = TValue(127.5, max, curve);
if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f))
Expand All @@ -365,10 +405,15 @@ public static DS4State SetCurveAndDeadzone(int device, DS4State cState)
}
}
dState.LX = (byte)Math.Round(curvex, 0);
dState.LY = (byte)Math.Round(curvey, 0);
dState.LY = (byte)Math.Round(curvey, 0);*/

ProccessCurveState(curve, cState, dState);
}
if (Global.getRSCurve(device) > 0)

if ((curve = Global.getRSCurve(device)) > 0)
{

/*
x = cState.RX;
y = cState.RY;
float max = x + y;
Expand All @@ -377,6 +422,7 @@ public static DS4State SetCurveAndDeadzone(int device, DS4State cState)
curve = Global.getRSCurve(device);
double multimax = TValue(382.5, max, curve);
double multimin = TValue(127.5, max, curve);

if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f))
{
curvex = (x > 127.5f ? Math.Min(x, (x / max) * multimax) : Math.Max(x, (x / max) * multimin));
Expand All @@ -396,30 +442,37 @@ public static DS4State SetCurveAndDeadzone(int device, DS4State cState)
}
}
dState.RX = (byte)Math.Round(curvex, 0);
dState.RY = (byte)Math.Round(curvey, 0);
dState.RY = (byte)Math.Round(curvey, 0);*/

ProccessCurveState(curve, cState, dState);
}

if (Global.getLSDeadzone(device) > 0 &&
Math.Sqrt(Math.Pow(cState.LX - 127.5f, 2) + Math.Pow(cState.LY - 127.5f, 2)) < Global.getLSDeadzone(device))
{
dState.LX = 127;
dState.LY = 127;
}

if (Global.getRSDeadzone(device) > 0
&& Math.Sqrt(Math.Pow(cState.RX - 127.5f, 2) + Math.Pow(cState.RY - 127.5f, 2)) < Global.getLSDeadzone(device))
{
dState.RX = 127;
dState.RY = 127;
}

if (Global.getL2Deadzone(device) > 0 && cState.L2 < Global.getL2Deadzone(device))
dState.L2 = 0;
if (Global.getR2Deadzone(device) > 0 && cState.R2 < Global.getR2Deadzone(device))
dState.R2 = 0;

return dState;
}

public static bool[] pressedonce = new bool[261], macrodone = new bool[34];
public static int test = 0;
static bool[] macroControl = new bool[25];

/// <summary>
/// Map DS4 Buttons/Axes to other DS4 Buttons/Axes (largely the same as Xinput ones) and to keyboard and mouse buttons.
/// </summary>
Expand Down Expand Up @@ -463,7 +516,10 @@ public static async void MapCustom(int device, DS4State cState, DS4State MappedS
}
cState.CopyTo(MappedState);
if (shift)
MapShiftCustom(device, cState, MappedState, eState, tp);
{
MapShiftCustom(device, cState, MappedState, eState, tp);
}

foreach (KeyValuePair<DS4Controls, string> customKey in Global.getCustomMacros(device))
{
if (shift == false ||
Expand Down Expand Up @@ -497,27 +553,34 @@ public static async void MapCustom(int device, DS4State cState, DS4State MappedS
if (!macrodone[DS4ControltoInt(customKey.Key)])
{
macrodone[DS4ControltoInt(customKey.Key)] = true;

for (int i = 0; i < keys.Length; i++)
{
if (keys[i] >= 300) //ints over 300 used to delay
{
await Task.Delay(keys[i] - 300);
}
else if (!keydown[keys[i]])
{
if (keys[i] == 256) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_LEFTDOWN); //anything above 255 is not a keyvalue
if (keys[i] == 256)
{
InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_LEFTDOWN); //anything above 255 is not a keyvalue
}

else if (keys[i] == 257) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_RIGHTDOWN);
else if (keys[i] == 258) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_MIDDLEDOWN);
else if (keys[i] == 259) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONDOWN, 1);
else if (keys[i] == 260) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONDOWN, 2);
else if (keys[i] == 261) macroControl[0] = true;
else if (keys[i] == 262) macroControl[1] = true;
else if (keys[i] == 263) macroControl[2] = true;
else if (keys[i] == 264) macroControl[3] = true;
else if (keys[i] == 265) macroControl[4] = true;
else if (keys[i] == 266) macroControl[5] = true;
else if (keys[i] == 267) macroControl[6] = true;
else if (keys[i] == 268) macroControl[7] = true;
else if (keys[i] == 269) macroControl[8] = true;
else if (keys[i] == 270) macroControl[9] = true;
else if (keys[i] == 261) macroControl[0] = true;
else if (keys[i] == 262) macroControl[1] = true;
else if (keys[i] == 263) macroControl[2] = true;
else if (keys[i] == 264) macroControl[3] = true;
else if (keys[i] == 265) macroControl[4] = true;
else if (keys[i] == 266) macroControl[5] = true;
else if (keys[i] == 267) macroControl[6] = true;
else if (keys[i] == 268) macroControl[7] = true;
else if (keys[i] == 269) macroControl[8] = true;
else if (keys[i] == 270) macroControl[9] = true;
else if (keys[i] == 271) macroControl[10] = true;
else if (keys[i] == 272) macroControl[11] = true;
else if (keys[i] == 273) macroControl[12] = true;
Expand All @@ -541,21 +604,25 @@ public static async void MapCustom(int device, DS4State cState, DS4State MappedS
}
else
{
if (keys[i] == 256) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_LEFTUP); //anything above 255 is not a keyvalue
if (keys[i] == 256)
{
InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_LEFTUP); //anything above 255 is not a keyvalue
}

else if (keys[i] == 257) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_RIGHTUP);
else if (keys[i] == 258) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_MIDDLEUP);
else if (keys[i] == 259) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 1);
else if (keys[i] == 260) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 2);
else if (keys[i] == 261) macroControl[0] = false;
else if (keys[i] == 262) macroControl[1] = false;
else if (keys[i] == 263) macroControl[2] = false;
else if (keys[i] == 264) macroControl[3] = false;
else if (keys[i] == 265) macroControl[4] = false;
else if (keys[i] == 266) macroControl[5] = false;
else if (keys[i] == 267) macroControl[6] = false;
else if (keys[i] == 268) macroControl[7] = false;
else if (keys[i] == 269) macroControl[8] = false;
else if (keys[i] == 270) macroControl[9] = false;
else if (keys[i] == 261) macroControl[0] = false;
else if (keys[i] == 262) macroControl[1] = false;
else if (keys[i] == 263) macroControl[2] = false;
else if (keys[i] == 264) macroControl[3] = false;
else if (keys[i] == 265) macroControl[4] = false;
else if (keys[i] == 266) macroControl[5] = false;
else if (keys[i] == 267) macroControl[6] = false;
else if (keys[i] == 268) macroControl[7] = false;
else if (keys[i] == 269) macroControl[8] = false;
else if (keys[i] == 270) macroControl[9] = false;
else if (keys[i] == 271) macroControl[10] = false;
else if (keys[i] == 272) macroControl[11] = false;
else if (keys[i] == 273) macroControl[12] = false;
Expand Down Expand Up @@ -695,6 +762,7 @@ public static async void MapCustom(int device, DS4State cState, DS4State MappedS
List<DS4Controls> RXP = new List<DS4Controls>();
List<DS4Controls> RYN = new List<DS4Controls>();
List<DS4Controls> RYP = new List<DS4Controls>();

foreach (KeyValuePair<DS4Controls, X360Controls> customButton in Global.getCustomButtons(device))
{
if (shift == false ||
Expand Down
1 change: 1 addition & 0 deletions DS4Control/MouseWheel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void touchesMoved(TouchpadEventArgs arg)
//mouse wheel 120 == 1 wheel click according to Windows API
double lastMidX = (lastT0.hwX + lastT1.hwX) / 2d, lastMidY = (lastT0.hwY + lastT1.hwY) / 2d,
currentMidX = (T0.hwX + T1.hwX) / 2d, currentMidY = (T0.hwY + T1.hwY) / 2d;

double coefficient = Global.getScrollSensitivity(deviceNumber);
// Adjust for touch distance: "standard" distance is 960 pixels, i.e. half the width. Scroll farther if fingers are farther apart, and vice versa, in linear proportion.
double touchXDistance = T1.hwX - T0.hwX, touchYDistance = T1.hwY - T0.hwY, touchDistance = Math.Sqrt(touchXDistance * touchXDistance + touchYDistance * touchYDistance);
Expand Down
Loading