Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Minor style changes and excess removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Apr 22, 2017
1 parent 52c5fde commit 23ee6f9
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 80 deletions.
62 changes: 0 additions & 62 deletions DS4Windows/DS4Control/ControlSerivce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@
using static DS4Windows.Global;
namespace DS4Windows
{
/*public class DS4ControlInfo
{
public enum ControlType { Unknown = 0, Button, AxisDir, Trigger, Touch, GyroDir, SwipeDir }
public DS4Controls control = DS4Controls.None;
public ControlType mappedType = ControlType.Unknown;
public DS4ControlInfo(DS4Controls control, ControlType mappedType)
{
this.control = control;
this.mappedType = mappedType;
}
}
*/

public class ControlService
{
public X360Device x360Bus;
Expand All @@ -41,8 +27,6 @@ public class ControlService
private int eCode = 0;
bool[] buttonsdown = { false, false, false, false };
List<DS4Controls> dcs = new List<DS4Controls>();
//Dictionary<DS4Controls, DS4ControlInfo> controlInfoDir =
// new Dictionary<DS4Controls, DS4ControlInfo>();
bool[] held = new bool[DS4_CONTROLLER_COUNT];
int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 };
SoundPlayer sp = new SoundPlayer();
Expand All @@ -60,7 +44,6 @@ public ControlService()
sp.Stream = Properties.Resources.EE;
x360Bus = new X360Device();
AddtoDS4List();
//populateControlInfoDictionary();

for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
{
Expand Down Expand Up @@ -105,51 +88,6 @@ void AddtoDS4List()
dcs.Add(DS4Controls.SwipeRight);
}

/*void populateControlInfoDictionary()
{
controlInfoDir.Add(DS4Controls.Cross, new DS4ControlInfo(DS4Controls.Cross, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.Circle, new DS4ControlInfo(DS4Controls.Circle, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.Square, new DS4ControlInfo(DS4Controls.Square, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.Triangle, new DS4ControlInfo(DS4Controls.Triangle, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.Options, new DS4ControlInfo(DS4Controls.Options, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.Share, new DS4ControlInfo(DS4Controls.Share, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.DpadUp, new DS4ControlInfo(DS4Controls.DpadUp, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.DpadDown, new DS4ControlInfo(DS4Controls.DpadDown, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.DpadLeft, new DS4ControlInfo(DS4Controls.DpadLeft, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.DpadRight, new DS4ControlInfo(DS4Controls.DpadRight, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.PS, new DS4ControlInfo(DS4Controls.PS, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.L1, new DS4ControlInfo(DS4Controls.L1, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.R1, new DS4ControlInfo(DS4Controls.R1, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.L2, new DS4ControlInfo(DS4Controls.L2, DS4ControlInfo.ControlType.Trigger));
controlInfoDir.Add(DS4Controls.R2, new DS4ControlInfo(DS4Controls.R2, DS4ControlInfo.ControlType.Trigger));
controlInfoDir.Add(DS4Controls.L3, new DS4ControlInfo(DS4Controls.L3, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.R3, new DS4ControlInfo(DS4Controls.R3, DS4ControlInfo.ControlType.Button));
controlInfoDir.Add(DS4Controls.LXPos, new DS4ControlInfo(DS4Controls.LXPos, DS4ControlInfo.ControlType.AxisDir));
controlInfoDir.Add(DS4Controls.LXNeg, new DS4ControlInfo(DS4Controls.LXNeg, DS4ControlInfo.ControlType.AxisDir));
controlInfoDir.Add(DS4Controls.LYPos, new DS4ControlInfo(DS4Controls.LYPos, DS4ControlInfo.ControlType.AxisDir));
controlInfoDir.Add(DS4Controls.LYNeg, new DS4ControlInfo(DS4Controls.LYNeg, DS4ControlInfo.ControlType.AxisDir));
controlInfoDir.Add(DS4Controls.RXPos, new DS4ControlInfo(DS4Controls.RXPos, DS4ControlInfo.ControlType.AxisDir));
controlInfoDir.Add(DS4Controls.RXNeg, new DS4ControlInfo(DS4Controls.RXNeg, DS4ControlInfo.ControlType.AxisDir));
controlInfoDir.Add(DS4Controls.RYPos, new DS4ControlInfo(DS4Controls.RYPos, DS4ControlInfo.ControlType.AxisDir));
controlInfoDir.Add(DS4Controls.RYNeg, new DS4ControlInfo(DS4Controls.RYNeg, DS4ControlInfo.ControlType.AxisDir));
controlInfoDir.Add(DS4Controls.SwipeUp, new DS4ControlInfo(DS4Controls.SwipeUp, DS4ControlInfo.ControlType.SwipeDir));
controlInfoDir.Add(DS4Controls.SwipeDown, new DS4ControlInfo(DS4Controls.SwipeDown, DS4ControlInfo.ControlType.SwipeDir));
controlInfoDir.Add(DS4Controls.SwipeLeft, new DS4ControlInfo(DS4Controls.SwipeLeft, DS4ControlInfo.ControlType.SwipeDir));
controlInfoDir.Add(DS4Controls.SwipeRight, new DS4ControlInfo(DS4Controls.SwipeRight, DS4ControlInfo.ControlType.SwipeDir));
controlInfoDir.Add(DS4Controls.TouchLeft, new DS4ControlInfo(DS4Controls.TouchLeft, DS4ControlInfo.ControlType.Touch));
controlInfoDir.Add(DS4Controls.TouchUpper, new DS4ControlInfo(DS4Controls.TouchUpper, DS4ControlInfo.ControlType.Touch));
controlInfoDir.Add(DS4Controls.TouchMulti, new DS4ControlInfo(DS4Controls.TouchMulti, DS4ControlInfo.ControlType.Touch));
controlInfoDir.Add(DS4Controls.TouchRight, new DS4ControlInfo(DS4Controls.TouchRight, DS4ControlInfo.ControlType.Touch));
controlInfoDir.Add(DS4Controls.GyroXPos, new DS4ControlInfo(DS4Controls.GyroXPos, DS4ControlInfo.ControlType.GyroDir));
controlInfoDir.Add(DS4Controls.GyroXNeg, new DS4ControlInfo(DS4Controls.GyroXNeg, DS4ControlInfo.ControlType.GyroDir));
controlInfoDir.Add(DS4Controls.GyroZPos, new DS4ControlInfo(DS4Controls.GyroZPos, DS4ControlInfo.ControlType.GyroDir));
controlInfoDir.Add(DS4Controls.GyroZNeg, new DS4ControlInfo(DS4Controls.GyroZNeg, DS4ControlInfo.ControlType.GyroDir));
}
*/

private async void WarnExclusiveModeFailure(DS4Device device)
{
if (DS4Devices.isExclusiveMode && !device.IsExclusive)
Expand Down
2 changes: 1 addition & 1 deletion DS4Windows/DS4Control/DS4StateFieldMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace DS4Windows
{
class DS4StateFieldMapping
public class DS4StateFieldMapping
{
public enum ControlType { Unknown = 0, Button, AxisDir, Trigger, Touch, GyroDir, SwipeDir }

Expand Down
98 changes: 81 additions & 17 deletions DS4Windows/DS4Control/ScpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,11 @@ public static void RemoveAction(string name)
public static int GetActionIndexOf(string name)
{
for (int i = 0, actionCount = m_Config.actions.Count; i < actionCount; i++)
{
if (m_Config.actions[i].name == name)
return i;
}

return -1;
}

Expand Down Expand Up @@ -798,7 +801,7 @@ public class BackingStore
public bool[] mouseAccel = { true, true, true, true, true };
public DS4Color[] m_LowLeds = new DS4Color[]
{
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
Expand All @@ -814,15 +817,15 @@ public class BackingStore
};
public DS4Color[] m_ChargingLeds = new DS4Color[]
{
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
};
public DS4Color[] m_FlashLeds = new DS4Color[]
{
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
Expand All @@ -831,7 +834,7 @@ public class BackingStore
public bool[] useCustomLeds = new bool[] { false, false, false, false };
public DS4Color[] m_CustomLeds = new DS4Color[]
{
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
Expand Down Expand Up @@ -891,8 +894,11 @@ public BackingStore()
for (int i = 0; i < 5; i++)
{
foreach (DS4Controls dc in Enum.GetValues(typeof(DS4Controls)))
{
if (dc != DS4Controls.None)
ds4settings[i].Add(new DS4ControlSettings(dc));
}

/*customMapKeyTypes[i] = new Dictionary<DS4Controls, DS4KeyType>();
customMapKeys[i] = new Dictionary<DS4Controls, UInt16>();
customMapMacros[i] = new Dictionary<DS4Controls, String>();
Expand All @@ -904,6 +910,7 @@ public BackingStore()
shiftCustomMapMacros[i] = new Dictionary<DS4Controls, String>();
shiftCustomMapButtons[i] = new Dictionary<DS4Controls, X360Controls>();
shiftCustomMapExtras[i] = new Dictionary<DS4Controls, string>();*/

profileActions[i] = new List<string>();
profileActions[i].Add("Disconnect Controller");
profileActionCount[i] = profileActions[i].Count;
Expand Down Expand Up @@ -2490,12 +2497,18 @@ public void UpdateDS4CSetting(int deviceNum, string buttonName, bool shift, obje
dc = getDS4ControlsByName(buttonName);
else
dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true);
foreach (DS4ControlSettings dcs in ds4settings[deviceNum])

//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.control == dc)
{
dcs.UpdateSettings(shift, action, exts, kt, trigger);
break;
}
}
}

public void UpdateDS4CExtra(int deviceNum, string buttonName, bool shift, string exts)
Expand All @@ -2505,15 +2518,22 @@ public void UpdateDS4CExtra(int deviceNum, string buttonName, bool shift, string
dc = getDS4ControlsByName(buttonName);
else
dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true);
foreach (DS4ControlSettings dcs in ds4settings[deviceNum])

//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.control == dc)
{
if (shift)
dcs.shiftExtras = exts;
else
dcs.extras = exts;

break;
}
}
}

private void UpdateDS4CKeyType(int deviceNum, string buttonName, bool shift, DS4KeyType keyType)
Expand All @@ -2523,15 +2543,22 @@ private void UpdateDS4CKeyType(int deviceNum, string buttonName, bool shift, DS4
dc = getDS4ControlsByName(buttonName);
else
dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true);
foreach (DS4ControlSettings dcs in ds4settings[deviceNum])

//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.control == dc)
{
if (shift)
dcs.shiftKeyType = keyType;
else
dcs.keyType = keyType;

break;
}
}
}

public object GetDS4Action(int deviceNum, string buttonName, bool shift)
Expand All @@ -2541,14 +2568,21 @@ public object GetDS4Action(int deviceNum, string buttonName, bool shift)
dc = getDS4ControlsByName(buttonName);
else
dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true);
foreach (DS4ControlSettings dcs in ds4settings[deviceNum])

