示例#1
0
 public DS4State(DS4State state)
 {
     ReportTimeStamp = state.ReportTimeStamp;
     Square = state.Square;
     Triangle = state.Triangle;
     Circle = state.Circle;
     Cross = state.Cross;
     DpadUp = state.DpadUp;
     DpadDown = state.DpadDown;
     DpadLeft = state.DpadLeft;
     DpadRight = state.DpadRight;
     L1 = state.L1;
     L2 = state.L2;
     L3 = state.L3;
     R1 = state.R1;
     R2 = state.R2;
     R3 = state.R3;
     Share = state.Share;
     Options = state.Options;
     PS = state.PS;
     Touch1 = state.Touch1;
     TouchRight = state.TouchRight;
     TouchLeft = state.TouchLeft;
     Touch1Identifier = state.Touch1Identifier;
     Touch2 = state.Touch2;
     Touch2Identifier = state.Touch2Identifier;
     TouchButton = state.TouchButton;
     TouchPacketCounter = state.TouchPacketCounter;
     LX = state.LX;
     RX = state.RX;
     LY = state.LY;
     RY = state.RY;
     FrameCounter = state.FrameCounter;
     Battery = state.Battery;
 }
示例#2
0
 public void CopyTo(DS4State state)
 {
     state.ReportTimeStamp = ReportTimeStamp;
     state.Square = Square;
     state.Triangle = Triangle;
     state.Circle = Circle;
     state.Cross = Cross;
     state.DpadUp = DpadUp;
     state.DpadDown = DpadDown;
     state.DpadLeft = DpadLeft;
     state.DpadRight = DpadRight;
     state.L1 = L1;
     state.L2 = L2;
     state.L3 = L3;
     state.R1 = R1;
     state.R2 = R2;
     state.R3 = R3;
     state.Share = Share;
     state.Options = Options;
     state.PS = PS;
     state.Touch1 = Touch1;
     state.Touch1Identifier = Touch1Identifier;
     state.Touch2 = Touch2;
     state.Touch2Identifier = Touch2Identifier;
     state.TouchLeft = TouchLeft;
     state.TouchRight = TouchRight;
     state.TouchButton = TouchButton;
     state.TouchPacketCounter = TouchPacketCounter;
     state.LX = LX;
     state.RX = RX;
     state.LY = LY;
     state.RY = RY;
     state.FrameCounter = FrameCounter;
     state.Battery = Battery;
 }
