Skip to content

Commit

Permalink
Merge branch 'Ryochan7:jay' into jay
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohoki authored Jul 3, 2021
2 parents 8fb02ce + d48dd9d commit 8a11577
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 162 deletions.
195 changes: 44 additions & 151 deletions DS4Windows/DS4Control/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public void Reset()
private static bool stickWheelDownDir = false;

//mapcustom
public static bool[] pressedonce = new bool[2400], macrodone = new bool[40];
public static bool[] pressedonce = new bool[2400], macrodone = new bool[48];
static bool[] macroControl = new bool[26];
static uint macroCount = 0;
static Dictionary<string, Task>[] macroTaskQueue = new Dictionary<string, Task>[Global.MAX_DS4_CONTROLLER_COUNT] { new Dictionary<string, Task>(), new Dictionary<string, Task>(), new Dictionary<string, Task>(), new Dictionary<string, Task>(), new Dictionary<string, Task>(), new Dictionary<string, Task>(), new Dictionary<string, Task>(), new Dictionary<string, Task>() };
Expand Down Expand Up @@ -2343,7 +2343,7 @@ public static void MapCustom(int device, DS4State cState, DS4State MappedState,
const byte axisDead = 128;
DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[tempOutControl];
bool alt = controlType == DS4StateFieldMapping.ControlType.AxisDir && tempOutControl % 2 == 0 ? true : false;
byte axisMapping = getXYAxisMapping2(device, tempMap.ds4input, cState, eState, tp, fieldMapping, alt);
byte axisMapping = GetXYAxisMapping2(device, tempMap.ds4input, cState, eState, tp, fieldMapping, alt);
if (axisMapping != axisDead)
{
int controlRelation = tempOutControl % 2 == 0 ? tempOutControl - 1 : tempOutControl + 1;
Expand All @@ -2356,7 +2356,7 @@ public static void MapCustom(int device, DS4State cState, DS4State MappedState,
if (tempMap.xoutput == DS4Controls.L2 || tempMap.xoutput == DS4Controls.R2)
{
const byte axisZero = 0;
byte axisMapping = getByteMapping2(device, tempMap.ds4input, cState, eState, tp, fieldMapping);
byte axisMapping = GetByteMapping2(device, tempMap.ds4input, cState, eState, tp, fieldMapping);
if (axisMapping != axisZero)
outputfieldMapping.triggers[tempOutControl] = axisMapping;
}
Expand Down Expand Up @@ -2890,19 +2890,19 @@ private static void ProcessControlSettingAction(DS4ControlSettings dcs, int devi
ushort value = Convert.ToUInt16(action.actionKey);
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
{
SyntheticState.KeyPresses kp;
if (!deviceState.keyPresses.TryGetValue(value, out kp))
{
deviceState.keyPresses[value] = kp = new SyntheticState.KeyPresses();
deviceState.nativeKeyAlias[value] = (ushort)actionAlias;
}
SyntheticState.KeyPresses kp;
if (!deviceState.keyPresses.TryGetValue(value, out kp))
{
deviceState.keyPresses[value] = kp = new SyntheticState.KeyPresses();
deviceState.nativeKeyAlias[value] = (ushort)actionAlias;
}

if (keyType.HasFlag(DS4KeyType.ScanCode))
kp.current.scanCodeCount++;
else
kp.current.vkCount++;
if (keyType.HasFlag(DS4KeyType.ScanCode))
kp.current.scanCodeCount++;
else
kp.current.vkCount++;

if (keyType.HasFlag(DS4KeyType.Toggle))
if (keyType.HasFlag(DS4KeyType.Toggle))
{
if (!pressedonce[value])
{
Expand Down Expand Up @@ -3007,7 +3007,7 @@ private static void ProcessControlSettingAction(DS4ControlSettings dcs, int devi
stickWheelDownDir = !stickWheelDownDir;
}

getMouseWheelMapping(device, dcs.control, cState, eState, tp, false);
GetMouseWheelMapping(device, dcs.control, cState, eState, tp, fieldMapping, false);
}
else
{
Expand All @@ -3029,7 +3029,7 @@ private static void ProcessControlSettingAction(DS4ControlSettings dcs, int devi
stickWheelDownDir = !stickWheelDownDir;
}

getMouseWheelMapping(device, dcs.control, cState, eState, tp, true);
GetMouseWheelMapping(device, dcs.control, cState, eState, tp, fieldMapping, true);
}
else
{
Expand Down Expand Up @@ -4159,19 +4159,18 @@ private static void AltTabSwappingRelease()
}
}

private static void getMouseWheelMapping(int device, DS4Controls control, DS4State cState,
DS4StateExposed eState, Mouse tp, bool down)
private static void GetMouseWheelMapping(int device, DS4Controls control, DS4State cState,
DS4StateExposed eState, Mouse tp, DS4StateFieldMapping fieldMap, bool down)
{
DateTime now = DateTime.UtcNow;
if (now >= oldnow + TimeSpan.FromMilliseconds(10) && !pressagain)
{
oldnow = now;
byte value = getByteMapping(device, control, cState, eState, tp);
int dirMax = value >= 128 ? 127 : 128;
int dirValue = value - 128;
byte value = GetByteMapping2(device, control, cState, eState, tp, fieldMap);
int wheelDir = down ? Global.outputKBMMapping.WHEEL_TICK_DOWN :
Global.outputKBMMapping.WHEEL_TICK_UP;
double ratio = Math.Abs(dirValue / (double)dirMax);
double ratio = value / 255.0;
//Debug.WriteLine(value);

// Use 4 runs as a full mouse wheel tick
double currentWheel = ratio / 4.0;
Expand Down Expand Up @@ -4489,7 +4488,17 @@ public static bool compare(byte b1, byte b2)
return result;
}

private static byte getByteMapping2(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp,
/// <summary>
/// Translate input value and output a virtual trigger value (0-255, neutral 0)
/// </summary>
/// <param name="device">Input slot number for DS4Device</param>
/// <param name="control">Current control mapped</param>
/// <param name="cState">Current input state</param>
/// <param name="eState">Exposed input state helper</param>
/// <param name="tp">Mouse object</param>
/// <param name="fieldMap">DS4StateFieldMapping instance for current MapCustom run</param>
/// <returns></returns>
private static byte GetByteMapping2(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp,
DS4StateFieldMapping fieldMap)
{
byte result = 0;
Expand Down Expand Up @@ -4562,133 +4571,6 @@ private static byte getByteMapping2(int device, DS4Controls control, DS4State cS
return result;
}

public static byte getByteMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
{
byte result = 0;

if (control >= DS4Controls.Square && control <= DS4Controls.Cross)
{
switch (control)
{
case DS4Controls.Cross: result = (byte)(cState.Cross ? 255 : 0); break;
case DS4Controls.Square: result = (byte)(cState.Square ? 255 : 0); break;
case DS4Controls.Triangle: result = (byte)(cState.Triangle ? 255 : 0); break;
case DS4Controls.Circle: result = (byte)(cState.Circle ? 255 : 0); break;
default: break;
}
}
else if (control >= DS4Controls.L1 && control <= DS4Controls.R3)
{
switch (control)
{
case DS4Controls.L1: result = (byte)(cState.L1 ? 255 : 0); break;
case DS4Controls.L2: result = cState.L2; break;
case DS4Controls.L3: result = (byte)(cState.L3 ? 255 : 0); break;
case DS4Controls.R1: result = (byte)(cState.R1 ? 255 : 0); break;
case DS4Controls.R2: result = cState.R2; break;
case DS4Controls.R3: result = (byte)(cState.R3 ? 255 : 0); break;
default: break;
}
}
else if (control >= DS4Controls.DpadUp && control <= DS4Controls.DpadLeft)
{
switch (control)
{
case DS4Controls.DpadUp: result = (byte)(cState.DpadUp ? 255 : 0); break;
case DS4Controls.DpadDown: result = (byte)(cState.DpadDown ? 255 : 0); break;
case DS4Controls.DpadLeft: result = (byte)(cState.DpadLeft ? 255 : 0); break;
case DS4Controls.DpadRight: result = (byte)(cState.DpadRight ? 255 : 0); break;
default: break;
}
}
else if (control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos)
{
switch (control)
{
case DS4Controls.LXNeg: result = (byte)(cState.LX - 128.0f >= 0 ? 0 : -(cState.LX - 128.0f) * 1.9921875f); break;
case DS4Controls.LYNeg: result = (byte)(cState.LY - 128.0f >= 0 ? 0 : -(cState.LY - 128.0f) * 1.9921875f); break;
case DS4Controls.RXNeg: result = (byte)(cState.RX - 128.0f >= 0 ? 0 : -(cState.RX - 128.0f) * 1.9921875f); break;
case DS4Controls.RYNeg: result = (byte)(cState.RY - 128.0f >= 0 ? 0 : -(cState.RY - 128.0f) * 1.9921875f); break;
case DS4Controls.LXPos: result = (byte)(cState.LX - 128.0f < 0 ? 0 : (cState.LX - 128.0f) * 2.0078740157480315f); break;
case DS4Controls.LYPos: result = (byte)(cState.LY - 128.0f < 0 ? 0 : (cState.LY - 128.0f) * 2.0078740157480315f); break;
case DS4Controls.RXPos: result = (byte)(cState.RX - 128.0f < 0 ? 0 : (cState.RX - 128.0f) * 2.0078740157480315f); break;
case DS4Controls.RYPos: result = (byte)(cState.RY - 128.0f < 0 ? 0 : (cState.RY - 128.0f) * 2.0078740157480315f); break;
default: break;
}
}
else if (control >= DS4Controls.TouchLeft && control <= DS4Controls.TouchRight)
{
switch (control)
{
case DS4Controls.TouchLeft: result = (byte)(tp != null && tp.leftDown ? 255 : 0); break;
case DS4Controls.TouchRight: result = (byte)(tp != null && tp.rightDown ? 255 : 0); break;
case DS4Controls.TouchMulti: result = (byte)(tp != null && tp.multiDown ? 255 : 0); break;
case DS4Controls.TouchUpper: result = (byte)(tp != null && tp.upperDown ? 255 : 0); break;
default: break;
}
}
else if (control >= DS4Controls.SwipeLeft && control <= DS4Controls.SwipeDown)
{
switch (control)
{
case DS4Controls.SwipeUp: result = (byte)(tp != null ? tp.swipeUpB : 0); break;
case DS4Controls.SwipeDown: result = (byte)(tp != null ? tp.swipeDownB : 0); break;
case DS4Controls.SwipeLeft: result = (byte)(tp != null ? tp.swipeLeftB : 0); break;
case DS4Controls.SwipeRight: result = (byte)(tp != null ? tp.swipeRightB : 0); break;
default: break;
}
}
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
{
double SXD = getSXDeadzone(device);
double SZD = getSZDeadzone(device);
bool saControls = IsUsingSAForControls(device);
double sxsens = getSXSens(device);
double szsens = getSZSens(device);

switch (control)
{
case DS4Controls.GyroXPos:
{
int gyroX = -eState.AccelX;
result = (byte)(saControls && sxsens * gyroX > SXD * 10 ? Math.Min(255, sxsens * gyroX * 2) : 0);
break;
}
case DS4Controls.GyroXNeg:
{
int gyroX = -eState.AccelX;
result = (byte)(saControls && sxsens * gyroX < -SXD * 10 ? Math.Min(255, sxsens * -gyroX * 2) : 0);
break;
}
case DS4Controls.GyroZPos:
{
int gyroZ = eState.AccelZ;
result = (byte)(saControls && szsens * gyroZ > SZD * 10 ? Math.Min(255, szsens * gyroZ * 2) : 0);
break;
}
case DS4Controls.GyroZNeg:
{
int gyroZ = eState.AccelZ;
result = (byte)(saControls && szsens * gyroZ < -SZD * 10 ? Math.Min(255, szsens * -gyroZ * 2) : 0);
break;
}
default: break;
}
}
else
{
switch (control)
{
case DS4Controls.Share: result = (byte)(cState.Share ? 255 : 0); break;
case DS4Controls.Options: result = (byte)(cState.Options ? 255 : 0); break;
case DS4Controls.PS: result = (byte)(cState.PS ? 255 : 0); break;
default: break;
}
}

return result;
}

/* TODO: Possibly remove usage of this version of the method */
public static bool getBoolMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
{
Expand Down Expand Up @@ -5023,7 +4905,18 @@ public static bool getBoolTouchMapping(bool touchButton)
return touchButton;
}

private static byte getXYAxisMapping2(int device, DS4Controls control, DS4State cState,
/// <summary>
/// Translate input value and output as a stick axis value (0-255, neutral 128)
/// </summary>
/// <param name="device">Input slot number for DS4Device</param>
/// <param name="control">Current control mapped</param>
/// <param name="cState">Current input state</param>
/// <param name="eState">Exposed input state helper</param>
/// <param name="tp">Mouse object</param>
/// <param name="fieldMap">DS4StateFieldMapping instance for current MapCustom run</param>
/// <param name="alt">Consider output a positive axis value</param>
/// <returns></returns>
private static byte GetXYAxisMapping2(int device, DS4Controls control, DS4State cState,
DS4StateExposed eState, Mouse tp, DS4StateFieldMapping fieldMap, bool alt = false)
{
const byte falseVal = 128;
Expand Down
7 changes: 5 additions & 2 deletions DS4Windows/DS4Control/Mouse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
//using System.Diagnostics;

namespace DS4Windows
{
Expand Down Expand Up @@ -492,8 +493,10 @@ private void SixMouseStick(SixAxisEventArgs arg)
if (msinfo.maxOutputEnabled)
{
double maxOutRatio = msinfo.maxOutput / 100.0;
double maxOutXRatio = normX * maxOutRatio;
double maxOutYRatio = normY * maxOutRatio;
// Expand output a bit. Likely not going to get a straight line with Gyro
double maxOutXRatio = Math.Min(normX / 0.99, 1.0) * maxOutRatio;
double maxOutYRatio = Math.Min(normY / 0.99, 1.0) * maxOutRatio;

xratio = Math.Min(Math.Max(xratio, 0.0), maxOutXRatio);
yratio = Math.Min(Math.Max(yratio, 0.0), maxOutYRatio);
}
Expand Down
4 changes: 2 additions & 2 deletions DS4Windows/DS4Control/ScpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3481,8 +3481,8 @@ public bool SaveProfile(int device, string proName)
XmlNode xmlRSVerticalScale = m_Xdoc.CreateNode(XmlNodeType.Element, "RSVerticalScale", null); xmlRSVerticalScale.InnerText = rsModInfo[device].verticalScale.ToString(); rootElement.AppendChild(xmlRSVerticalScale);
XmlNode xmlLSMaxOutput = m_Xdoc.CreateNode(XmlNodeType.Element, "LSMaxOutput", null); xmlLSMaxOutput.InnerText = lsModInfo[device].maxOutput.ToString(); rootElement.AppendChild(xmlLSMaxOutput);
XmlNode xmlRSMaxOutput = m_Xdoc.CreateNode(XmlNodeType.Element, "RSMaxOutput", null); xmlRSMaxOutput.InnerText = rsModInfo[device].maxOutput.ToString(); rootElement.AppendChild(xmlRSMaxOutput);
XmlNode xmlLSMaxOutputForce = m_Xdoc.CreateNode(XmlNodeType.Element, "LSMaxOutputForce", null); xmlLSMaxOutput.InnerText = lsModInfo[device].maxOutputForce.ToString(); rootElement.AppendChild(xmlLSMaxOutputForce);
XmlNode xmlRSMaxOutputForce = m_Xdoc.CreateNode(XmlNodeType.Element, "RSMaxOutputForce", null); xmlRSMaxOutput.InnerText = rsModInfo[device].maxOutputForce.ToString(); rootElement.AppendChild(xmlRSMaxOutputForce);
XmlNode xmlLSMaxOutputForce = m_Xdoc.CreateNode(XmlNodeType.Element, "LSMaxOutputForce", null); xmlLSMaxOutputForce.InnerText = lsModInfo[device].maxOutputForce.ToString(); rootElement.AppendChild(xmlLSMaxOutputForce);
XmlNode xmlRSMaxOutputForce = m_Xdoc.CreateNode(XmlNodeType.Element, "RSMaxOutputForce", null); xmlRSMaxOutputForce.InnerText = rsModInfo[device].maxOutputForce.ToString(); rootElement.AppendChild(xmlRSMaxOutputForce);
XmlNode xmlLSDeadZoneType = m_Xdoc.CreateNode(XmlNodeType.Element, "LSDeadZoneType", null); xmlLSDeadZoneType.InnerText = lsModInfo[device].deadzoneType.ToString(); rootElement.AppendChild(xmlLSDeadZoneType);
XmlNode xmlRSDeadZoneType = m_Xdoc.CreateNode(XmlNodeType.Element, "RSDeadZoneType", null); xmlRSDeadZoneType.InnerText = rsModInfo[device].deadzoneType.ToString(); rootElement.AppendChild(xmlRSDeadZoneType);

Expand Down
12 changes: 6 additions & 6 deletions DS4Windows/DS4Forms/ViewModels/BindingWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ public string DefaultColor
{
color = Colors.LimeGreen.ToString();
}
/*else
else
{
color = SystemColors.ControlBrush.Color.ToString();
color = Application.Current.FindResource("SecondaryColor").ToString();
//color = SystemColors.ControlBrush.Color.ToString();
}
*/

return color;
}
Expand All @@ -387,11 +387,11 @@ public string UnboundColor
{
color = Colors.LimeGreen.ToString();
}
/*else
else
{
color = SystemColors.ControlBrush.Color.ToString();
color = Application.Current.FindResource("SecondaryColor").ToString();
//color = SystemColors.ControlBrush.Color.ToString();
}
*/

return color;
}
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
* Determine output behavior for Outer Bind Button. Currently treated as a virtual trigger. Steam treats its version like a normal button (no analog)
* ~~Test Steam Input Gyro vs Touchpad mouse action priority. (Tested. Output actions are added together. Do not want)~~
* Add Button Wheel sensitivity setting of some kind
* Add Max Output Force option for Gyro Mouse-like Joystick
* ~~Add Max Output Force option for Gyro Mouse-like Joystick~~

0 comments on commit 8a11577

Please sign in to comment.