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); }
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; }
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; } }
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; }
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; }
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); }
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; } } }
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); }