//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.control == dc)
{
if (shift)
return dcs.shiftAction;
else
return dcs.action;
}
}

return null;
}

Expand Down Expand Up @@ -2579,14 +2613,21 @@ public string GetDS4Extra(int deviceNum, string buttonName, bool shift)
dc = getDS4ControlsByName(buttonName);
else
dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true);
foreach (DS4ControlSettings dcs in ds4settings[deviceNum])

//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.control == dc)
{
if (shift)
return dcs.shiftExtras;
else
return dcs.extras;
}
}

return null;
}

Expand All @@ -2597,14 +2638,21 @@ public DS4KeyType GetDS4KeyType(int deviceNum, string buttonName, bool shift)
dc = getDS4ControlsByName(buttonName);
else
dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true);
foreach (DS4ControlSettings dcs in ds4settings[deviceNum])

//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.control == dc)
{
if (shift)
return dcs.shiftKeyType;
else
return dcs.keyType;
}
}

return DS4KeyType.None;
}

Expand All @@ -2615,9 +2663,16 @@ public int GetDS4STrigger(int deviceNum, string buttonName)
dc = getDS4ControlsByName(buttonName);
else
dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true);
foreach (DS4ControlSettings dcs in ds4settings[deviceNum])

//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.control == dc)
return dcs.shiftTrigger;
return dcs.shiftTrigger;
}