示例#3
0
        public void HandleSixaxis(byte[] gyro, byte[] accel, DS4State state)
        {
            int currentX = (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64;
            int currentY = (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64;
            int currentZ = (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64;
            int AccelX = (short)((ushort)(accel[2] << 8) | accel[3]) / 256;
            int AccelY = (short)((ushort)(accel[0] << 8) | accel[1]) / 256;
            int AccelZ = (short)((ushort)(accel[4] << 8) | accel[5]) / 256;

            if ((AccelX == 0) && (AccelY == 0) && (AccelZ == 0))
            {
                return;
            }

            if (SixAccelMoved != null)
            {
                SixAxis sPrev = new SixAxis(lastGyroX, lastGyroY, lastGyroZ, lastAX, lastAY, lastAZ);
                SixAxis now = new SixAxis(currentX, currentY, currentZ, AccelX, AccelY, AccelZ, sPrev);
                SixAxisEventArgs args = new SixAxisEventArgs(state.ReportTimeStamp, now);
                SixAccelMoved(this, args);
            }

            lastGyroX = currentX;
            lastGyroY = currentY;
            lastGyroZ = currentZ;
            lastAX = AccelX;
            lastAY = AccelY;
            lastAZ = AccelZ;
        }
示例#4
0
		public ControlService()
		{
			sp.Stream = Resources.EE;
			x360Bus = new X360Device();
			AddtoDS4List();
			for (int i = 0; i < DS4Controllers.Length; i++)
			{
				processingData[i] = new X360Data();
				MappedState[i]    = new DS4State();
				CurrentState[i]   = new DS4State();
				PreviousState[i]  = new DS4State();
				ExposedState[i]   = new DS4StateExposed(CurrentState[i]);
			}
		}
示例#5
0
		public static bool getBoolMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
		{
			bool sOff = Global.UseSAforMouse[device];
			switch (control)
			{
				case DS4Controls.Share:
					return cState.Share;
				case DS4Controls.Options:
					return cState.Options;
				case DS4Controls.L1:
					return cState.L1;
				case DS4Controls.R1:
					return cState.R1;
				case DS4Controls.L3:
					return cState.L3;
				case DS4Controls.R3:
					return cState.R3;
				case DS4Controls.DpadUp:
					return cState.DpadUp;
				case DS4Controls.DpadDown:
					return cState.DpadDown;
				case DS4Controls.DpadLeft:
					return cState.DpadLeft;
				case DS4Controls.DpadRight:
					return cState.DpadRight;
				case DS4Controls.PS:
					return cState.PS;
				case DS4Controls.Cross:
					return cState.Cross;
				case DS4Controls.Square:
					return cState.Square;
				case DS4Controls.Triangle:
					return cState.Triangle;
				case DS4Controls.Circle:
					return cState.Circle;
				case DS4Controls.TouchLeft:
					return tp != null ? tp.leftDown : false;
				case DS4Controls.TouchRight:
					return tp != null ? tp.rightDown : false;
				case DS4Controls.TouchMulti:
					return tp != null ? tp.multiDown : false;
				case DS4Controls.TouchUpper:
					return tp != null ? tp.upperDown : false;
				case DS4Controls.LXNeg:
					return cState.LX < 127 - 55;
				case DS4Controls.LYNeg:
					return cState.LY < 127 - 55;
				case DS4Controls.RXNeg:
					return cState.RX < 127 - 55;
				case DS4Controls.RYNeg:
					return cState.RY < 127 - 55;
				case DS4Controls.LXPos:
					return cState.LX > 127 + 55;
				case DS4Controls.LYPos:
					return cState.LY > 127 + 55;
				case DS4Controls.RXPos:
					return cState.RX > 127 + 55;
				case DS4Controls.RYPos:
					return cState.RY > 127 + 55;
				case DS4Controls.L2:
					return cState.L2 > 100;
				case DS4Controls.R2:
					return cState.R2 > 100;
				case DS4Controls.GyroXPos:
					return !sOff && Global.SXSens[device] * eState.GyroX > 67;
				case DS4Controls.GyroXNeg:
					return !sOff && Global.SXSens[device] * eState.GyroX < -67;
				case DS4Controls.GyroZPos:
					return !sOff && Global.SZSens[device] * eState.GyroZ > 67;
				case DS4Controls.GyroZNeg:
					return !sOff && Global.SZSens[device] * eState.GyroZ < -67;
				case DS4Controls.SwipeUp:
					return (tp != null) && tp.swipeUp;
				case DS4Controls.SwipeDown:
					return (tp != null) && tp.swipeDown;
				case DS4Controls.SwipeLeft:
					return (tp != null) && tp.swipeLeft;
				case DS4Controls.SwipeRight:
					return (tp != null) && tp.swipeRight;
			}
			return false;
		}
示例#6
0
		public static byte getByteMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
		{
			double SXD = Global.SXDeadzone[device];
			double SZD = Global.SZDeadzone[device];
			bool sOff = Global.UseSAforMouse[device];
			switch (control)
			{
				case DS4Controls.Share:
					return (byte)(cState.Share ? 255 : 0);
				case DS4Controls.Options:
					return (byte)(cState.Options ? 255 : 0);
				case DS4Controls.L1:
					return (byte)(cState.L1 ? 255 : 0);
				case DS4Controls.R1:
					return (byte)(cState.R1 ? 255 : 0);
				case DS4Controls.L3:
					return (byte)(cState.L3 ? 255 : 0);
				case DS4Controls.R3:
					return (byte)(cState.R3 ? 255 : 0);
				case DS4Controls.DpadUp:
					return (byte)(cState.DpadUp ? 255 : 0);
				case DS4Controls.DpadDown:
					return (byte)(cState.DpadDown ? 255 : 0);
				case DS4Controls.DpadLeft:
					return (byte)(cState.DpadLeft ? 255 : 0);
				case DS4Controls.DpadRight:
					return (byte)(cState.DpadRight ? 255 : 0);
				case DS4Controls.PS:
					return (byte)(cState.PS ? 255 : 0);
				case DS4Controls.Cross:
					return (byte)(cState.Cross ? 255 : 0);
				case DS4Controls.Square:
					return (byte)(cState.Square ? 255 : 0);
				case DS4Controls.Triangle:
					return (byte)(cState.Triangle ? 255 : 0);
				case DS4Controls.Circle:
					return (byte)(cState.Circle ? 255 : 0);
				case DS4Controls.TouchLeft:
					return (byte)((tp != null) && tp.leftDown ? 255 : 0);
				case DS4Controls.TouchRight:
					return (byte)((tp != null) && tp.rightDown ? 255 : 0);
				case DS4Controls.TouchMulti:
					return (byte)((tp != null) && tp.multiDown ? 255 : 0);
				case DS4Controls.TouchUpper:
					return (byte)((tp != null) && tp.upperDown ? 255 : 0);
				case DS4Controls.LXNeg:
					return (byte)(cState.LX - 127.5f > 0 ? 0 : -(cState.LX - 127.5f) * 2);
				case DS4Controls.LYNeg:
					return (byte)(cState.LY - 127.5f > 0 ? 0 : -(cState.LY - 127.5f) * 2);
				case DS4Controls.RXNeg:
					return (byte)(cState.RX - 127.5f > 0 ? 0 : -(cState.RX - 127.5f) * 2);
				case DS4Controls.RYNeg:
					return (byte)(cState.RY - 127.5f > 0 ? 0 : -(cState.RY - 127.5f) * 2);
				case DS4Controls.LXPos:
					return (byte)(cState.LX - 127.5f < 0 ? 0 : (cState.LX - 127.5f) * 2);
				case DS4Controls.LYPos:
					return (byte)(cState.LY - 127.5f < 0 ? 0 : (cState.LY - 127.5f) * 2);
				case DS4Controls.RXPos:
					return (byte)(cState.RX - 127.5f < 0 ? 0 : (cState.RX - 127.5f) * 2);
				case DS4Controls.RYPos:
					return (byte)(cState.RY - 127.5f < 0 ? 0 : (cState.RY - 127.5f) * 2);
				case DS4Controls.L2:
					return cState.L2;
				case DS4Controls.R2:
					return cState.R2;
				case DS4Controls.GyroXPos:
					return (byte)(!sOff && (Global.SXSens[device] * eState.GyroX > SXD * 10) ? Math.Min(255, Global.SXSens[device] * eState.GyroX * 2) : 0);
				case DS4Controls.GyroXNeg:
					return (byte)(!sOff && (Global.SXSens[device] * eState.GyroX < -SXD * 10) ? Math.Min(255, Global.SXSens[device] * -eState.GyroX * 2) : 0);
				case DS4Controls.GyroZPos:
					return (byte)(!sOff && (Global.SZSens[device] * eState.GyroZ > SZD * 10) ? Math.Min(255, Global.SZSens[device] * eState.GyroZ * 2) : 0);
				case DS4Controls.GyroZNeg:
					return (byte)(!sOff && (Global.SZSens[device] * eState.GyroZ < -SZD * 10) ? Math.Min(255, Global.SZSens[device] * -eState.GyroZ * 2) : 0);
				case DS4Controls.SwipeUp:
					return (byte)(tp != null ? tp.swipeUpB : 0);
				case DS4Controls.SwipeDown:
					return (byte)(tp != null ? tp.swipeDownB : 0);
				case DS4Controls.SwipeLeft:
					return (byte)(tp != null ? tp.swipeLeftB : 0);
				case DS4Controls.SwipeRight:
					return (byte)(tp != null ? tp.swipeRightB : 0);
			}
			return 0;
		}
示例#7
0
		private static int getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, int mnum)
		{
			int controlnum = DS4ControltoInt(control);
			double SXD = Global.SXDeadzone[device];
			double SZD = Global.SZDeadzone[device];
			int deadzoneL = 3;
			int deadzoneR = 3;
			if (Global.LSDeadzone[device] >= 3)
			{
				deadzoneL = 0;
			}
			if (Global.RSDeadzone[device] >= 3)
			{
				deadzoneR = 0;
			}
			double value = 0;
			int speed = Global.ButtonMouseSensitivity[device] + 15;
			const double root = 1.002;
			const double divide = 10000d;
			//DateTime now = mousenow[mnum];
			switch (control)
			{
				case DS4Controls.LXNeg:
					if (cState.LX - 127.5f < -deadzoneL)
					{
						value = -(cState.LX - 127.5f) / 2550d * speed;
					}
					break;
				case DS4Controls.LXPos:
					if (cState.LX - 127.5f > deadzoneL)
					{
						value = (cState.LX - 127.5f) / 2550d * speed;
					}
					break;
				case DS4Controls.RXNeg:
					if (cState.RX - 127.5f < -deadzoneR)
					{
						value = -(cState.RX - 127.5f) / 2550d * speed;
					}
					break;
				case DS4Controls.RXPos:
					if (cState.RX - 127.5f > deadzoneR)
					{
						value = (cState.RX - 127.5f) / 2550d * speed;
					}
					break;
				case DS4Controls.LYNeg:
					if (cState.LY - 127.5f < -deadzoneL)
					{
						value = -(cState.LY - 127.5f) / 2550d * speed;
					}
					break;
				case DS4Controls.LYPos:
					if (cState.LY - 127.5f > deadzoneL)
					{
						value = (cState.LY - 127.5f) / 2550d * speed;
					}
					break;
				case DS4Controls.RYNeg:
					if (cState.RY - 127.5f < -deadzoneR)
					{
						value = -(cState.RY - 127.5f) / 2550d * speed;
					}
					break;
				case DS4Controls.RYPos:
					if (cState.RY - 127.5f > deadzoneR)
					{
						value = (cState.RY - 127.5f) / 2550d * speed;
					}
					break;
				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.L1:
					value = cState.L1 ? 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.L3:
					value = cState.L3 ? Math.Pow(root + speed / divide, 100) - 1 : 0;
					break;
				case DS4Controls.R3:
					value = cState.R3 ? Math.Pow(root + speed / divide, 100) - 1 : 0;
					break;
				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;
				case DS4Controls.PS:
					value = cState.PS ? Math.Pow(root + speed / divide, 100) - 1 : 0;
					break;
				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;
				case DS4Controls.L2:
					value = Math.Pow(root + speed / divide, cState.L2 / 2d) - 1;
					break;
				case DS4Controls.R2:
					value = Math.Pow(root + speed / divide, cState.R2 / 2d) - 1;
					break;
				case DS4Controls.GyroXPos:
					return (byte)(eState.GyroX > SXD * 10 ? Math.Pow(root + speed / divide, eState.GyroX) : 0);
				case DS4Controls.GyroXNeg:
					return (byte)(eState.GyroX < -SXD * 10 ? Math.Pow(root + speed / divide, -eState.GyroX) : 0);
				case DS4Controls.GyroZPos:
					return (byte)(eState.GyroZ > SZD * 10 ? Math.Pow(root + speed / divide, eState.GyroZ) : 0);
				case DS4Controls.GyroZNeg:
					return (byte)(eState.GyroZ < -SZD * 10 ? Math.Pow(root + speed / divide, -eState.GyroZ) : 0);

				case DS4Controls.None:
					break;
				case DS4Controls.TouchLeft:
					break;
				case DS4Controls.TouchUpper:
					break;
				case DS4Controls.TouchMulti:
					break;
				case DS4Controls.TouchRight:
					break;
				case DS4Controls.SwipeLeft:
					break;
				case DS4Controls.SwipeRight:
					break;
				case DS4Controls.SwipeUp:
					break;
				case DS4Controls.SwipeDown:
					break;

				default:
					throw new ArgumentOutOfRangeException(nameof(control), control, null);
			}
			bool LXChanged = Math.Abs(127 - cState.LX) < deadzoneL;
			bool LYChanged = Math.Abs(127 - cState.LY) < deadzoneL;
			bool RXChanged = Math.Abs(127 - cState.RX) < deadzoneR;
			bool RYChanged = Math.Abs(127 - cState.RY) < deadzoneR;
			bool contains = control.ToString().Contains("LX") ||
			                control.ToString().Contains("LY") ||
			                control.ToString().Contains("RX") ||
			                control.ToString().Contains("RY");

			if (Global.MouseAccel[device])
			{
				if (value > 0)
				{
					mcounter = 34;
					mouseaccel++;
				}
				if (mouseaccel == prevmouseaccel)
				{
					mcounter--;
				}
				if (mcounter <= 0)
				{
					mouseaccel = 0;
					mcounter = 34;
				}
				value *= 1 + Math.Min(20000, mouseaccel) / 10000d;
				prevmouseaccel = mouseaccel;
			}
			int intValue;
			if (mnum > 1)
			{
				if (((value > 0.0) && (horizontalRemainder > 0.0)) || ((value < 0.0) && (horizontalRemainder < 0.0)))
				{
					value += horizontalRemainder;
				}
				intValue = (int)value;
				horizontalRemainder = value - intValue;
			}
			else
			{
				if (((value > 0.0) && (verticalRemainder > 0.0)) || ((value < 0.0) && (verticalRemainder < 0.0)))
				{
					value += verticalRemainder;
				}
				intValue = (int)value;
				verticalRemainder = value - intValue;
			}
			return intValue;
		}
示例#8
0
		private static void getMouseWheelMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp, bool down)
		{
			DateTime now = DateTime.UtcNow;
			if ((now < oldnow + TimeSpan.FromMilliseconds(10)) || pressagain)
			{
				return;
			}
			oldnow = now;
			InputMethods.MouseWheel((int)(getByteMapping(device, control, cState, eState, tp) / 51f * (down ? -1 : 1)), 0);
		}
示例#9
0
		public static async void MapCustomAction(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState, Mouse tp, ControlService ctrl)
		{
			try
			{
				foreach (string actionname in Global.ProfileActions[device])
				{
					//DS4KeyType keyType = getShiftCustomKeyType(device, customKey.Key);
					SpecialAction action = Global.GetAction(actionname);
					int index = Global.GetActionIndexOf(actionname);
					//If a key or button is assigned to the trigger, a key special action is used like
					//a quick tap to use and hold to use the regular custom button/key
					bool triggerToBeTapped = (action.type == "Key") && (action.trigger.Count == 1) &&
					                         (Global.GetDS4Action(device, action.trigger[0].ToString(), false) == null);
					if ((action.name == "null") || (index < 0))
					{
						continue;
					}

					bool triggeractivated = true;
					if (action.delayTime > 0)
					{
						triggeractivated = false;
						bool subtriggeractivated = action.trigger.All(dc => getBoolMapping(device, dc, cState, eState, tp));
						if (subtriggeractivated)
						{
							double time = action.delayTime;
							nowAction[device] = DateTime.UtcNow;
							if (nowAction[device] >= oldnowAction[device] + TimeSpan.FromSeconds(time))
							{
								triggeractivated = true;
							}
						}
						else if (nowAction[device] < DateTime.UtcNow - TimeSpan.FromMilliseconds(100))
						{
							oldnowAction[device] = DateTime.UtcNow;
						}
					}
					else if (triggerToBeTapped && (oldnowKeyAct[device] == DateTime.MinValue))
					{
						triggeractivated = false;
						bool subtriggeractivated = action.trigger.All(dc => getBoolMapping(device, dc, cState, eState, tp));
						if (subtriggeractivated)
						{
							oldnowKeyAct[device] = DateTime.UtcNow;
						}
					}
					else if (triggerToBeTapped && (oldnowKeyAct[device] != DateTime.MinValue))
					{
						triggeractivated = false;
						bool subtriggeractivated = action.trigger.All(dc => getBoolMapping(device, dc, cState, eState, tp));
						DateTime now = DateTime.UtcNow;
						if (!subtriggeractivated && (now <= oldnowKeyAct[device] + TimeSpan.FromMilliseconds(250)))
						{
							await Task.Delay(3); //if the button is assigned to the same key use a delay so the key down is the last action, not key up
							triggeractivated = true;
							oldnowKeyAct[device] = DateTime.MinValue;
						}
						else if (!subtriggeractivated)
						{
							oldnowKeyAct[device] = DateTime.MinValue;
						}
					}
					else if (action.trigger.Any(dc => !getBoolMapping(device, dc, cState, eState, tp)))
					{
						triggeractivated = false;
					}

					bool utriggeractivated = true;
					if ((action.type == "Key") && (action.uTrigger.Count > 0))
					{
						if (action.uTrigger.Any(dc => !getBoolMapping(device, dc, cState, eState, tp)))
						{
							utriggeractivated = false;
						}
						if (action.pressRelease)
						{
							utriggeractivated = !utriggeractivated;
						}
					}

					if (triggeractivated && (action.type == "Program"))
					{
						if (actionDone[device, index])
						{
							continue;
						}
						actionDone[device, index] = true;
						if (!string.IsNullOrEmpty(action.extra))
						{
							Process.Start(action.details, action.extra);
						}
						else
						{
							Process.Start(action.details);
						}
					}
					else if (triggeractivated && (action.type == "Profile"))
					{
						if (actionDone[device, index] || !string.IsNullOrEmpty(Global.tempprofilename[device]))
						{
							continue;
						}

						actionDone[device, index] = true;
						untriggeraction[device] = action;
						untriggerindex[device] = index;
						foreach (DS4Controls dc in action.trigger)
						{
							DS4ControlSettings dcs = Global.getDS4CSetting(device, dc.ToString());
							if (dcs.action == null)
							{
								continue;
							}
							if (dcs.actionType == DS4ControlSettings.ActionType.Key)
							{
								InputMethods.PerformKeyRelease(ushort.Parse(action.ToString()));
							}
							else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
							{
								int[] keys = (int[])dcs.action;
								foreach (int key in keys)
								{
									InputMethods.PerformKeyRelease((ushort)key);
								}
							}
						}
						Global.LoadTempProfile(device, action.details, true, ctrl);
						return;
					}
					else if (triggeractivated && (action.type == "Macro"))
					{
						if (!actionDone[device, index])
						{
							DS4KeyType keyType = action.keyType;
							actionDone[device, index] = true;
							foreach (DS4Controls dc in action.trigger)
							{
								resetToDefaultValue(dc, MappedState);
							}
							PlayMacro(device, macroControl, string.Join("/", action.macro), DS4Controls.None, keyType);
						}
						else
						{
							EndMacro(device, macroControl, string.Join("/", action.macro), DS4Controls.None);
						}
					}
					else if (triggeractivated && (action.type == "Key"))
					{
						if ((action.uTrigger.Count != 0) && ((action.uTrigger.Count <= 0) || (untriggerindex[device] != -1) || actionDone[device, index]))
						{
							continue;
						}
						actionDone[device, index] = true;
						untriggerindex[device] = index;
						ushort key;
						ushort.TryParse(action.details, out key);
						if (action.uTrigger.Count == 0)
						{
							SyntheticState.KeyPresses kp;
							if (!deviceState[device].keyPresses.TryGetValue(key, out kp))
							{
								deviceState[device].keyPresses[key] = kp = new SyntheticState.KeyPresses();
							}
							if (action.keyType.HasFlag(DS4KeyType.ScanCode))
							{
								kp.current.scanCodeCount++;
							}
							else
							{
								kp.current.vkCount++;
							}
							kp.current.repeatCount++;
						}
						else if (action.keyType.HasFlag(DS4KeyType.ScanCode))
						{
							InputMethods.PerformScKeyPress(key);
						}
						else
						{
							InputMethods.PerformKeyPress(key);
						}
					}
					else if ((action.uTrigger.Count > 0) && utriggeractivated && (action.type == "Key"))
					{
						if ((untriggerindex[device] <= -1) || actionDone[device, index])
						{
							continue;
						}
						actionDone[device, index] = true;
						untriggerindex[device] = -1;
						ushort key;
						ushort.TryParse(action.details, out key);
						if (action.keyType.HasFlag(DS4KeyType.ScanCode))
						{
							InputMethods.PerformScKeyRelease(key);
						}
						else
						{
							InputMethods.PerformKeyRelease(key);
						}
					}
					else if (triggeractivated && (action.type == "DisconnectBT"))
					{
						DS4Device d = ctrl.DS4Controllers[device];
						if (d.Charging)
						{
							continue;
						}
						d.DisconnectBluetooth();
						foreach (DS4Controls dc in action.trigger)
						{
							DS4ControlSettings dcs = Global.getDS4CSetting(device, dc.ToString());
							if (dcs.action != null)
							{
								if (dcs.actionType == DS4ControlSettings.ActionType.Key)
								{
									InputMethods.PerformKeyRelease((ushort)dcs.action);
								}
								else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
								{
									int[] keys = (int[])dcs.action;
									foreach (int key in keys)
									{
										InputMethods.PerformKeyRelease((ushort)key);
									}
								}
							}
						}
						return;
					}
					else if (triggeractivated && (action.type == "BatteryCheck"))
					{
						string[] dets = action.details.Split(',');
						if (bool.Parse(dets[1]) && !actionDone[device, index])
						{
							Log.LogToTray("Controller " + (device + 1) + ": " +
							              ctrl.GetDS4Battery(device), LogWarning.Yes);
						}
						if (bool.Parse(dets[2]))
						{
							DS4Device d = ctrl.DS4Controllers[device];
							if (!actionDone[device, index])
							{
								lastColor[device] = d.LightBarColor;
								DS4LightBar.forcelight[device] = true;
							}
							DS4Color empty = new DS4Color(byte.Parse(dets[3]), byte.Parse(dets[4]), byte.Parse(dets[5]));
							DS4Color full = new DS4Color(byte.Parse(dets[6]), byte.Parse(dets[7]), byte.Parse(dets[8]));
							DS4Color trans = Global.getTransitionedColor(empty, full, d.Battery);
							if (fadetimer[device] < 100)
							{
								DS4LightBar.forcedColor[device] = Global.getTransitionedColor(lastColor[device], trans, fadetimer[device] += 2);
							}
						}
						actionDone[device, index] = true;
					}
					else if (!triggeractivated && (action.type == "BatteryCheck"))
					{
						if (actionDone[device, index])
						{
							fadetimer[device] = 0;
							DS4LightBar.forcelight[device] = false;
							actionDone[device, index] = false;
						}
					}
					else if (action.type == "XboxGameDVR")
					{
						/*if (getCustomButton(device, action.trigger[0]) != X360Controls.Unbound)
								getCustomButtons(device)[action.trigger[0]] = X360Controls.Unbound;
							if (getCustomMacro(device, action.trigger[0]) != "0")
								getCustomMacros(device).Remove(action.trigger[0]);
							if (getCustomKey(device, action.trigger[0]) != 0)
								getCustomMacros(device).Remove(action.trigger[0]);*/
						string[] dets = action.details.Split(',');
						DS4Device d = ctrl.DS4Controllers[device];
						//cus
						if (getBoolMapping(device, action.trigger[0], cState, eState, tp) && !getBoolMapping(device, action.trigger[0], d.GetPreviousState(), eState, tp))
						{
							//pressed down
							pastTime = DateTime.UtcNow;
							if (DateTime.UtcNow <= firstTap + TimeSpan.FromMilliseconds(150))
							{
								tappedOnce = false;
								secondtouchbegin = true;
							}
							else
							{
								firstTouch = true;
							}
						}
						else if (!getBoolMapping(device, action.trigger[0], cState, eState, tp) && getBoolMapping(device, action.trigger[0], d.GetPreviousState(), eState, tp))
						{
							//released
							if (secondtouchbegin)
							{
								firstTouch = false;
								secondtouchbegin = false;
							}
							else if (firstTouch)
							{
								firstTouch = false;
								if ((DateTime.UtcNow <= pastTime + TimeSpan.FromMilliseconds(200)) && !tappedOnce)
								{
									tappedOnce = true;
									firstTap = DateTime.UtcNow;
									TimeofEnd = DateTime.UtcNow;
								}
							}
						}

						int type;
						string macro = string.Empty;
						if (tappedOnce) //single tap
						{
							if (int.TryParse(dets[0], out type))
							{
								switch (type)
								{
									case 0:
										macro = "91/71/71/91";
										break;
									case 1:
										macro = "91/164/82/82/164/91";
										break;
									case 2:
										macro = "91/164/44/44/164/91";
										break;
									case 3:
										macro = dets[3] + "/" + dets[3];
										break;
									case 4:
										macro = "91/164/71/71/164/91";
										break;
								}
							}
							if (DateTime.UtcNow - TimeofEnd > TimeSpan.FromMilliseconds(150))
							{
								PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
								tappedOnce = false;
							}
							//if it fails the method resets, and tries again with a new tester value (gives tap a delay so tap and hold can work)
						}
						else if (firstTouch && (DateTime.UtcNow - pastTime > TimeSpan.FromMilliseconds(1000))) //helddown
						{
							if (int.TryParse(dets[1], out type))
							{
								switch (type)
								{
									case 0:
										macro = "91/71/71/91";
										break;
									case 1:
										macro = "91/164/82/82/164/91";
										break;
									case 2:
										macro = "91/164/44/44/164/91";
										break;
									case 3:
										macro = dets[3] + "/" + dets[3];
										break;
									case 4:
										macro = "91/164/71/71/164/91";
										break;
								}
							}
							PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
							firstTouch = false;
						}
						else if (secondtouchbegin) //if double tap
						{
							if (int.TryParse(dets[2], out type))
							{
								switch (type)
								{
									case 0:
										macro = "91/71/71/91";
										break;
									case 1:
										macro = "91/164/82/82/164/91";
										break;
									case 2:
										macro = "91/164/44/44/164/91";
										break;
									case 3:
										macro = dets[3] + "/" + dets[3];
										break;
									case 4:
										macro = "91/164/71/71/164/91";
										break;
								}
							}
							PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
							secondtouchbegin = false;
						}
					}
					else
					{
						actionDone[device, index] = false;
					}
				}
			}
			catch
			{
				return;
			}

			if (untriggeraction[device] != null)
			{
				SpecialAction action = untriggeraction[device];
				int index = untriggerindex[device];

				if (action.uTrigger.All(dc => getBoolMapping(device, dc, cState, eState, tp)) && (action.type == "Profile"))
				{
					if (((action.controls != action.ucontrols) || actionDone[device, index]) && (action.controls == action.ucontrols))
					{
						return;
					}

					if (string.IsNullOrEmpty(Global.tempprofilename[device]))
					{
						return;
					}

					foreach (DS4Controls dc in action.uTrigger)
					{
						actionDone[device, index] = true;
						DS4ControlSettings dcs = Global.getDS4CSetting(device, dc.ToString());
						if (dcs.action == null)
						{
							continue;
						}

						if (dcs.actionType == DS4ControlSettings.ActionType.Key)
						{
							InputMethods.PerformKeyRelease((ushort)dcs.action);
						}
						else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
						{
							int[] keys = (int[])dcs.action;
							foreach (int key in keys)
							{
								InputMethods.PerformKeyRelease((ushort)key);
							}
						}
					}

					untriggeraction[device] = null;
					Global.LoadProfile(device, false, ctrl);
				}
				else
				{
					actionDone[device, index] = false;
				}
			}
		}
示例#10
0
        public void handleTouchpad(byte[] data, DS4State sensors, int touchPacketOffset = 0)
        {
            bool touchPadIsDown = sensors.TouchButton;
            if (!PacketChanged(data, touchPacketOffset) && (touchPadIsDown == lastTouchPadIsDown))
            {
                TouchUnchanged?.Invoke(this, EventArgs.Empty);
                return;
            }
            byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);
            byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);
            int currentX1 = data[1 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] + (data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF) * 255;
            int currentY1 = ((data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4) + data[3 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] * 16;
            int currentX2 = data[5 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] + (data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF) * 255;
            int currentY2 = ((data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4) + data[7 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] * 16;

            TouchpadEventArgs args;
            if (sensors.Touch1 || sensors.Touch2)
            {
                if ((sensors.Touch1 && !lastIsActive1) || (sensors.Touch2 && !lastIsActive2))
                {
                    if (TouchesBegan != null)
                    {
                        if (sensors.Touch1 && sensors.Touch2)
                        {
                            args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1), new Touch(currentX2, currentY2, touchID2));
                        }
                        else if (sensors.Touch1)
                        {
                            args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1));
                        }
                        else
                        {
                            args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX2, currentY2, touchID2));
                        }

                        TouchesBegan(this, args);
                    }
                }
                else if ((sensors.Touch1 == lastIsActive1) && (sensors.Touch2 == lastIsActive2) && (TouchesMoved != null))
                {
                    Touch tPrev, t0, t1;

                    if (sensors.Touch1 && sensors.Touch2)
                    {
                        tPrev = new Touch(lastTouchPadX1, lastTouchPadY1, lastTouchID1);
                        t0 = new Touch(currentX1, currentY1, touchID1, tPrev);
                        tPrev = new Touch(lastTouchPadX2, lastTouchPadY2, lastTouchID2);
                        t1 = new Touch(currentX2, currentY2, touchID2, tPrev);
                    }
                    else if (sensors.Touch1)
                    {
                        tPrev = new Touch(lastTouchPadX1, lastTouchPadY1, lastTouchID1);
                        t0 = new Touch(currentX1, currentY1, touchID1, tPrev);
                        t1 = null;
                    }
                    else
                    {
                        tPrev = new Touch(lastTouchPadX2, lastTouchPadY2, lastTouchID2);
                        t0 = new Touch(currentX2, currentY2, touchID2, tPrev);
                        t1 = null;
                    }
                    args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1);

                    TouchesMoved(this, args);
                }

                if (!lastTouchPadIsDown && touchPadIsDown && (TouchButtonDown != null))
                {
                    if (sensors.Touch1 && sensors.Touch2)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1), new Touch(currentX2, currentY2, touchID2));
                    }
                    else if (sensors.Touch1)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1));
                    }
                    else
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX2, currentY2, touchID2));
                    }

                    TouchButtonDown(this, args);
                }
                else if (lastTouchPadIsDown && !touchPadIsDown && (TouchButtonUp != null))
                {
                    if (sensors.Touch1 && sensors.Touch2)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1), new Touch(currentX2, currentY2, touchID2));
                    }
                    else if (sensors.Touch1)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1));
                    }
                    else
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX2, currentY2, touchID2));
                    }

                    TouchButtonUp(this, args);
                }

                if (sensors.Touch1)
                {
                    lastTouchPadX1 = currentX1;
                    lastTouchPadY1 = currentY1;
                }
                if (sensors.Touch2)
                {
                    lastTouchPadX2 = currentX2;
                    lastTouchPadY2 = currentY2;
                }
                lastTouchPadIsDown = touchPadIsDown;
            }
            else
            {
                if (touchPadIsDown && !lastTouchPadIsDown)
                {
                    TouchButtonDown?.Invoke(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null));
                }
                else if (!touchPadIsDown && lastTouchPadIsDown)
                {
                    TouchButtonUp?.Invoke(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null));
                }

                if ((lastIsActive1 || lastIsActive2) && (TouchesEnded != null))
                {
                    if (lastIsActive1 && lastIsActive2)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(lastTouchPadX1, lastTouchPadY1, touchID1), new Touch(lastTouchPadX2, lastTouchPadY2, touchID2));
                    }
                    else if (lastIsActive1)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(lastTouchPadX1, lastTouchPadY1, touchID1));
                    }
                    else
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(lastTouchPadX2, lastTouchPadY2, touchID2));
                    }

                    TouchesEnded(this, args);
                }
            }

            lastIsActive1 = sensors.Touch1;
            lastIsActive2 = sensors.Touch2;
            lastTouchID1 = touchID1;
            lastTouchID2 = touchID2;
            lastTouchPadIsDown = touchPadIsDown;
        }
