/// <inheritdoc /> protected override void DoBegin() { if (VibrationAction == null) { return; } VibrationAction.Execute(StartDelay, Duration, Frequency, Intensity, Controller); }
public void VibrateCustomVibrate(string action) { var actions = VibrationAction.StringToActions(action); VibrationCreator.Instance.Play(actions, MyGameManager.Instance); }
private void OnTimedEvent() { lock (lockObject) { List <RepeatPattern> removeList = new List <RepeatPattern>(); foreach (RepeatPattern repeatP in repeatablePatternList) { if (repeatP.pattern.IsRepeating() && repeatP.endTime <= getTimeMilliseconds()) { long startTime = getTimeMilliseconds(); List <SimplePattern> simplePatternList = repeatP.pattern.GetSimplePatterns(); repeatP.endTime = startTime + Pattern.Utils.GetMaxDuration(simplePatternList); PlaySimplePatterns(simplePatternList, startTime, false); } if (!repeatP.pattern.IsRepeating() && repeatP.endTime <= getTimeMilliseconds()) { //stop Motors foreach (SimplePattern sp in repeatP.pattern.GetSimplePatterns()) { actions.Add(new VibrationAction(sp.GetMotor(), repeatP.endTime, 0)); } removeList.Add(repeatP); } } foreach (RepeatPattern repeatP in removeList) { repeatablePatternList.Remove(repeatP); } } lock (lockObject) { if (getTimeMilliseconds() < lastSend + MIN_DELAY_BETWEEN_SENDS) { return; } long currentTime = getTimeMilliseconds(); List <VibrationAction> tempActions = new List <VibrationAction>(); foreach (VibrationAction action in actions) { if (action.actionTime <= currentTime) { tempActions.Add(action); } } if (tempActions.Count == 0) { return; //Nothing to do } foreach (VibrationAction action in tempActions) { actions.Remove(action); // Remove the action from the actions list } List <VibrationAction> actionsToDo = new List <VibrationAction>(); for (int i = 0; i < NUMBER_OF_MOTORS; i++) { // Look for actions in tempActions that have the same motor and only use the newest List <VibrationAction> actionsByMotorID = GetVibrationActionByMotor(tempActions, i); VibrationAction actionToAdd = actionsByMotorID.FirstOrDefault(); foreach (VibrationAction action in actionsByMotorID) { if (actionToAdd.actionTime < action.actionTime) { actionToAdd = action; } } if (actionToAdd != null) { actionsToDo.Add(actionToAdd); } } byte[] strengthArray = lastStrengthArray; strengthArray[0] = 0xFF; //Add 0xFF as first byte to indicate control over all motors foreach (VibrationAction action in actionsToDo) { actions.Remove(action); //Console.WriteLine("Performing action \t" + (getTimeMilliseconds() - action.actionTime) + "ms \tafter scheduled time. " + "Last Action before \t" + (getTimeMilliseconds() - lastSend) + "ms. "); strengthArray[action.motorID + 1] = action.strength; } if (getTimeMilliseconds() < lastSend + MIN_DELAY_BETWEEN_SENDS + 10) { //Console.WriteLine("Sending after " + (getTimeMilliseconds() - lastSend) + "ms"); } //Console.WriteLine(getTimeMilliseconds() + " Performing change: " + Main.ByteArrayToString(strengthArray)); tactPlayConnection.SendBytes(strengthArray); lastSend = getTimeMilliseconds(); } }
/// <inheritdoc /> protected override void DoCancel() { VibrationAction.Execute(0f, float.Epsilon, float.Epsilon, float.Epsilon, Controller); }