return 0;
}

Expand All @@ -2641,9 +2696,16 @@ public DS4ControlSettings getDS4CSetting(int deviceNum, string buttonName)
dc = getDS4ControlsByName(buttonName);
else
dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true);
foreach (DS4ControlSettings dcs in ds4settings[deviceNum])

//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.control == dc)
return dcs;
}

return null;
}

Expand All @@ -2663,9 +2725,10 @@ public DS4ControlSettings getDS4CSetting(int deviceNum, DS4Controls dc)
public bool HasCustomActions(int deviceNum)
{
//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
for (int i = 0, listLen = ds4settings[deviceNum].Count; i < listLen; i++)
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settings[deviceNum][i];
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.action != null || dcs.shiftAction != null)
return true;
}
Expand All @@ -2677,9 +2740,10 @@ public bool HasCustomActions(int deviceNum)
public bool HasCustomExtras(int deviceNum)
{
//foreach (DS4ControlSettings dcs in ds4settings[deviceNum])
for (int i = 0, listLen = ds4settings[deviceNum].Count; i < listLen; i++)
List<DS4ControlSettings> ds4settingsList = ds4settings[deviceNum];
for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++)
{
DS4ControlSettings dcs = ds4settings[deviceNum][i];
DS4ControlSettings dcs = ds4settingsList[i];
if (dcs.extras != null || dcs.shiftExtras != null)
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions DS4Windows/DS4Library/DS4Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ public DS4Device(HidDevice hidDevice)
outputReportBuffer = new byte[BT_OUTPUT_REPORT_LENGTH];
warnInterval = WARN_INTERVAL_BT;
}

touchpad = new DS4Touchpad();
sixAxis = new DS4SixAxis();
}
Expand Down Expand Up @@ -500,9 +501,11 @@ public bool IsAlive()
{
return priorInputReport30 != 0xff;
}

private byte priorInputReport30 = 0xff;
public double Latency = 0;
public string error;

private void performDs4Input()
{
firstActive = DateTime.UtcNow;
Expand Down Expand Up @@ -736,6 +739,7 @@ private void sendOutputReport(bool synchronous)
{
setTestRumble();
setHapticState();

if (conType == ConnectionType.BT)
{
outputReportBuffer[0] = 0x11;
Expand Down

0 comments on commit 23ee6f9

Please sign in to comment.