示例#11
0
		protected virtual void CheckForHotkeys(int deviceId, DS4State cState, DS4State pState)
		{
			if (!Global.UseTPforControls[deviceId] && cState.Touch1 && pState.PS)
			{
				if ((Global.TouchSensitivity[deviceId] > 0) && touchreleased[deviceId])
				{
					oldtouchvalue[deviceId] = Global.TouchSensitivity[deviceId];
					oldscrollvalue[deviceId] = Global.ScrollSensitivity[deviceId];
					Global.TouchSensitivity[deviceId] = 0;
					Global.ScrollSensitivity[deviceId] = 0;
					LogDebug(Global.TouchSensitivity[deviceId] > 0 ? Resources.TouchpadMovementOn : Resources.TouchpadMovementOff);
					Log.LogToTray(Global.TouchSensitivity[deviceId] > 0 ? Resources.TouchpadMovementOn : Resources.TouchpadMovementOff);
					touchreleased[deviceId] = false;
				}
				else if (touchreleased[deviceId])
				{
					Global.TouchSensitivity[deviceId] = oldtouchvalue[deviceId];
					Global.ScrollSensitivity[deviceId] = oldscrollvalue[deviceId];
					LogDebug(Global.TouchSensitivity[deviceId] > 0 ? Resources.TouchpadMovementOn : Resources.TouchpadMovementOff);
					Log.LogToTray(Global.TouchSensitivity[deviceId] > 0 ? Resources.TouchpadMovementOn : Resources.TouchpadMovementOff);
					touchreleased[deviceId] = false;
				}
			}
			else
			{
				touchreleased[deviceId] = true;
			}
		}
