diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlSerivce.cs index a32d46f..bb6dc3a 100644 --- a/DS4Windows/DS4Control/ControlSerivce.cs +++ b/DS4Windows/DS4Control/ControlSerivce.cs @@ -595,7 +595,6 @@ namespace DS4Windows EasterTime(ind); cState = Mapping.SetCurveAndDeadzone(ind, cState); - cState.calculateStickAngles(); if (!recordingMacro && (!string.IsNullOrEmpty(tempprofilename[ind]) || containsCustomAction(ind) || containsCustomExtras(ind) || diff --git a/DS4Windows/DS4Control/DS4StateFieldMapping.cs b/DS4Windows/DS4Control/DS4StateFieldMapping.cs new file mode 100644 index 0000000..c79fdd1 --- /dev/null +++ b/DS4Windows/DS4Control/DS4StateFieldMapping.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS4Windows +{ + class DS4StateFieldMapping + { + public enum ControlType { Unknown = 0, Button, AxisDir, Trigger, Touch, GyroDir, SwipeDir } + + public bool[] buttons = new bool[(int)DS4Controls.SwipeDown + 1]; + public byte[] axisdirs = new byte[(int)DS4Controls.SwipeDown + 1]; + public byte[] triggers = new byte[(int)DS4Controls.SwipeDown + 1]; + public int[] gryodirs = new int[(int)DS4Controls.SwipeDown + 1]; + public byte[] swipedirs = new byte[(int)DS4Controls.SwipeDown + 1]; + public bool[] swipedirbools = new bool[(int)DS4Controls.SwipeDown + 1]; + + public static ControlType[] mappedType = { ControlType.Unknown, // DS4Controls.None + ControlType.AxisDir, // DS4Controls.LXNeg + ControlType.AxisDir, // DS4Controls.LXPos + ControlType.AxisDir, // DS4Controls.LYNeg + ControlType.AxisDir, // DS4Controls.LYPos + ControlType.AxisDir, // DS4Controls.RXNeg + ControlType.AxisDir, // DS4Controls.RXPos + ControlType.AxisDir, // DS4Controls.RYNeg + ControlType.AxisDir, // DS4Controls.RYPos + ControlType.Button, // DS4Controls.L1 + ControlType.Trigger, // DS4Controls.L2 + ControlType.Button, // DS4Controls.L3 + ControlType.Button, // DS4Controls.R1 + ControlType.Trigger, // DS4Controls.R2 + ControlType.Button, // DS4Controls.R3 + ControlType.Button, // DS4Controls.Square + ControlType.Button, // DS4Controls.Triangle + ControlType.Button, // DS4Controls.Circle + ControlType.Button, // DS4Controls.Cross + ControlType.Button, // DS4Controls.DpadUp + ControlType.Button, // DS4Controls.DpadRight + ControlType.Button, // DS4Controls.DpadDown + ControlType.Button, // DS4Controls.DpadLeft + ControlType.Button, // DS4Controls.PS + ControlType.Touch, // DS4Controls.TouchLeft + ControlType.Touch, // DS4Controls.TouchUpper + ControlType.Touch, // DS4Controls.TouchMulti + ControlType.Touch, // DS4Controls.TouchRight + ControlType.Button, // DS4Controls.Share + ControlType.Button, // DS4Controls.Options + ControlType.GyroDir, // DS4Controls.GyroXPos + ControlType.GyroDir, // DS4Controls.GyroXNeg + ControlType.GyroDir, // DS4Controls.GyroZPos + ControlType.GyroDir, // DS4Controls.GyroZNeg + ControlType.SwipeDir, // DS4Controls.SwipeLeft + ControlType.SwipeDir, // DS4Controls.SwipeRight + ControlType.SwipeDir, // DS4Controls.SwipeUp + ControlType.SwipeDir, // DS4Controls.SwipeDown + }; + + public DS4StateFieldMapping(DS4State cState, DS4StateExposed exposeState, Mouse tp) + { + axisdirs[(int)DS4Controls.LXNeg] = cState.LX; + axisdirs[(int)DS4Controls.LXPos] = cState.LX; + axisdirs[(int)DS4Controls.LYNeg] = cState.LY; + axisdirs[(int)DS4Controls.LYPos] = cState.LY; + + axisdirs[(int)DS4Controls.RXNeg] = cState.RX; + axisdirs[(int)DS4Controls.RXPos] = cState.RX; + axisdirs[(int)DS4Controls.RYNeg] = cState.RY; + axisdirs[(int)DS4Controls.RYPos] = cState.RY; + + triggers[(int)DS4Controls.L2] = cState.L2; + triggers[(int)DS4Controls.R2] = cState.R2; + + buttons[(int)DS4Controls.L1] = cState.L1; + buttons[(int)DS4Controls.L3] = cState.L3; + buttons[(int)DS4Controls.R1] = cState.R1; + buttons[(int)DS4Controls.R3] = cState.R3; + + buttons[(int)DS4Controls.Cross] = cState.Cross; + buttons[(int)DS4Controls.Triangle] = cState.Triangle; + buttons[(int)DS4Controls.Circle] = cState.Circle; + buttons[(int)DS4Controls.Square] = cState.Square; + buttons[(int)DS4Controls.PS] = cState.PS; + buttons[(int)DS4Controls.Options] = cState.Options; + buttons[(int)DS4Controls.Share] = cState.Share; + + buttons[(int)DS4Controls.DpadUp] = cState.DpadUp; + buttons[(int)DS4Controls.DpadRight] = cState.DpadRight; + buttons[(int)DS4Controls.DpadDown] = cState.DpadDown; + buttons[(int)DS4Controls.DpadLeft] = cState.DpadLeft; + + buttons[(int)DS4Controls.TouchLeft] = tp.leftDown; + buttons[(int)DS4Controls.TouchRight] = tp.rightDown; + buttons[(int)DS4Controls.TouchUpper] = tp.upperDown; + buttons[(int)DS4Controls.TouchMulti] = tp.multiDown; + + gryodirs[(int)DS4Controls.GyroXNeg] = exposeState.getGyroX(); + gryodirs[(int)DS4Controls.GyroXPos] = exposeState.getGyroX(); + + gryodirs[(int)DS4Controls.GyroZPos] = exposeState.getGyroZ(); + gryodirs[(int)DS4Controls.GyroZPos] = exposeState.getGyroZ(); + + swipedirs[(int)DS4Controls.SwipeLeft] = tp.swipeLeftB; + swipedirs[(int)DS4Controls.SwipeRight] = tp.swipeRightB; + swipedirs[(int)DS4Controls.SwipeUp] = tp.swipeUpB; + swipedirs[(int)DS4Controls.SwipeDown] = tp.swipeDownB; + + swipedirbools[(int)DS4Controls.SwipeLeft] = tp.swipeLeft; + swipedirbools[(int)DS4Controls.SwipeRight] = tp.swipeRight; + swipedirbools[(int)DS4Controls.SwipeUp] = tp.swipeUp; + swipedirbools[(int)DS4Controls.SwipeDown] = tp.swipeDown; + } + + public void populateState(DS4State state) + { + state.LX = axisdirs[(int)DS4Controls.LXNeg]; + state.LX = axisdirs[(int)DS4Controls.LXPos]; + state.LY = axisdirs[(int)DS4Controls.LYNeg]; + state.LY = axisdirs[(int)DS4Controls.LYPos]; + + state.RX = axisdirs[(int)DS4Controls.RXNeg]; + state.RX = axisdirs[(int)DS4Controls.RXPos]; + state.RY = axisdirs[(int)DS4Controls.RYNeg]; + state.RY = axisdirs[(int)DS4Controls.RYPos]; + + state.L2 = triggers[(int)DS4Controls.L2]; + state.R2 = triggers[(int)DS4Controls.R2]; + + state.L1 = buttons[(int)DS4Controls.L1]; + state.L3 = buttons[(int)DS4Controls.L3]; + state.R1 = buttons[(int)DS4Controls.R1]; + state.R3 = buttons[(int)DS4Controls.R3]; + + state.Cross = buttons[(int)DS4Controls.Cross]; + state.Triangle = buttons[(int)DS4Controls.Triangle]; + state.Circle = buttons[(int)DS4Controls.Circle]; + state.Square = buttons[(int)DS4Controls.Square]; + state.PS = buttons[(int)DS4Controls.PS]; + state.Options = buttons[(int)DS4Controls.Options]; + state.Share = buttons[(int)DS4Controls.Share]; + + state.DpadUp = buttons[(int)DS4Controls.DpadUp]; + state.DpadRight = buttons[(int)DS4Controls.DpadRight]; + state.DpadDown = buttons[(int)DS4Controls.DpadDown]; + state.DpadLeft = buttons[(int)DS4Controls.DpadLeft]; + } + } +} diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 0549486..e096635 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -783,10 +783,13 @@ namespace DS4Windows double tempMouseDeltaY = 0.0; int mouseDeltaX = 0; int mouseDeltaY = 0; + + cState.calculateStickAngles(); + DS4StateFieldMapping fieldMapping = new DS4StateFieldMapping(cState, eState, tp); SyntheticState deviceState = Mapping.deviceState[device]; if (getProfileActionCount(device) > 0 || !string.IsNullOrEmpty(tempprofilename[device])) - MapCustomAction(device, cState, MappedState, eState, tp, ctrl); + MapCustomAction(device, cState, MappedState, eState, tp, ctrl, fieldMapping); if (ctrl.DS4Controllers[device] == null) return; cState.CopyTo(MappedState); @@ -818,12 +821,13 @@ namespace DS4Windows { if (actionType == DS4ControlSettings.ActionType.Macro) { - if (getBoolMapping(device, dcs.control, cState, eState, tp)) + bool active = getBoolMapping2(device, dcs.control, cState, eState, tp, fieldMapping); + if (active) { - resetToDefaultValue(dcs.control, MappedState); + resetToDefaultValue2(dcs.control, MappedState, fieldMapping); PlayMacro(device, macroControl, string.Join("/", (int[])action), dcs.control, keyType); } - else if (!getBoolMapping(device, dcs.control, cState, eState, tp)) + else { EndMacro(device, macroControl, string.Join("/", (int[])action), dcs.control); } @@ -831,9 +835,9 @@ namespace DS4Windows else if (actionType == DS4ControlSettings.ActionType.Key) { ushort value = ushort.Parse(action.ToString()); - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) { - resetToDefaultValue(dcs.control, MappedState); + resetToDefaultValue2(dcs.control, MappedState, fieldMapping); SyntheticState.KeyPresses kp; if (!deviceState.keyPresses.TryGetValue(value, out kp)) deviceState.keyPresses[value] = kp = new SyntheticState.KeyPresses(); @@ -939,38 +943,38 @@ namespace DS4Windows { case X360Controls.LeftMouse: keyvalue = 256; - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) deviceState.currentClicks.leftCount++; break; case X360Controls.RightMouse: keyvalue = 257; - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) deviceState.currentClicks.rightCount++; break; case X360Controls.MiddleMouse: keyvalue = 258; - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) deviceState.currentClicks.middleCount++; break; case X360Controls.FourthMouse: keyvalue = 259; - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) deviceState.currentClicks.fourthCount++; break; case X360Controls.FifthMouse: keyvalue = 260; - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) deviceState.currentClicks.fifthCount++; break; case X360Controls.WUP: - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (isAnalog) getMouseWheelMapping(device, dcs.control, cState, eState, tp, false); else deviceState.currentClicks.wUpCount++; break; case X360Controls.WDOWN: - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (isAnalog) getMouseWheelMapping(device, dcs.control, cState, eState, tp, true); else @@ -986,28 +990,28 @@ namespace DS4Windows case X360Controls.MouseUp: if (tempMouseDeltaY == 0) { - tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 0); + tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 0); tempMouseDeltaY = -Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY)); } break; case X360Controls.MouseDown: if (tempMouseDeltaY == 0) { - tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 1); + tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 1); tempMouseDeltaY = Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY)); } break; case X360Controls.MouseLeft: if (tempMouseDeltaX == 0) { - tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 2); + tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 2); tempMouseDeltaX = -Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX)); } break; case X360Controls.MouseRight: if (tempMouseDeltaX == 0) { - tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 3); + tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 3); tempMouseDeltaX = Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX)); } break; @@ -1028,9 +1032,9 @@ namespace DS4Windows if (keyType.HasFlag(DS4KeyType.Toggle)) { - if (getBoolActionMapping(device, dcs.control, cState, eState, tp)) + if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) { - resetToDefaultValue(dcs.control, MappedState); + resetToDefaultValue2(dcs.control, MappedState, fieldMapping); if (!pressedonce[keyvalue]) { deviceState.currentClicks.toggle = !deviceState.currentClicks.toggle; @@ -1044,7 +1048,7 @@ namespace DS4Windows } } - resetToDefaultValue(dcs.control, MappedState); // erase default mappings for things that are remapped + resetToDefaultValue2(dcs.control, MappedState, fieldMapping); // erase default mappings for things that are remapped } } @@ -1162,7 +1166,7 @@ namespace DS4Windows DS4Controls dc = tempControlDict[key]; //DS4Controls key = entry.Key; //DS4Controls dc = entry.Value; - if (getBoolActionMapping(device, dc, cState, eState, tp, true)) + if (getBoolActionMapping2(device, dc, cState, eState, tp, fieldMapping, true)) { if (key >= DS4Controls.Square && key <= DS4Controls.Cross) { @@ -1303,6 +1307,8 @@ namespace DS4Windows } } + fieldMapping.populateState(MappedState); + calculateFinalMouseMovement(ref tempMouseDeltaX, ref tempMouseDeltaY, out mouseDeltaX, out mouseDeltaY); if (mouseDeltaX != 0 || mouseDeltaY != 0) @@ -1315,8 +1321,9 @@ namespace DS4Windows { return shift ? false : GetDS4Action(device, dc, false) == null; } - public static async void MapCustomAction(int device, DS4State cState, DS4State MappedState, - DS4StateExposed eState, Mouse tp, ControlService ctrl) + + private static async void MapCustomAction(int device, DS4State cState, DS4State MappedState, + DS4StateExposed eState, Mouse tp, ControlService ctrl, DS4StateFieldMapping fieldMapping) { /* TODO: This method is slow sauce. Find ways to speed up action execution */ try @@ -1510,7 +1517,7 @@ namespace DS4Windows for (int i = 0, arlen = action.trigger.Count; i < arlen; i++) { DS4Controls dc = action.trigger[i]; - resetToDefaultValue(dc, MappedState); + resetToDefaultValue2(dc, MappedState, fieldMapping); } PlayMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None, keyType); @@ -2075,7 +2082,8 @@ namespace DS4Windows } } - private static double getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, int mnum) + private static double getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, + DS4StateFieldMapping fieldMapping, int mnum) { int controlnum = DS4ControltoInt(control); @@ -2092,7 +2100,15 @@ namespace DS4Windows double divide = 10000d; //DateTime now = mousenow[mnum]; - if (control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos) + int controlNum = (int)control; + DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum]; + + if (controlType == DS4StateFieldMapping.ControlType.Button) + { + bool active = fieldMapping.buttons[controlNum]; + value = (active ? Math.Pow(root + speed / divide, 100) - 1 : 0); + } + else if (controlType == DS4StateFieldMapping.ControlType.AxisDir) { switch (control) { @@ -2131,7 +2147,12 @@ namespace DS4Windows default: break; } } - else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg) + else if (controlType == DS4StateFieldMapping.ControlType.Trigger) + { + byte trigger = fieldMapping.triggers[controlNum]; + value = Math.Pow(root + speed / divide, trigger / 2d) - 1; + } + else if (controlType == DS4StateFieldMapping.ControlType.GyroDir) { double SXD = getSXDeadzone(device); double SZD = getSZDeadzone(device); @@ -2140,74 +2161,28 @@ namespace DS4Windows { case DS4Controls.GyroXPos: { - int gyroX = eState.GyroX; + int gyroX = fieldMapping.gryodirs[controlNum]; value = (byte)(gyroX > SXD * 10 ? Math.Pow(root + speed / divide, gyroX) : 0); break; } case DS4Controls.GyroXNeg: { - int gyroX = eState.GyroX; + int gyroX = fieldMapping.gryodirs[controlNum]; value = (byte)(gyroX < -SXD * 10 ? Math.Pow(root + speed / divide, -gyroX) : 0); break; } case DS4Controls.GyroZPos: { - int gyroZ = eState.GyroZ; + int gyroZ = fieldMapping.gryodirs[controlNum]; value = (byte)(gyroZ > SZD * 10 ? Math.Pow(root + speed / divide, gyroZ) : 0); break; } case DS4Controls.GyroZNeg: { - int gyroZ = eState.GyroZ; + int gyroZ = fieldMapping.gryodirs[controlNum]; value = (byte)(gyroZ < -SZD * 10 ? Math.Pow(root + speed / divide, -gyroZ) : 0); break; } - - default: break; - } - } - else if (control >= DS4Controls.DpadUp && control <= DS4Controls.DpadLeft) - { - switch (control) - { - case DS4Controls.DpadUp: value = (cState.DpadUp ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.DpadDown: value = (cState.DpadDown ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.DpadLeft: value = (cState.DpadLeft ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.DpadRight: value = (cState.DpadRight ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - default: break; - } - } - else if (control >= DS4Controls.Square && control <= DS4Controls.Cross) - { - switch (control) - { - case DS4Controls.Cross: value = (cState.Cross ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.Square: value = (cState.Square ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.Triangle: value = (cState.Triangle ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.Circle: value = (cState.Circle ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - default: break; - } - } - else if (control >= DS4Controls.L1 && control <= DS4Controls.R3) - { - switch (control) - { - case DS4Controls.L1: value = (cState.L1 ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.L2: value = Math.Pow(root + speed / divide, cState.L2 / 2d) - 1; break; - case DS4Controls.L3: value = (cState.L3 ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.R1: value = (cState.R1 ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.R2: value = Math.Pow(root + speed / divide, cState.R2 / 2d) - 1; break; - case DS4Controls.R3: value = (cState.R3 ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - default: break; - } - } - else - { - switch (control) - { - case DS4Controls.Share: value = (cState.Share ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.Options: value = (cState.Options ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; - case DS4Controls.PS: value = (cState.PS ? Math.Pow(root + speed / divide, 100) - 1 : 0); break; default: break; } } @@ -2505,6 +2480,222 @@ namespace DS4Windows return result; } + private static bool getBoolMapping2(int device, DS4Controls control, + DS4State cState, DS4StateExposed eState, Mouse tp, DS4StateFieldMapping fieldMap) + { + bool result = false; + + int controlNum = (int)control; + DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum]; + if (controlType == DS4StateFieldMapping.ControlType.Button) + { + result = fieldMap.buttons[controlNum]; + } + else if (controlType == DS4StateFieldMapping.ControlType.AxisDir) + { + byte axisValue = fieldMap.axisdirs[controlNum]; + + switch (control) + { + case DS4Controls.LXNeg: result = cState.LX < 127 - 55; break; + case DS4Controls.LYNeg: result = cState.LY < 127 - 55; break; + case DS4Controls.RXNeg: result = cState.RX < 127 - 55; break; + case DS4Controls.RYNeg: result = cState.RY < 127 - 55; break; + default: result = axisValue > 127 + 55; break; + } + } + else if (controlType == DS4StateFieldMapping.ControlType.Trigger) + { + result = fieldMap.triggers[controlNum] > 100; + } + else if (controlType == DS4StateFieldMapping.ControlType.Touch) + { + result = fieldMap.buttons[controlNum]; + } + else if (controlType == DS4StateFieldMapping.ControlType.SwipeDir) + { + result = fieldMap.swipedirbools[controlNum]; + } + else if (controlType == DS4StateFieldMapping.ControlType.GyroDir) + { + bool sOff = isUsingSAforMouse(device); + bool safeTest = false; + if (control == DS4Controls.GyroXNeg || control == DS4Controls.GyroZNeg) + { + safeTest = SXSens[device] * fieldMap.gryodirs[controlNum] > 67; + } + else + { + safeTest = SXSens[device] * fieldMap.gryodirs[controlNum] < -67; + } + + result = !sOff ? safeTest : false; + } + + return result; + } + + private static bool getBoolActionMapping2(int device, DS4Controls control, + DS4State cState, DS4StateExposed eState, Mouse tp, DS4StateFieldMapping fieldMap, bool analog = false) + { + bool result = false; + + int controlNum = (int)control; + DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum]; + if (controlType == DS4StateFieldMapping.ControlType.Button) + { + result = fieldMap.buttons[controlNum]; + } + else if (controlType == DS4StateFieldMapping.ControlType.AxisDir) + { + switch (control) + { + case DS4Controls.LXNeg: + { + if (!analog) + { + double angle = cState.LSAngle; + result = cState.LX < 127 && (angle >= 210 && angle <= 330); + } + else + { + result = cState.LX < 127; + } + + break; + } + case DS4Controls.LYNeg: + { + if (!analog) + { + double angle = cState.LSAngle; + result = cState.LY < 127 && (angle >= 300 || angle <= 60); + } + else + { + result = cState.LY < 127; + } + + break; + } + case DS4Controls.RXNeg: + { + if (!analog) + { + double angle = cState.RSAngle; + result = cState.RX < 127 && (angle >= 210 && angle <= 330); + } + else + { + result = cState.RX < 127; + } + + break; + } + case DS4Controls.RYNeg: + { + if (!analog) + { + double angle = cState.RSAngle; + result = cState.RY < 127 && (angle >= 300 || angle <= 60); + } + else + { + result = cState.RY < 127; + } + + break; + } + case DS4Controls.LXPos: + { + if (!analog) + { + double angle = cState.LSAngle; + result = cState.LX > 127 && (angle >= 30 && angle <= 150); + } + else + { + result = cState.LX > 127; + } + + break; + } + case DS4Controls.LYPos: + { + if (!analog) + { + double angle = cState.LSAngle; + result = cState.LY > 127 && (angle >= 120 && angle <= 240); + } + else + { + result = cState.LY > 127; + } + + break; + } + case DS4Controls.RXPos: + { + if (!analog) + { + double angle = cState.RSAngle; + result = cState.RX > 127 && (angle >= 30 && angle <= 150); + } + else + { + result = cState.RX > 127; + } + + break; + } + case DS4Controls.RYPos: + { + if (!analog) + { + double angle = cState.RSAngle; + result = cState.RY > 127 && (angle >= 120 && angle <= 240); + } + else + { + result = cState.RY > 127; + } + + break; + } + default: break; + } + } + else if (controlType == DS4StateFieldMapping.ControlType.Trigger) + { + result = fieldMap.triggers[controlNum] > 0; + } + else if (controlType == DS4StateFieldMapping.ControlType.Touch) + { + result = fieldMap.buttons[controlNum]; + } + else if (controlType == DS4StateFieldMapping.ControlType.SwipeDir) + { + result = fieldMap.swipedirbools[controlNum]; + } + else if (controlType == DS4StateFieldMapping.ControlType.GyroDir) + { + bool sOff = isUsingSAforMouse(device); + bool safeTest = false; + if (control == DS4Controls.GyroXNeg || control == DS4Controls.GyroZNeg) + { + safeTest = SXSens[device] * fieldMap.gryodirs[controlNum] > 67; + } + else + { + safeTest = SXSens[device] * fieldMap.gryodirs[controlNum] < -67; + } + + result = !sOff ? safeTest : false; + } + + return result; + } + public static bool getBoolActionMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp, bool analog=false) { @@ -2941,5 +3132,27 @@ namespace DS4Windows } } } + + private static void resetToDefaultValue2(DS4Controls control, DS4State cState, DS4StateFieldMapping fieldMap) + { + int controlNum = (int)control; + DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum]; + if (controlType == DS4StateFieldMapping.ControlType.Button) + { + fieldMap.buttons[controlNum] = false; + } + else if (controlType == DS4StateFieldMapping.ControlType.AxisDir) + { + fieldMap.axisdirs[controlNum] = 127; + } + else if (controlType == DS4StateFieldMapping.ControlType.Trigger) + { + fieldMap.triggers[controlNum] = 0; + } + else if (controlType == DS4StateFieldMapping.ControlType.Touch) + { + fieldMap.buttons[controlNum] = false; + } + } } } diff --git a/DS4Windows/DS4Library/DS4StateExposed.cs b/DS4Windows/DS4Library/DS4StateExposed.cs index c7ec114..f4ac887 100644 --- a/DS4Windows/DS4Library/DS4StateExposed.cs +++ b/DS4Windows/DS4Library/DS4StateExposed.cs @@ -72,11 +72,28 @@ namespace DS4Windows /// R side of controller upward /// Add double the previous result to this delta and divide by three. public int GyroX { get { return (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64; } } + + public int getGyroX() + { + return (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64; + } + /// touchpad and button face side of controller upward /// Add double the previous result to this delta and divide by three. public int GyroY { get { return (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64; } } + + public int getGyroY() + { + return (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64; + } + /// Audio/expansion ports upward and light bar/shoulders/bumpers/USB port downward /// Add double the previous result to this delta and divide by three. - public int GyroZ { get { return (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64; } } + public int GyroZ { get { return (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64; } } + + public int getGyroZ() + { + return (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64; + } } } diff --git a/DS4Windows/DS4Windows.csproj b/DS4Windows/DS4Windows.csproj index 1c3d266..07dfdc7 100644 --- a/DS4Windows/DS4Windows.csproj +++ b/DS4Windows/DS4Windows.csproj @@ -101,6 +101,7 @@ +