public void PlaySoundEffect(SoundEffect effect, FeedbackMode mode) { if (mode == FeedbackMode.Off || effect == SoundEffect.None || (mode == FeedbackMode.Default && Feedback.SoundMode == FeedbackMode.Off || _audio is null || _soundPool is null)) { return; } if (mode == FeedbackMode.Default) { if (Feedback.HapticMode != FeedbackMode.On) { var enabled = Android.Provider.Settings.System.GetInt(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.System.SoundEffectsEnabled) != 0; if (!enabled) { return; } } } switch (effect) { case SoundEffect.None: return; case SoundEffect.KeyClick: _audio.PlaySoundEffect(Android.Media.SoundEffect.KeyClick); break; case SoundEffect.Return: _audio.PlaySoundEffect(Android.Media.SoundEffect.Return); break; case SoundEffect.Delete: _audio.PlaySoundEffect(Android.Media.SoundEffect.Delete); break; case SoundEffect.Info: _soundPool.Play(notificationId, 1, 1, 0, 0, 1); break; case SoundEffect.Message: _soundPool.Play(messageId, 1, 1, 0, 0, 1); break; case SoundEffect.Alert: _soundPool.Play(alertId, 1, 1, 0, 0, 1); break; case SoundEffect.Alarm: _soundPool.Play(alarmId, 1, 1, 0, 0, 1); break; case SoundEffect.Error: _soundPool.Play(errorId, 1, 1, 0, 0, 1); break; } }
public void setFrequency(float frequency) { var prev_feedback_mode = feedback_mode; _feedback_mode = FeedbackMode.FixedFrequency; try { engine.SetFrequency(frequency); } catch (EngineMessageException) { _feedback_mode = prev_feedback_mode; throw; } }
public Pen(uint touchPoints, FeedbackMode mode) { if (!IsSupported) { throw new ExternalException("Not Supported on your OS."); } _contact = new POINTER_PEN_INFO(); _contact.pointerInfo.pointerType = TouchApi.PT_PEN; _contact.pointerInfo.pointerId = 0; _contact.pressure = 32000; _contact.penFlags = TouchApi.PEN_FLAG_NONE; _contact.penMask = TouchApi.PEN_MASK_PRESSURE; if (!TouchApi.InitializeTouchInjection(touchPoints, (uint)mode)) { throw new ExternalException("Initialisation failed. Code: " + Marshal.GetLastWin32Error()); } }
public void PlaySoundEffect(SoundEffect effect, FeedbackMode mode) { if (mode == FeedbackMode.Off || effect == SoundEffect.None || (mode == FeedbackMode.Default && Feedback.SoundMode != FeedbackMode.On)) { return; } switch (effect) { case SoundEffect.KeyClick: click.PlaySystemSound(); break; case SoundEffect.Return: modifier.PlaySystemSound(); break; case SoundEffect.Delete: delete.PlaySystemSound(); break; case SoundEffect.Info: notificationPlayer.Play(); break; case SoundEffect.Message: messagePlayer.Play(); break; case SoundEffect.Alert: alertPlayer.Play(); break; case SoundEffect.Alarm: alarmPlayer.Play(); break; case SoundEffect.Error: errorPlayer.Play(); break; } }
/// <summary> /// Create a Touch emulator instance /// </summary> /// <param name="touchPoints">Number of concurrent touch points</param> /// <param name="mode">Feedback mode</param> public Touch(int touchPoints, FeedbackMode mode) { if (!IsSupported) { throw new ExternalException("Not Supported on your OS."); } _contact = new POINTER_TOUCH_INFO(); _contact.pointerInfo.pointerType = TouchApi.PT_TOUCH; _contact.pointerInfo.pointerId = 0; //contact 0 _contact.orientation = 90; // Orientation of 90 means touching perpendicular to screen. _contact.pressure = 32000; _contact.touchFlags = TouchApi.POINTER_FLAG_NONE; _contact.touchMask = TouchApi.TOUCH_MASK_CONTACTAREA | TouchApi.TOUCH_MASK_ORIENTATION | TouchApi.TOUCH_MASK_PRESSURE; if (!TouchApi.InitializeTouchInjection((uint)touchPoints, (uint)mode)) { throw new ExternalException("Initialisation failed. Code: " + Marshal.GetLastWin32Error()); } }
public static int GetMaximumAmplifierOutput( int initialInput, int numberOfAmplifiers, BigInteger[] program, FeedbackMode feedbackMode) { int maxOutput = int.MinValue; int[] phaseValues; if (FeedbackMode.Normal.Equals(feedbackMode)) { // Phase values between 1 and N phaseValues = Enumerable.Range(0, numberOfAmplifiers).ToArray(); } else if (FeedbackMode.Loop.Equals(feedbackMode)) { // Phase values between N and 2N phaseValues = Enumerable.Range(numberOfAmplifiers, numberOfAmplifiers).ToArray(); } else { throw new Exception($"Invalid feedback mode {feedbackMode}"); } var phaseValuesPermutations = new Permutations <int>(phaseValues); foreach (IList <int> amplifierPhaseSettings in phaseValuesPermutations) { var output = GetAmplifierOutput( initialInput, amplifierPhaseSettings.ToArray(), program, feedbackMode); if (output > maxOutput) { maxOutput = output; } } return(maxOutput); }
public void Feedback(HapticEffect effect, FeedbackMode mode = FeedbackMode.Default) { if (effect == HapticEffect.None || mode == FeedbackMode.Off || (mode == FeedbackMode.Default && Forms9Patch.Feedback.HapticMode == FeedbackMode.Off)) { return; } var hapticEnabled = true; if (mode == FeedbackMode.Default) { hapticEnabled = Android.Provider.Settings.System.GetInt(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.System.HapticFeedbackEnabled) != 0; } if (hapticEnabled && AppEnabled) { if (effect == HapticEffect.Selection) { Settings.Activity.Window.DecorView.PerformHapticFeedback(Android.Views.FeedbackConstants.KeyboardTap); } else if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O) { VibrationEffect droidEffect = null; switch (effect) { case HapticEffect.LightImpact: droidEffect = VibrationEffect.CreateOneShot(200, 128); break; case HapticEffect.MediumImpact: droidEffect = VibrationEffect.CreateOneShot(200, 196); break; case HapticEffect.HeavyImpact: droidEffect = VibrationEffect.CreateOneShot(200, 255); break; case HapticEffect.ErrorNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200, 100, 200 }, new int[] { 0, 196, 0, 196, 0, 255 }, -1); break; case HapticEffect.WarningNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200 }, new int[] { 0, 196, 0, 255 }, -1); break; case HapticEffect.SuccessNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200 }, new int[] { 0, 255, 0, 196 }, -1); break; case HapticEffect.Long: droidEffect = VibrationEffect.CreateOneShot(800, 255); break; } if (droidEffect != null) { _vibrator.Vibrate(droidEffect); } } else { #pragma warning disable CS0618 // Type or member is obsolete long[] pattern = null; switch (effect) { case HapticEffect.LightImpact: _vibrator.Vibrate(200, Attributes); break; case HapticEffect.MediumImpact: _vibrator.Vibrate(300, Attributes); break; case HapticEffect.HeavyImpact: _vibrator.Vibrate(400, Attributes); break; case HapticEffect.ErrorNotification: pattern = new long[] { 0, 200, 100, 200, 100, 200 }; break; case HapticEffect.WarningNotification: pattern = new long[] { 0, 200, 100, 200 }; break; case HapticEffect.SuccessNotification: pattern = new long[] { 0, 200, 100, 200 }; break; case HapticEffect.Long: _vibrator.Vibrate(800, Attributes); break; } if (pattern != null) { _vibrator.Vibrate(pattern, -1, Attributes); } #pragma warning restore CS0618 // Type or member is obsolete } } }
public static int GetAmplifierOutput( int initialInput, int[] phaseSettings, BigInteger[] program, FeedbackMode feedbackMode) { // Initialize the amplifiers var numberOfAmplifiers = phaseSettings.Length; var amplifiers = new List <Tuple <IntcodeComputer, BufferedInputProvider, ListOutputListener> >(numberOfAmplifiers); for (int i = 0; i < numberOfAmplifiers; i++) { var inputProvider = new BufferedInputProvider(); inputProvider.AddInputValue(phaseSettings[i]); if (i == 0) { inputProvider.AddInputValue(initialInput); } var outputListener = new ListOutputListener(); var computer = new IntcodeComputer(inputProvider, outputListener); computer.LoadProgram(program); amplifiers.Add(new Tuple <IntcodeComputer, BufferedInputProvider, ListOutputListener>( computer, inputProvider, outputListener)); } int currentAmplifierIndex = 0; int round = 1; BigInteger output; while (true) { var currentAmplifier = amplifiers[currentAmplifierIndex]; var computer = currentAmplifier.Item1; var outputListener = currentAmplifier.Item3; var status = computer.RunProgram(); if (!IntcodeProgramStatus.AwaitingInput.Equals(status) && !IntcodeProgramStatus.Completed.Equals(status)) { throw new Exception($"Program halted with invalid status: {status}"); } if (outputListener.Values.Count == 0) { throw new Exception("No output received"); } output = outputListener.Values.Last(); // The program has completed, break out if (currentAmplifierIndex == numberOfAmplifiers - 1 && IntcodeProgramStatus.Completed.Equals(status)) { break; } // The program hasn't finished... // Pass the output from this amplifier to the input of the next var nextAmplifierIndex = currentAmplifierIndex + 1; if (nextAmplifierIndex >= numberOfAmplifiers) { nextAmplifierIndex = 0; } var nextAmplifier = amplifiers[nextAmplifierIndex]; var nextAmplifierInputProvider = nextAmplifier.Item2; nextAmplifierInputProvider.AddInputValue(output); currentAmplifierIndex++; if (currentAmplifierIndex == numberOfAmplifiers) { if (FeedbackMode.Normal.Equals(feedbackMode)) { break; } else if (FeedbackMode.Loop.Equals(feedbackMode)) { currentAmplifierIndex = 0; round++; } } } return((int)output); }
public void Feedback(HapticEffect effect, FeedbackMode mode = FeedbackMode.Default) { if (mode == FeedbackMode.Off || effect == HapticEffect.None || (mode == FeedbackMode.Default && Forms9Patch.Feedback.HapticMode == FeedbackMode.Off) || !UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { return; } switch (effect) { case HapticEffect.Selection: { using (var selection = new UISelectionFeedbackGenerator()) { selection.Prepare(); selection.SelectionChanged(); } } break; case HapticEffect.LightImpact: { using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Light)) { impact.Prepare(); impact.ImpactOccurred(); } } break; case HapticEffect.MediumImpact: { using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Medium)) { impact.Prepare(); impact.ImpactOccurred(); } } break; case HapticEffect.HeavyImpact: { using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Heavy)) { impact.Prepare(); impact.ImpactOccurred(); } } break; case HapticEffect.ErrorNotification: { // Initialize feedback using (var notification = new UINotificationFeedbackGenerator()) { notification.Prepare(); notification.NotificationOccurred(UINotificationFeedbackType.Error); } } break; case HapticEffect.WarningNotification: { // Initialize feedback using (var notification = new UINotificationFeedbackGenerator()) { notification.Prepare(); notification.NotificationOccurred(UINotificationFeedbackType.Warning); } } break; case HapticEffect.SuccessNotification: { // Initialize feedback using (var notification = new UINotificationFeedbackGenerator()) { notification.Prepare(); notification.NotificationOccurred(UINotificationFeedbackType.Success); } } break; case HapticEffect.Long: vibrate.PlaySystemSound(); break; } }
public void setRpmTarget(float rpm) { _feedback_mode = FeedbackMode.FixedRPM; rpm_target = rpm; }
public void Initialize() { _allScenarioPaths = Resources.LoadAll("Scenarios").Select(t => t.name).ToArray(); var streamingAssetsPath = Path.Combine(Application.streamingAssetsPath, "levelconfig.json"); var www = new WWW((Application.platform != RuntimePlatform.Android ? "file:///" : string.Empty) + streamingAssetsPath); while (!www.isDone) { } var obj = JsonConvert.DeserializeObject <RoundConfig>(www.text); // If no round value is provided in CustomArgs, Round is set to 1 if lockafterq is a CustomArgs key and is true, set to 2 otherwise var parseLockAfterQ = false; if (CommandLineUtility.CustomArgs.ContainsKey("lockafterq")) { bool.TryParse(CommandLineUtility.CustomArgs["lockafterq"], out parseLockAfterQ); } var hasPilotArgs = CommandLineUtility.CustomArgs.ContainsKey("feedback") && CommandLineUtility.CustomArgs.ContainsKey("lockafterq"); var gameUnlocked = PlayerPrefs.GetInt("GameUnlocked") == 1; RoundNumber = SUGARManager.CurrentUser != null && hasPilotArgs ? parseLockAfterQ ? 1 : 2 : gameUnlocked ? 2 : 0; int parseFeedback; FeedbackLevel = SUGARManager.CurrentUser != null && CommandLineUtility.CustomArgs.ContainsKey("feedback") ? int.TryParse(CommandLineUtility.CustomArgs["feedback"], out parseFeedback) ? (FeedbackMode)parseFeedback : FeedbackMode.EndGame : (FeedbackMode)PlayerPrefs.GetInt("Feedback", (int)FeedbackMode.EndGame); PlayerPrefs.SetInt("Feedback", (int)FeedbackLevel); var round = obj.Rounds[RoundNumber]; CurrentLevel = PlayerPrefs.GetInt("CurrentLevel" + RoundNumber, 0); _isDemo = (CommandLineUtility.CustomArgs == null || CommandLineUtility.CustomArgs.Count == 0) && !hasPilotArgs && !gameUnlocked && CurrentLevel <= 0; if (_isDemo) { var prefix = _demoScenarioPrefix + _demoUtterance; _scenarios = round.Levels.Select(level => new ScenarioData(level.Id, _allScenarioPaths.Where(x => x.Contains(prefix)).ToArray(), level.Character, level.MaxPoints, level.Prefix)).ToArray(); } else { _scenarios = round.Levels.Select(level => new ScenarioData(level.Id, _allScenarioPaths.Where(x => x.Contains(level.Prefix)).ToArray(), level.Character, level.MaxPoints, level.Prefix)).ToArray(); } LevelMax = _scenarios.Length; // Boolean for checking if the post game questionnaire is opened after the round bool parseInGameQ; UseInGameQuestionnaire = SUGARManager.CurrentUser != null && CommandLineUtility.CustomArgs.ContainsKey("ingameq") && bool.TryParse(CommandLineUtility.CustomArgs["ingameq"], out parseInGameQ) && parseInGameQ; if (CurrentLevel >= LevelMax) { if (SUGARManager.CurrentUser != null) { if (parseLockAfterQ) { CurrentLevel = LevelMax; } else { PlayerPrefs.SetInt("GameUnlocked", 1); CurrentLevel = 0; } } else { CurrentLevel = 0; } } }