示例#12
0
		public static DS4State SetCurveAndDeadzone(int device, DS4State cState)
		{
			DS4State dState = new DS4State(cState);
			int x;
			int y;
			int curve;
			if (Global.LSCurve[device] > 0)
			{
				x = cState.LX;
				y = cState.LY;
				float max = x + y;
				double curvex;
				double curvey;
				curve = Global.LSCurve[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);
			}
			if (Global.RSCurve[device] > 0)
			{
				x = cState.RX;
				y = cState.RY;
				float max = x + y;
				double curvex;
				double curvey;
				curve = Global.RSCurve[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);
				}
				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.RX = (byte)Math.Round(curvex, 0);
				dState.RY = (byte)Math.Round(curvey, 0);
			}
			double ls = Math.Sqrt(Math.Pow(cState.LX - 127.5f, 2) + Math.Pow(cState.LY - 127.5f, 2));
			//deadzones
			if ((Global.LSDeadzone[device] > 0) && (ls < Global.LSDeadzone[device]))
			{
				dState.LX = 127;
				dState.LY = 127;
			}
			else if ((Global.LSDeadzone[device] < 0) && (ls > 127.5f + Global.LSDeadzone[device]))
			{
				double r = Math.Atan2(dState.LY - 127.5f, dState.LX - 127.5f);
				dState.LX = (byte)(Math.Cos(r) * (127.5f + Global.LSDeadzone[device]) + 127.5f);
				dState.LY = (byte)(Math.Sin(r) * (127.5f + Global.LSDeadzone[device]) + 127.5f);
			}
			//Console.WriteLine
			double rs = Math.Sqrt(Math.Pow(cState.RX - 127.5f, 2) + Math.Pow(cState.RY - 127.5f, 2));
			if ((Global.RSDeadzone[device] > 0) && (rs < Global.LSDeadzone[device]))
			{
				dState.RX = 127;
				dState.RY = 127;
			}
			else if ((Global.RSDeadzone[device] < 0) && (rs > 127.5f + Global.RSDeadzone[device]))
			{
				double r = Math.Atan2(dState.RY - 127.5f, dState.RX - 127.5f);
				dState.RX = (byte)(Math.Cos(r) * (127.5f + Global.RSDeadzone[device]) + 127.5f);
				dState.RY = (byte)(Math.Sin(r) * (127.5f + Global.RSDeadzone[device]) + 127.5f);
			}
			if ((Global.L2Deadzone[device] > 0) && (cState.L2 < Global.L2Deadzone[device]))
			{
				dState.L2 = 0;
			}
			if ((Global.R2Deadzone[device] > 0) && (cState.R2 < Global.R2Deadzone[device]))
			{
				dState.R2 = 0;
			}
			if (Global.LSSens[device] != 1)
			{
				dState.LX = (byte)Clamp(0, Global.LSSens[device] * (dState.LX - 127) + 127, 255);
				dState.LY = (byte)Clamp(0, Global.LSSens[device] * (dState.LY - 127) + 127, 255);
			}
			if (Global.RSSens[device] != 1)
			{
				dState.RX = (byte)Clamp(0, Global.RSSens[device] * (dState.RX - 127) + 127, 255);
				dState.RY = (byte)Clamp(0, Global.RSSens[device] * (dState.RY - 127) + 127, 255);
			}
			if (Global.L2Sens[device] != 1)
			{
				dState.L2 = (byte)Clamp(0, Global.L2Sens[device] * dState.L2, 255);
			}
			if (Global.R2Sens[device] != 1)
			{
				dState.R2 = (byte)Clamp(0, Global.R2Sens[device] * dState.R2, 255);
			}
			return dState;
		}
示例#13
0
        public void Parse(DS4State state, byte[] Output, int device)
        {
            Output[0] = 0x1C;
            Output[4] = (byte)(device + firstController);
            Output[9] = 0x14;

            for (int i = 10; i < Output.Length; i++)
            {
                Output[i] = 0;
            }
            if (state.Share)
            {
                Output[10] |= 1 << 5; // Back
            }
            if (state.L3)
            {
                Output[10] |= 1 << 6; // Left  Thumb
            }
            if (state.R3)
            {
                Output[10] |= 1 << 7; // Right Thumb
            }
            if (state.Options)
            {
                Output[10] |= 1 << 4; // Start
            }

            if (state.DpadUp)
            {
                Output[10] |= 1 << 0; // Up
            }
            if (state.DpadRight)
            {
                Output[10] |= 1 << 3; // Down
            }
            if (state.DpadDown)
            {
                Output[10] |= 1 << 1; // Right
            }
            if (state.DpadLeft)
            {
                Output[10] |= 1 << 2; // Left
            }

            if (state.L1)
            {
                Output[11] |= 1 << 0; // Left  Shoulder
            }
            if (state.R1)
            {
                Output[11] |= 1 << 1; // Right Shoulder
            }

            if (state.Triangle)
            {
                Output[11] |= 1 << 7; // Y
            }
            if (state.Circle)
            {
                Output[11] |= 1 << 5; // B
            }
            if (state.Cross)
            {
                Output[11] |= 1 << 4; // A
            }
            if (state.Square)
            {
                Output[11] |= 1 << 6; // X
            }

            if (state.PS)
            {
                Output[11] |= 1 << 2; // Guide
            }

            Output[12] = state.L2; // Left Trigger
            Output[13] = state.R2; // Right Trigger

            int thumbLx = Scale(state.LX, false);
            int thumbLy = -Scale(state.LY, false);
            int thumbRx = Scale(state.RX, false);
            int thumbRy = -Scale(state.RY, false);
            Output[14] = (byte)((thumbLx >> 0) & 0xFF); // LX
            Output[15] = (byte)((thumbLx >> 8) & 0xFF);
            Output[16] = (byte)((thumbLy >> 0) & 0xFF); // LY
            Output[17] = (byte)((thumbLy >> 8) & 0xFF);
            Output[18] = (byte)((thumbRx >> 0) & 0xFF); // RX
            Output[19] = (byte)((thumbRx >> 8) & 0xFF);
            Output[20] = (byte)((thumbRy >> 0) & 0xFF); // RY
            Output[21] = (byte)((thumbRy >> 8) & 0xFF);
        }
示例#14
0
		public void GetPreviousState(DS4State state)
		{
			pState.CopyTo(state);
		}
示例#15
0
		public void GetCurrentState(DS4State state)
		{
			cState.CopyTo(state);
		}
示例#16
0
		public void GetExposedState(DS4StateExposed expState, DS4State state)
		{
			cState.CopyTo(state);
			expState.Accel = accel;
			expState.Gyro = gyro;
		}
示例#17
0
		public static byte getXYAxisMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp, bool alt = false)
		{
			byte trueVal = 0;
			byte falseVal = 127;
			double SXD = Global.SXDeadzone[device];
			double SZD = Global.SZDeadzone[device];
			bool sOff = Global.UseSAforMouse[device];
			if (alt)
			{
				trueVal = 255;
			}
			switch (control)
			{
				case DS4Controls.Share:
					return cState.Share ? trueVal : falseVal;
				case DS4Controls.Options:
					return cState.Options ? trueVal : falseVal;
				case DS4Controls.L1:
					return cState.L1 ? trueVal : falseVal;
				case DS4Controls.R1:
					return cState.R1 ? trueVal : falseVal;
				case DS4Controls.L3:
					return cState.L3 ? trueVal : falseVal;
				case DS4Controls.R3:
					return cState.R3 ? trueVal : falseVal;
				case DS4Controls.DpadUp:
					return cState.DpadUp ? trueVal : falseVal;
				case DS4Controls.DpadDown:
					return cState.DpadDown ? trueVal : falseVal;
				case DS4Controls.DpadLeft:
					return cState.DpadLeft ? trueVal : falseVal;
				case DS4Controls.DpadRight:
					return cState.DpadRight ? trueVal : falseVal;
				case DS4Controls.PS:
					return cState.PS ? trueVal : falseVal;
				case DS4Controls.Cross:
					return cState.Cross ? trueVal : falseVal;
				case DS4Controls.Square:
					return cState.Square ? trueVal : falseVal;
				case DS4Controls.Triangle:
					return cState.Triangle ? trueVal : falseVal;
				case DS4Controls.Circle:
					return cState.Circle ? trueVal : falseVal;
				case DS4Controls.TouchLeft:
					return (tp != null) && tp.leftDown ? trueVal : falseVal;
				case DS4Controls.TouchRight:
					return (tp != null) && tp.rightDown ? trueVal : falseVal;
				case DS4Controls.TouchMulti:
					return (tp != null) && tp.multiDown ? trueVal : falseVal;
				case DS4Controls.TouchUpper:
					return (tp != null) && tp.upperDown ? trueVal : falseVal;
				case DS4Controls.L2:
					if (alt)
					{
						return (byte)(127.5f + cState.L2 / 2f);
					}
					return (byte)(127.5f - cState.L2 / 2f);
				case DS4Controls.R2:
					if (alt)
					{
						return (byte)(127.5f + cState.R2 / 2f);
					}
					return (byte)(127.5f - cState.R2 / 2f);
				case DS4Controls.SwipeUp:
					if (alt)
					{
						return (byte)(tp != null ? 127.5f + tp.swipeUpB / 2f : 0);
					}
					return (byte)(tp != null ? 127.5f - tp.swipeUpB / 2f : 0);
				case DS4Controls.SwipeDown:
					if (alt)
					{
						return (byte)(tp != null ? 127.5f + tp.swipeDownB / 2f : 0);
					}
					return (byte)(tp != null ? 127.5f - tp.swipeDownB / 2f : 0);
				case DS4Controls.SwipeLeft:
					if (alt)
					{
						return (byte)(tp != null ? 127.5f + tp.swipeLeftB / 2f : 0);
					}
					return (byte)(tp != null ? 127.5f - tp.swipeLeftB / 2f : 0);
				case DS4Controls.SwipeRight:
					if (alt)
					{
						return (byte)(tp != null ? 127.5f + tp.swipeRightB / 2f : 0);
					}
					return (byte)(tp != null ? 127.5f - tp.swipeRightB / 2f : 0);
				case DS4Controls.GyroXPos:
					if (!sOff && (eState.GyroX > SXD * 10))
					{
						if (alt)
						{
							return (byte)Math.Min(255, 127 + Global.SXSens[device] * eState.GyroX);
						}
						return (byte)Math.Max(0, 127 - Global.SXSens[device] * eState.GyroX);
					}
					return falseVal;
				case DS4Controls.GyroXNeg:
					if (!sOff && (eState.GyroX < -SXD * 10))
					{
						if (alt)
						{
							return (byte)Math.Min(255, 127 + Global.SXSens[device] * -eState.GyroX);
						}
						return (byte)Math.Max(0, 127 - Global.SXSens[device] * -eState.GyroX);
					}
					return falseVal;
				case DS4Controls.GyroZPos:
					if (!sOff && (eState.GyroZ > SZD * 10))
					{
						if (alt)
						{
							return (byte)Math.Min(255, 127 + Global.SZSens[device] * eState.GyroZ);
						}
						return (byte)Math.Max(0, 127 - Global.SZSens[device] * eState.GyroZ);
					}
					return falseVal;
				case DS4Controls.GyroZNeg:
					if (sOff || !(eState.GyroZ < -SZD * 10))
					{
						return falseVal;
					}
					return alt ? (byte)Math.Min(255, 127 + Global.SZSens[device] * -eState.GyroZ) : (byte)Math.Max(0, 127 - Global.SZSens[device] * -eState.GyroZ);
			}
			if (!alt)
			{
				switch (control)
				{
					case DS4Controls.LXNeg:
						return cState.LX;
					case DS4Controls.LYNeg:
						return cState.LY;
					case DS4Controls.RXNeg:
						return cState.RX;
					case DS4Controls.RYNeg:
						return cState.RY;
					case DS4Controls.LXPos:
						return (byte)(255 - cState.LX);
					case DS4Controls.LYPos:
						return (byte)(255 - cState.LY);
					case DS4Controls.RXPos:
						return (byte)(255 - cState.RX);
					case DS4Controls.RYPos:
						return (byte)(255 - cState.RY);
				}
			}
			else
			{
				switch (control)
				{
					case DS4Controls.LXNeg:
						return (byte)(255 - cState.LX);
					case DS4Controls.LYNeg:
						return (byte)(255 - cState.LY);
					case DS4Controls.RXNeg:
						return (byte)(255 - cState.RX);
					case DS4Controls.RYNeg:
						return (byte)(255 - cState.RY);
					case DS4Controls.LXPos:
						return cState.LX;
					case DS4Controls.LYPos:
						return cState.LY;
					case DS4Controls.RXPos:
						return cState.RX;
					case DS4Controls.RYPos:
						return cState.RY;
				}
			}
			return 0;
		}
示例#18
0
		//Returns false for any bool, 
		//if control is one of the xy axis returns 127
		//if its a trigger returns 0
		public static void resetToDefaultValue(DS4Controls control, DS4State cState)
		{
			switch (control)
			{
				case DS4Controls.Share:
					cState.Share = false;
					break;
				case DS4Controls.Options:
					cState.Options = false;
					break;
				case DS4Controls.L1:
					cState.L1 = false;
					break;
				case DS4Controls.R1:
					cState.R1 = false;
					break;
				case DS4Controls.L3:
					cState.L3 = false;
					break;
				case DS4Controls.R3:
					cState.R3 = false;
					break;
				case DS4Controls.DpadUp:
					cState.DpadUp = false;
					break;
				case DS4Controls.DpadDown:
					cState.DpadDown = false;
					break;
				case DS4Controls.DpadLeft:
					cState.DpadLeft = false;
					break;
				case DS4Controls.DpadRight:
					cState.DpadRight = false;
					break;
				case DS4Controls.PS:
					cState.PS = false;
					break;
				case DS4Controls.Cross:
					cState.Cross = false;
					break;
				case DS4Controls.Square:
					cState.Square = false;
					break;
				case DS4Controls.Triangle:
					cState.Triangle = false;
					break;
				case DS4Controls.Circle:
					cState.Circle = false;
					break;
				case DS4Controls.LXNeg:
					cState.LX = 127;
					break;
				case DS4Controls.LYNeg:
					cState.LY = 127;
					break;
				case DS4Controls.RXNeg:
					cState.RX = 127;
					break;
				case DS4Controls.RYNeg:
					cState.RY = 127;
					break;
				case DS4Controls.LXPos:
					cState.LX = 127;
					break;
				case DS4Controls.LYPos:
					cState.LY = 127;
					break;
				case DS4Controls.RXPos:
					cState.RX = 127;
					break;
				case DS4Controls.RYPos:
					cState.RY = 127;
					break;
				case DS4Controls.L2:
					cState.L2 = 0;
					break;
				case DS4Controls.R2:
					cState.R2 = 0;
					break;
			}
		}
示例#19
0
		public static void MapCustom(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState, Mouse tp, ControlService ctrl)
		{
			MappedState.LX = 127;
			MappedState.LY = 127;
			MappedState.RX = 127;
			MappedState.RY = 127;
			int mouseDeltaX = 0;
			int mouseDeltaY = 0;

			SyntheticState state = deviceState[device];
			if ((Global.GetActions().Count > 0) && ((Global.ProfileActions[device].Count > 0) || !string.IsNullOrEmpty(Global.tempprofilename[device])))
			{
				MapCustomAction(device, cState, MappedState, eState, tp, ctrl);
			}
			if (ctrl.DS4Controllers[device] == null)
			{
				return;
			}

			cState.CopyTo(MappedState);

			List<DS4Controls> cross     = new List<DS4Controls>();
			List<DS4Controls> circle    = new List<DS4Controls>();
			List<DS4Controls> square    = new List<DS4Controls>();
			List<DS4Controls> triangle  = new List<DS4Controls>();
			List<DS4Controls> options   = new List<DS4Controls>();
			List<DS4Controls> share     = new List<DS4Controls>();
			List<DS4Controls> dPadUp    = new List<DS4Controls>();
			List<DS4Controls> dPadDown  = new List<DS4Controls>();
			List<DS4Controls> dPadLeft  = new List<DS4Controls>();
			List<DS4Controls> dpadRight = new List<DS4Controls>();
			List<DS4Controls> ps        = new List<DS4Controls>();
			List<DS4Controls> l1        = new List<DS4Controls>();
			List<DS4Controls> r1        = new List<DS4Controls>();
			List<DS4Controls> l2        = new List<DS4Controls>();
			List<DS4Controls> r2        = new List<DS4Controls>();
			List<DS4Controls> l3        = new List<DS4Controls>();
			List<DS4Controls> r3        = new List<DS4Controls>();
			List<DS4Controls> lxn       = new List<DS4Controls>();
			List<DS4Controls> lxp       = new List<DS4Controls>();
			List<DS4Controls> lyn       = new List<DS4Controls>();
			List<DS4Controls> lyp       = new List<DS4Controls>();
			List<DS4Controls> rxn       = new List<DS4Controls>();
			List<DS4Controls> rxp       = new List<DS4Controls>();
			List<DS4Controls> ryn       = new List<DS4Controls>();
			List<DS4Controls> ryp       = new List<DS4Controls>();

			DS4Controls usingExtra = DS4Controls.None;

			foreach (DS4ControlSettings dcs in Global.getDS4CSettings(device))
			{
				object action = null;
				DS4ControlSettings.ActionType actionType = 0;
				DS4KeyType keyType = DS4KeyType.None;
				if ((dcs.shiftAction != null) && ShiftTrigger(dcs.shiftTrigger, device, cState, eState, tp))
				{
					action = dcs.shiftAction;
					actionType = dcs.shiftActionType;
					keyType = dcs.shiftKeyType;
				}
				else if (dcs.action != null)
				{
					action = dcs.action;
					actionType = dcs.actionType;
					keyType = dcs.keyType;
				}
				if (action != null)
				{
					switch (actionType)
					{
						case DS4ControlSettings.ActionType.Macro:
							if (getBoolMapping(device, dcs.control, cState, eState, tp))
							{
								resetToDefaultValue(dcs.control, MappedState);
								PlayMacro(device, macroControl, string.Join("/", (int[])action), dcs.control, keyType);
							}
							else if (!getBoolMapping(device, dcs.control, cState, eState, tp))
							{
								EndMacro(device, macroControl, string.Join("/", (int[])action), dcs.control);
							}
							break;
						case DS4ControlSettings.ActionType.Key:
							ushort value = ushort.Parse(action.ToString());
							if (getBoolMapping(device, dcs.control, cState, eState, tp))
							{
								resetToDefaultValue(dcs.control, MappedState);
								SyntheticState.KeyPresses kp;
								if (!state.keyPresses.TryGetValue(value, out kp))
								{
									state.keyPresses[value] = kp = new SyntheticState.KeyPresses();
								}
								if (keyType.HasFlag(DS4KeyType.ScanCode))
								{
									kp.current.scanCodeCount++;
								}
								else
								{
									kp.current.vkCount++;
								}
								if (keyType.HasFlag(DS4KeyType.Toggle))
								{
									if (!pressedonce[value])
									{
										kp.current.toggle = !kp.current.toggle;
										pressedonce[value] = true;
									}
									kp.current.toggleCount++;
								}
								kp.current.repeatCount++;
							}
							else
							{
								pressedonce[value] = false;
							}
							break;
						case DS4ControlSettings.ActionType.Button:
							int keyvalue = 0;
							bool isAnalog = dcs.control.ToString().Contains("LX") ||
							                dcs.control.ToString().Contains("RX") ||
							                dcs.control.ToString().Contains("LY") ||
							                dcs.control.ToString().Contains("LY") ||
							                dcs.control.ToString().Contains("R2") ||
							                dcs.control.ToString().Contains("L2") ||
							                dcs.control.ToString().Contains("Gyro");
							switch (getX360ControlsByName(action.ToString()))
							{
								case X360Controls.A:
									cross.Add(dcs.control);
									break;
								case X360Controls.B:
									circle.Add(dcs.control);
									break;
								case X360Controls.X:
									square.Add(dcs.control);
									break;
								case X360Controls.Y:
									triangle.Add(dcs.control);
									break;
								case X360Controls.LB:
									l1.Add(dcs.control);
									break;
								case X360Controls.LS:
									l3.Add(dcs.control);
									break;
								case X360Controls.RB:
									r1.Add(dcs.control);
									break;
								case X360Controls.RS:
									r3.Add(dcs.control);
									break;
								case X360Controls.DpadUp:
									dPadUp.Add(dcs.control);
									break;
								case X360Controls.DpadDown:
									dPadDown.Add(dcs.control);
									break;
								case X360Controls.DpadLeft:
									dPadLeft.Add(dcs.control);
									break;
								case X360Controls.DpadRight:
									dpadRight.Add(dcs.control);
									break;
								case X360Controls.Start:
									options.Add(dcs.control);
									break;
								case X360Controls.Guide:
									ps.Add(dcs.control);
									break;
								case X360Controls.Back:
									share.Add(dcs.control);
									break;
								case X360Controls.LXNeg:
									lxn.Add(dcs.control);
									break;
								case X360Controls.LYNeg:
									lyn.Add(dcs.control);
									break;
								case X360Controls.RXNeg:
									rxn.Add(dcs.control);
									break;
								case X360Controls.RYNeg:
									ryn.Add(dcs.control);
									break;
								case X360Controls.LXPos:
									lxp.Add(dcs.control);
									break;
								case X360Controls.LYPos:
									lyp.Add(dcs.control);
									break;
								case X360Controls.RXPos:
									rxp.Add(dcs.control);
									break;
								case X360Controls.RYPos:
									ryp.Add(dcs.control);
									break;
								case X360Controls.LT:
									l2.Add(dcs.control);
									break;
								case X360Controls.RT:
									r2.Add(dcs.control);
									break;
								case X360Controls.LeftMouse:
									keyvalue = 256;
									if (getBoolMapping(device, dcs.control, cState, eState, tp))
									{
										state.currentClicks.leftCount++;
									}
									break;
								case X360Controls.RightMouse:
									keyvalue = 257;
									if (getBoolMapping(device, dcs.control, cState, eState, tp))
									{
										state.currentClicks.rightCount++;
									}
									break;
								case X360Controls.MiddleMouse:
									keyvalue = 258;
									if (getBoolMapping(device, dcs.control, cState, eState, tp))
									{
										state.currentClicks.middleCount++;
									}
									break;
								case X360Controls.FourthMouse:
									keyvalue = 259;
									if (getBoolMapping(device, dcs.control, cState, eState, tp))
									{
										state.currentClicks.fourthCount++;
									}
									break;
								case X360Controls.FifthMouse:
									keyvalue = 260;
									if (getBoolMapping(device, dcs.control, cState, eState, tp))
									{
										state.currentClicks.fifthCount++;
									}
									break;
								case X360Controls.WUP:
									if (getBoolMapping(device, dcs.control, cState, eState, tp))
									{
										if (isAnalog)
										{
											getMouseWheelMapping(device, dcs.control, cState, eState, tp, false);
										}
										else
										{
											state.currentClicks.wUpCount++;
										}
									}
									break;
								case X360Controls.WDOWN:
									if (getBoolMapping(device, dcs.control, cState, eState, tp))
									{
										if (isAnalog)
										{
											getMouseWheelMapping(device, dcs.control, cState, eState, tp, true);
										}
										else
										{
											state.currentClicks.wDownCount++;
										}
									}
									break;
								case X360Controls.MouseUp:
									if (mouseDeltaY == 0)
									{
										mouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 0);
										mouseDeltaY = -Math.Abs(mouseDeltaY == -2147483648 ? 0 : mouseDeltaY);
									}
									break;
								case X360Controls.MouseDown:
									if (mouseDeltaY == 0)
									{
										mouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 1);
										mouseDeltaY = Math.Abs(mouseDeltaY == -2147483648 ? 0 : mouseDeltaY);
									}
									break;
								case X360Controls.MouseLeft:
									if (mouseDeltaX == 0)
									{
										mouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 2);
										mouseDeltaX = -Math.Abs(mouseDeltaX == -2147483648 ? 0 : mouseDeltaX);
									}
									break;
								case X360Controls.MouseRight:
									if (mouseDeltaX == 0)
									{
										mouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 3);
										mouseDeltaX = Math.Abs(mouseDeltaX == -2147483648 ? 0 : mouseDeltaX);
									}
									break;
							}
							if (keyType.HasFlag(DS4KeyType.Toggle))
							{
								if (getBoolMapping(device, dcs.control, cState, eState, tp))
								{
									resetToDefaultValue(dcs.control, MappedState);
									if (!pressedonce[keyvalue])
									{
										state.currentClicks.toggle = !state.currentClicks.toggle;
										pressedonce[keyvalue] = true;
									}
									state.currentClicks.toggleCount++;
								}
								else
								{
									pressedonce[keyvalue] = false;
								}
							}
							resetToDefaultValue(dcs.control, MappedState); // erase default mappings for things that are remapped
							break;
					}
				}

				if ((usingExtra != DS4Controls.None) && (usingExtra != dcs.control))
				{
					continue;
				}

				bool shiftE = (dcs.shiftExtras != "0,0,0,0,0,0,0,0") && !string.IsNullOrEmpty(dcs.shiftExtras) && ShiftTrigger(dcs.shiftTrigger, device, cState, eState, tp);
				bool regE = (dcs.extras != "0,0,0,0,0,0,0,0") && !string.IsNullOrEmpty(dcs.extras);
				if ((regE || shiftE) && getBoolMapping(device, dcs.control, cState, eState, tp))
				{
					usingExtra = dcs.control;
					string p = shiftE ? dcs.shiftExtras : dcs.extras;
					string[] extraS = p.Split(',');
					int[] extras = new int[extraS.Length];
					for (int i = 0; i < extraS.Length; i++)
					{
						int b;
						if (int.TryParse(extraS[i], out b))
						{
							extras[i] = b;
						}
					}
					held[device] = true;
					try
					{
						if (!((extras[0] == extras[1]) && (extras[1] == 0)))
						{
							ctrl.SetRumble((byte)extras[0], (byte)extras[1], device);
						}
						if (extras[2] == 1)
						{
							DS4Color color = new DS4Color { red = (byte)extras[3], green = (byte)extras[4], blue = (byte)extras[5] };
							DS4LightBar.forcedColor[device] = color;
							DS4LightBar.forcedFlash[device] = (byte)extras[6];
							DS4LightBar.forcelight[device] = true;
						}
						if (extras[7] == 1)
						{
							if (oldmouse[device] == -1)
							{
								oldmouse[device] = Global.ButtonMouseSensitivity[device];
							}
							Global.ButtonMouseSensitivity[device] = extras[8];
						}
					}
					catch
					{
						// ignored
					}
				}
				else if ((regE || shiftE) && held[device])
				{
					DS4LightBar.forcelight[device] = false;
					DS4LightBar.forcedFlash[device] = 0;
					Global.ButtonMouseSensitivity[device] = oldmouse[device];
					oldmouse[device] = -1;
					ctrl.SetRumble(0, 0, device);
					held[device] = false;
					usingExtra = DS4Controls.None;
				}
			}

			if (macroControl[00])
			{
				MappedState.Cross = true;
			}
			if (macroControl[01])
			{
				MappedState.Circle = true;
			}
			if (macroControl[02])
			{
				MappedState.Square = true;
			}
			if (macroControl[03])
			{
				MappedState.Triangle = true;
			}
			if (macroControl[04])
			{
				MappedState.Options = true;
			}
			if (macroControl[05])
			{
				MappedState.Share = true;
			}
			if (macroControl[06])
			{
				MappedState.DpadUp = true;
			}
			if (macroControl[07])
			{
				MappedState.DpadDown = true;
			}
			if (macroControl[08])
			{
				MappedState.DpadLeft = true;
			}
			if (macroControl[09])
			{
				MappedState.DpadRight = true;
			}
			if (macroControl[10])
			{
				MappedState.PS = true;
			}
			if (macroControl[11])
			{
				MappedState.L1 = true;
			}
			if (macroControl[12])
			{
				MappedState.R1 = true;
			}
			if (macroControl[13])
			{
				MappedState.L2 = 255;
			}
			if (macroControl[14])
			{
				MappedState.R2 = 255;
			}
			if (macroControl[15])
			{
				MappedState.L3 = true;
			}
			if (macroControl[16])
			{
				MappedState.R3 = true;
			}
			if (macroControl[17])
			{
				MappedState.LX = 255;
			}
			if (macroControl[18])
			{
				MappedState.LX = 0;
			}
			if (macroControl[19])
			{
				MappedState.LY = 255;
			}
			if (macroControl[20])
			{
				MappedState.LY = 0;
			}
			if (macroControl[21])
			{
				MappedState.RX = 255;
			}
			if (macroControl[22])
			{
				MappedState.RX = 0;
			}
			if (macroControl[23])
			{
				MappedState.RY = 255;
			}
			if (macroControl[24])
			{
				MappedState.RY = 0;
			}
			foreach (DS4Controls dc in cross)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.Cross = true;
				}
			}
			foreach (DS4Controls dc in circle)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.Circle = true;
				}
			}
			foreach (DS4Controls dc in square)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.Square = true;
				}
			}
			foreach (DS4Controls dc in triangle)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.Triangle = true;
				}
			}
			foreach (DS4Controls dc in l1)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.L1 = true;
				}
			}
			foreach (DS4Controls dc in l2)
			{
				if (getByteMapping(device, dc, cState, eState, tp) > 5)
				{
					MappedState.L2 = getByteMapping(device, dc, cState, eState, tp);
				}
			}
			foreach (DS4Controls dc in l3)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.L3 = true;
				}
			}
			foreach (DS4Controls dc in r1)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.R1 = true;
				}
			}
			foreach (DS4Controls dc in r2)
			{
				if (getByteMapping(device, dc, cState, eState, tp) > 5)
				{
					MappedState.R2 = getByteMapping(device, dc, cState, eState, tp);
				}
			}
			foreach (DS4Controls dc in r3)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.R3 = true;
				}
			}
			foreach (DS4Controls dc in dPadUp)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.DpadUp = true;
				}
			}
			foreach (DS4Controls dc in dpadRight)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.DpadRight = true;
				}
			}
			foreach (DS4Controls dc in dPadLeft)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.DpadLeft = true;
				}
			}
			foreach (DS4Controls dc in dPadDown)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.DpadDown = true;
				}
			}
			foreach (DS4Controls dc in options)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.Options = true;
				}
			}
			foreach (DS4Controls dc in share)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.Share = true;
				}
			}
			foreach (DS4Controls dc in ps)
			{
				if (getBoolMapping(device, dc, cState, eState, tp))
				{
					MappedState.PS = true;
				}
			}
			if (IfAxisIsNotModified(device, ShiftTrigger(Global.GetDS4STrigger(device, DS4Controls.LXNeg.ToString()), device, cState, eState, tp), DS4Controls.LXNeg))
			{
				lxn.Add(DS4Controls.LXNeg);
			}

			if (IfAxisIsNotModified(device, ShiftTrigger(Global.GetDS4STrigger(device, DS4Controls.LXPos.ToString()), device, cState, eState, tp), DS4Controls.LXPos))
			{
				lxp.Add(DS4Controls.LXPos);
			}

			if (IfAxisIsNotModified(device, ShiftTrigger(Global.GetDS4STrigger(device, DS4Controls.LYNeg.ToString()), device, cState, eState, tp), DS4Controls.LYNeg))
			{
				lyn.Add(DS4Controls.LYNeg);
			}

			if (IfAxisIsNotModified(device, ShiftTrigger(Global.GetDS4STrigger(device, DS4Controls.LYPos.ToString()), device, cState, eState, tp), DS4Controls.LYPos))
			{
				lyp.Add(DS4Controls.LYPos);
			}

			if (IfAxisIsNotModified(device, ShiftTrigger(Global.GetDS4STrigger(device, DS4Controls.RXNeg.ToString()), device, cState, eState, tp), DS4Controls.RXNeg))
			{
				rxn.Add(DS4Controls.RXNeg);
			}

			if (IfAxisIsNotModified(device, ShiftTrigger(Global.GetDS4STrigger(device, DS4Controls.RXPos.ToString()), device, cState, eState, tp), DS4Controls.RXPos))
			{
				rxp.Add(DS4Controls.RXPos);
			}

			if (IfAxisIsNotModified(device, ShiftTrigger(Global.GetDS4STrigger(device, DS4Controls.RYNeg.ToString()), device, cState, eState, tp), DS4Controls.RYNeg))
			{
				ryn.Add(DS4Controls.RYNeg);
			}

			if (IfAxisIsNotModified(device, ShiftTrigger(Global.GetDS4STrigger(device, DS4Controls.RYPos.ToString()), device, cState, eState, tp), DS4Controls.RYPos))
			{
				ryp.Add(DS4Controls.RYPos);
			}

			if (Math.Abs(MappedState.LX - 127) < 10)
			{
				if ((lxn.Count > 0) || (lxp.Count > 0))
				{
					foreach (DS4Controls dc in lxp)
					{
						if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp, true)) > 5)
						{
							MappedState.LX = getXYAxisMapping(device, dc, cState, eState, tp, true);
						}
					}
					foreach (DS4Controls dc in lxn)
					{
						if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp)) > 5)
						{
							MappedState.LX = getXYAxisMapping(device, dc, cState, eState, tp);
						}
					}
				}
			}
			//else
			//MappedState.LX = cState.LX;
			if (Math.Abs(MappedState.LY - 127) < 10)
			{
				if ((lyn.Count > 0) || (lyp.Count > 0))
				{
					foreach (DS4Controls dc in lyn)
					{
						if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp)) > 5)
						{
							MappedState.LY = getXYAxisMapping(device, dc, cState, eState, tp);
						}
					}
					foreach (DS4Controls dc in lyp)
					{
						if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp, true)) > 5)
						{
							MappedState.LY = getXYAxisMapping(device, dc, cState, eState, tp, true);
						}
					}
				}
			}
			//else
			//MappedState.LY = cState.LY;
			if (Math.Abs(MappedState.RX - 127) < 10)
			{
				if ((rxn.Count > 0) || (rxp.Count > 0))
				{
					foreach (DS4Controls dc in rxn)
					{
						if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp)) > 5)
						{
							MappedState.RX = getXYAxisMapping(device, dc, cState, eState, tp);
						}
					}
					foreach (DS4Controls dc in rxp)
					{
						if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp, true)) > 5)
						{
							MappedState.RX = getXYAxisMapping(device, dc, cState, eState, tp, true);
						}
					}
				}
			}
			//else
			// MappedState.RX = cState.RX;
			if (Math.Abs(MappedState.RY - 127) < 10)
			{
				if ((ryn.Count > 0) || (ryp.Count > 0))
				{
					foreach (DS4Controls dc in ryn)
					{
						if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp)) > 5)
						{
							MappedState.RY = getXYAxisMapping(device, dc, cState, eState, tp);
						}
					}
					foreach (DS4Controls dc in ryp)
					{
						if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp, true)) > 5)
						{
							MappedState.RY = getXYAxisMapping(device, dc, cState, eState, tp, true);
						}
					}
				}
			}
			// else
			// MappedState.RY = cState.RY;
			InputMethods.MoveCursorBy(mouseDeltaX, mouseDeltaY);
		}
示例#20
0
		private static bool ShiftTrigger(int trigger, int device, DS4State cState, DS4StateExposed eState, Mouse tp)
		{
			switch (trigger)
			{
				case 1:
					return getBoolMapping(device, DS4Controls.Cross, cState, eState, tp);
				case 2:
					return getBoolMapping(device, DS4Controls.Circle, cState, eState, tp);
				case 3:
					return getBoolMapping(device, DS4Controls.Square, cState, eState, tp);
				case 4:
					return getBoolMapping(device, DS4Controls.Triangle, cState, eState, tp);
				case 5:
					return getBoolMapping(device, DS4Controls.Options, cState, eState, tp);
				case 6:
					return getBoolMapping(device, DS4Controls.Share, cState, eState, tp);
				case 7:
					return getBoolMapping(device, DS4Controls.DpadUp, cState, eState, tp);
				case 8:
					return getBoolMapping(device, DS4Controls.DpadDown, cState, eState, tp);
				case 9:
					return getBoolMapping(device, DS4Controls.DpadLeft, cState, eState, tp);
				case 10:
					return getBoolMapping(device, DS4Controls.DpadRight, cState, eState, tp);
				case 11:
					return getBoolMapping(device, DS4Controls.PS, cState, eState, tp);
				case 12:
					return getBoolMapping(device, DS4Controls.L1, cState, eState, tp);
				case 13:
					return getBoolMapping(device, DS4Controls.R1, cState, eState, tp);
				case 14:
					return getBoolMapping(device, DS4Controls.L2, cState, eState, tp);
				case 15:
					return getBoolMapping(device, DS4Controls.R2, cState, eState, tp);
				case 16:
					return getBoolMapping(device, DS4Controls.L3, cState, eState, tp);
				case 17:
					return getBoolMapping(device, DS4Controls.R3, cState, eState, tp);
				case 18:
					return getBoolMapping(device, DS4Controls.TouchLeft, cState, eState, tp);
				case 19:
					return getBoolMapping(device, DS4Controls.TouchUpper, cState, eState, tp);
				case 20:
					return getBoolMapping(device, DS4Controls.TouchMulti, cState, eState, tp);
				case 21:
					return getBoolMapping(device, DS4Controls.TouchRight, cState, eState, tp);
				case 22:
					return getBoolMapping(device, DS4Controls.GyroZNeg, cState, eState, tp);
				case 23:
					return getBoolMapping(device, DS4Controls.GyroZPos, cState, eState, tp);
				case 24:
					return getBoolMapping(device, DS4Controls.GyroXPos, cState, eState, tp);
				case 25:
					return getBoolMapping(device, DS4Controls.GyroXNeg, cState, eState, tp);
				case 26:
					return cState.Touch1;
				default:
					return false;
			}
		}
示例#21
0
		public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState, DS4StateExposed eState, Mouse tp)
		{
			DS4Color color;
			if (!defualtLight && !forcelight[deviceNum])
			{
				if (Global.UseCustomLed[deviceNum])
				{
					if (Global.LedAsBatteryIndicator[deviceNum])
					{
						DS4Color fullColor = Global.CustomColor[deviceNum];
						DS4Color lowColor = Global.LowColor[deviceNum];

						color = Global.getTransitionedColor(lowColor, fullColor, device.Battery);
					}
					else
					{
						color = Global.CustomColor[deviceNum];
					}
				}
				else
				{
					if (Global.Rainbow[deviceNum] > 0)
					{
						// Display rainbow
						DateTime now = DateTime.UtcNow;
						if (now >= oldnow + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
						{
							oldnow = now;
							if (device.Charging)
							{
								counters[deviceNum] -= 1.5 * 3 / Global.Rainbow[deviceNum];
							}
							else
							{
								counters[deviceNum] += 1.5 * 3 / Global.Rainbow[deviceNum];
							}
						}
						if (counters[deviceNum] < 0)
						{
							counters[deviceNum] = 180000;
						}
						if (counters[deviceNum] > 180000)
						{
							counters[deviceNum] = 0;
						}

						color = Global.LedAsBatteryIndicator[deviceNum]
							? HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.Battery))
							: HuetoRGB((float)counters[deviceNum] % 360, 255);
					}
					else if (Global.LedAsBatteryIndicator[deviceNum])
					{
						//if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation
						{
							DS4Color fullColor = Global.MainColor[deviceNum];
							DS4Color lowColor = Global.LowColor[deviceNum];

							color = Global.getTransitionedColor(lowColor, fullColor, (uint)device.Battery);
						}
					}
					else
					{
						color = Global.MainColor[deviceNum];
					}
				}

				if ((device.Battery <= Global.FlashAt[deviceNum]) && !defualtLight && !device.Charging)
				{
					if (!((Global.FlashColor[deviceNum].red == 0) &&
					      (Global.FlashColor[deviceNum].green == 0) &&
					      (Global.FlashColor[deviceNum].blue == 0)))
					{
						color = Global.FlashColor[deviceNum];
					}
					if (Global.FlashType[deviceNum] == 1)
					{
						if (fadetimer[deviceNum] <= 0)
						{
							fadedirection[deviceNum] = true;
						}
						else if (fadetimer[deviceNum] >= 100)
						{
							fadedirection[deviceNum] = false;
						}
						if (fadedirection[deviceNum])
						{
							fadetimer[deviceNum] += 1;
						}
						else
						{
							fadetimer[deviceNum] -= 1;
						}
						color = Global.getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
					}
				}

				if ((Global.IdleDisconnectTimeout[deviceNum] > 0) && Global.LedAsBatteryIndicator[deviceNum] && (!device.Charging || (device.Battery >= 100)))
				{
					//Fade lightbar by idle time
					TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.LastActive.Ticks);
					double botratio = timeratio.TotalMilliseconds;
					double topratio = TimeSpan.FromSeconds(Global.IdleDisconnectTimeout[deviceNum]).TotalMilliseconds;
					double ratio = botratio / topratio * 100;
					if ((ratio >= 50) && (ratio <= 100))
					{
						color = Global.getTransitionedColor(color, new DS4Color(0, 0, 0), (uint)((ratio - 50) * 2));
					}
					else if (ratio >= 100)
					{
						color = Global.getTransitionedColor(color, new DS4Color(0, 0, 0), 100);
					}
				}
				if (device.Charging && (device.Battery < 100))
				{
					switch (Global.ChargingType[deviceNum])
					{
						case 1:
							if (fadetimer[deviceNum] <= 0)
							{
								fadedirection[deviceNum] = true;
							}
							else if (fadetimer[deviceNum] >= 105)
							{
								fadedirection[deviceNum] = false;
							}
							if (fadedirection[deviceNum])
							{
								fadetimer[deviceNum] += .1;
							}
							else
							{
								fadetimer[deviceNum] -= .1;
							}
							color = Global.getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
							break;
						case 2:
							counters[deviceNum] += .167;
							color = HuetoRGB((float)counters[deviceNum] % 360, 255);
							break;
						case 3:
							color = Global.ChargingColor[deviceNum];
							break;
					}
				}
			}
			else if (forcelight[deviceNum])
			{
				color = forcedColor[deviceNum];
			}
			else if (shuttingdown)
			{
				color = new DS4Color(0, 0, 0);
			}
			else
			{
				color = device.ConnectionType == ConnectionType.BT ? new DS4Color(32, 64, 64) : new DS4Color(0, 0, 0);
			}
			bool distanceprofile = Global.ProfilePath[deviceNum].ToLower().Contains("distance") || Global.tempprofilename[deviceNum].ToLower().Contains("distance");
			if (distanceprofile && !defualtLight)
			{
				//Thing I did for Distance
				float rumble = device.LeftHeavySlowRumble / 2.55f;
				byte max = Math.Max(color.red, Math.Max(color.green, color.blue));
				color = device.LeftHeavySlowRumble > 100
					? Global.getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), rumble)
					: Global.getTransitionedColor(color, Global.getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.LeftHeavySlowRumble);
			}
			DS4HapticState haptics = new DS4HapticState
			{
				LightBarColor = color
			};
			if (haptics.IsLightBarSet())
			{
				if (forcelight[deviceNum] && (forcedFlash[deviceNum] > 0))
				{
					haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(25 - forcedFlash[deviceNum]);
					haptics.LightBarExplicitlyOff = true;
				}
				else if ((device.Battery <= Global.FlashAt[deviceNum]) && (Global.FlashType[deviceNum] == 0) && !defualtLight && !device.Charging)
				{
					int level = device.Battery / 10;
					//if (level >= 10)
					//level = 0; // all values of ~0% or >~100% are rendered the same
					haptics.LightBarFlashDurationOn = BatteryIndicatorDurations[level, 0];
					haptics.LightBarFlashDurationOff = BatteryIndicatorDurations[level, 1];
				}
				else if (distanceprofile && (device.LeftHeavySlowRumble > 155)) //also part of Distance
				{
					haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(-device.LeftHeavySlowRumble + 265);
					haptics.LightBarExplicitlyOff = true;
				}
				else
				{
					//haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
					haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 0;
					haptics.LightBarExplicitlyOff = true;
				}
			}
			else
			{
				haptics.LightBarExplicitlyOff = true;
			}
			if ((device.LightBarOnDuration != haptics.LightBarFlashDurationOn) && (device.LightBarOnDuration != 1) && (haptics.LightBarFlashDurationOn == 0))
			{
				haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
			}
			if (device.LightBarOnDuration == 1) //helps better reset the color
			{
				Thread.Sleep(5);
			}
			device.PushHapticState(haptics);
		}
示例#22
0
        private void ds4_Tick(object sender, EventArgs e)
        {
            if (Program.RootHub.DS4Controllers[0] == null)
            {
                return;
            }

            cState = Program.RootHub.GetDS4State(0);
            if (btnRecord.Text != Resources.StopText)
            {
                return;
            }

            if (cBRecordDelays.Checked)
            {
                Mouse touchPad = Program.RootHub.touchPad[0];
                if (touchPad.leftDown && !storedTouchPad[0])
                {
                    if (!btnRumble.Text.Contains("Stop"))
                    {
                        btnRumble_Click(sender, e);
                    }
                    else if (!touchPad.leftDown && storedTouchPad[0])
                    {
                        if (btnRumble.Text.Contains("Stop"))
                        {
                            btnRumble_Click(sender, e);
                        }
                    }
                }

                if (touchPad.rightDown && !storedTouchPad[1])
                {
                    if (!btnLightbar.Text.Contains("Reset"))
                    {
                        btnLightbar_Click(sender, e);
                    }
                    else if (!touchPad.rightDown && storedTouchPad[1])
                    {
                        if (btnLightbar.Text.Contains("Reset"))
                        {
                            btnLightbar_Click(sender, e);
                        }
                    }
                }

                storedTouchPad[0] = touchPad.leftDown;
                storedTouchPad[1] = touchPad.rightDown;
            }

            foreach (DS4Controls control in controls)
            {
                if (Mapping.getBoolMapping(0, control, cState, null, null))
                {
                    int value = DS4ControltoInt(control);

                    if (macros.Count == 0)
                    {
                        AddMacroValue(value);
                        lVMacros.Items.Add(DS4ControltoX360(control), 0);
                        if (cBRecordDelays.Checked)
                        {
                            stopwatch.Reset();
                            stopwatch.Start();
                        }
                    }
                    else if (macros.Count(i => i == value) % 2 == 0)
                    {
                        if (cBRecordDelays.Checked)
                        {
                            AddMacroValue((int)stopwatch.ElapsedMilliseconds + 300);
                            lVMacros.Items.Add(Resources.WaitMS.Replace("*number*", stopwatch.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
                            stopwatch.Reset();
                            stopwatch.Start();
                        }
                        AddMacroValue(value);
                        lVMacros.Items.Add(DS4ControltoX360(control), 0);
                    }

                    lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
                }
                else
                {
                    if (macros.Count == 0)
                    {
                        continue;
                    }

                    int value = DS4ControltoInt(control);

                    if (macros.Count(i => i == value) % 2 != 1)
                    {
                        continue;
                    }

                    if (cBRecordDelays.Checked)
                    {
                        AddMacroValue((int)stopwatch.ElapsedMilliseconds + 300);
                        lVMacros.Items.Add(Resources.WaitMS.Replace("*number*", stopwatch.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
                        stopwatch.Reset();
                        stopwatch.Start();
                    }

                    AddMacroValue(value);
                    lVMacros.Items.Add(DS4ControltoX360(control), 1);
                    lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
                }
            }
        }
示例#23
0
 private void synthesizeMouseButtons()
 {
     if ((Global.GetDS4Action(deviceNum, DS4Controls.TouchLeft.ToString(), false) == null) && leftDown)
     {
         Mapping.MapClick(deviceNum, Mapping.Click.Left);
         dragging2 = true;
     }
     else
     {
         dragging2 = false;
     }
     if ((Global.GetDS4Action(deviceNum, DS4Controls.TouchUpper.ToString(), false) == null) && upperDown)
     {
         Mapping.MapClick(deviceNum, Mapping.Click.Middle);
     }
     if ((Global.GetDS4Action(deviceNum, DS4Controls.TouchRight.ToString(), false) == null) && rightDown)
     {
         Mapping.MapClick(deviceNum, Mapping.Click.Left);
     }
     if ((Global.GetDS4Action(deviceNum, DS4Controls.TouchMulti.ToString(), false) == null) && multiDown)
     {
         Mapping.MapClick(deviceNum, Mapping.Click.Right);
     }
     if (!Global.UseTPforControls[deviceNum])
     {
         if (tappedOnce)
         {
             DateTime tester = DateTime.Now;
             if (tester > TimeofEnd + TimeSpan.FromMilliseconds(Global.TapSensitivity[deviceNum] * 1.5))
             {
                 Mapping.MapClick(deviceNum, Mapping.Click.Left);
                 tappedOnce = false;
             }
             //if it fails the method resets, and tries again with a new tester value (gives tap a delay so tap and hold can work)
         }
         if (secondtouchbegin) //if tap and hold (also works as double tap)
         {
             Mapping.MapClick(deviceNum, Mapping.Click.Left);
             dragging = true;
         }
         else
         {
             dragging = false;
         }
     }
     state = remapped;
     //remapped.CopyTo(s);
 }