// The PointerEnter event will get fired as soon as Pointer input is received. // This event handler implementation will query the device providing input to see if it's a pen and // then check to see the pen supports tactile feedback private void MainGrid_Entered(object sender, PointerRoutedEventArgs e) { // If the current Pointer device is not a pen, exit if (e.Pointer.PointerDeviceType != PointerDeviceType.Pen) { return; } // Attempt to retrieve the PenDevice from the current PointerId penDevice = PenDevice.GetFromPointerId(e.Pointer.PointerId); // If a PenDevice cannot be retrieved based on the PointerId, it does not support // advanced pen features, such as tactile feedback if (penDevice == null) { statusText.Text = "Advanced pen features not supported"; return; } // Check to see if the current PenDevice supports tactile feedback by seeing if it // has a SimpleHapticsController hapticsController = penDevice.SimpleHapticsController; if (hapticsController == null) { statusText.Text = "This pen does not provide tactile feedback"; return; } }
/// <summary> /// Start haptic feedback on the interaction source with the specified intensity and continue for the specified amount of time. /// </summary> /// <param name="interactionSource">The source to start haptics on.</param> /// <param name="intensity">The strength of the haptic feedback from 0.0 (no haptics) to 1.0 (maximum strength).</param> /// <param name="durationInSeconds">The time period expressed in seconds.</param> public static bool StartHaptics(this InteractionSource interactionSource, float intensity, float durationInSeconds) { if (!IsHapticsAvailable) { return(false); } #if WINDOWS_UWP || DOTNETWINRT_PRESENT SimpleHapticsController simpleHapticsController = interactionSource.GetSpatialInteractionSource()?.Controller.SimpleHapticsController; foreach (SimpleHapticsControllerFeedback hapticsFeedback in simpleHapticsController?.SupportedFeedback) { if (hapticsFeedback.Waveform.Equals(ContinuousBuzzWaveform)) { if (UnityEngine.Mathf.Approximately(durationInSeconds, float.MaxValue)) { simpleHapticsController.SendHapticFeedback(hapticsFeedback, intensity); } else { simpleHapticsController.SendHapticFeedbackForDuration(hapticsFeedback, intensity, TimeSpan.FromSeconds(durationInSeconds)); } return(true); } } #endif // WINDOWS_UWP || DOTNETWINRT_PRESENT return(false); }
public static void StartHaptics(this InteractionSource interactionSource, float intensity, float durationInSeconds) { #if !UNITY_EDITOR UnityEngine.WSA.Application.InvokeOnUIThread(() => { IReadOnlyList <SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now)); foreach (SpatialInteractionSourceState sourceState in sources) { if (sourceState.Source.Id.Equals(interactionSource.id)) { SimpleHapticsController simpleHapticsController = sourceState.Source.Controller.SimpleHapticsController; foreach (SimpleHapticsControllerFeedback hapticsFeedback in simpleHapticsController.SupportedFeedback) { if (hapticsFeedback.Waveform.Equals(ContinuousBuzzWaveform)) { if (durationInSeconds.Equals(float.MaxValue)) { simpleHapticsController.SendHapticFeedback(hapticsFeedback, intensity); } else { simpleHapticsController.SendHapticFeedbackForDuration(hapticsFeedback, intensity, TimeSpan.FromSeconds(durationInSeconds)); } return; } } } } }, true); #endif }
private void SendHapticFeedback(SimpleHapticsController simpleHapticsController, int count) { var feedback = simpleHapticsController.SupportedFeedback.FirstOrDefault(f => f.Waveform == KnownSimpleHapticsControllerWaveforms.Click); if (feedback != null) { simpleHapticsController.SendHapticFeedbackForPlayCount(feedback, 1, count, TimeSpan.FromMilliseconds(100)); } }
// Stop sending the tactile feedback and clear the current penDevice and hapticsController on PointerExit. // Stopping the feedback is important as it clears the tactile signal from the PenDevice's // SimpleHapticsController, ensuring that it has a clean state once it next enters range. private void MovableRect_Exited(object sender, PointerRoutedEventArgs e) { penDevice = null; statusText.Text = ""; if (hapticsController != null) { hapticsController.StopFeedback(); hapticsController = null; } }
static SimpleHapticsControllerFeedback FindFeedback(SimpleHapticsController controller, ushort type) { foreach (var feedback in controller.SupportedFeedback) { if (feedback.Waveform == type) { return(feedback); } } return(null); }
// Returns the first SimpleHapticsControllerFeedback supported by the provided SimpleHapticsController // which supports the specified waveform. public static SimpleHapticsControllerFeedback FindSupportedFeedback(SimpleHapticsController hapticsController, ushort waveform) { foreach (SimpleHapticsControllerFeedback feedback in hapticsController.SupportedFeedback) { if (feedback.Waveform == waveform) { return(feedback); } } return(null); }
private void SendHapticFeedback(SimpleHapticsController hapticController) { var feedbacks = hapticController.SupportedFeedback; foreach (SimpleHapticsControllerFeedback feedback in feedbacks) { if (feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Click) { hapticController.SendHapticFeedback(feedback); return; } } }
private void SendBuzzFeedback(SimpleHapticsController hapticController) { var feedbacks = hapticController.SupportedFeedback; foreach (SimpleHapticsControllerFeedback feedback in feedbacks) { if (feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Click) { //Click the RadialController 3 times, with a duration of 250ms between each click hapticController.SendHapticFeedbackForPlayCount(feedback, 1, 3, TimeSpan.FromMilliseconds(250)); return; } } }
// The PointerEnter event will get fired as soon as Pointer input is received. // This event handler implementation will query the device providing input to see if it's a pen and // then check to see the pen supports tactile feedback and, if so, configure the PenDevice // to send the appropriate tactile signal based on what is selected in the dropdown. private void HapticCanvas_Entered(object sender, PointerRoutedEventArgs e) { // If the current Pointer device is not a pen, exit if (e.Pointer.PointerDeviceType != PointerDeviceType.Pen) { return; } // Attempt to retrieve the PenDevice from the current PointerId penDevice = PenDevice.GetFromPointerId(e.Pointer.PointerId); // If a PenDevice cannot be retrieved based on the PointerId, it does not support // advanced pen features, such as tactile feedback if (penDevice == null) { statusText.Text = "Advanced pen features not supported"; return; } // Check to see if the current PenDevice supports tactile feedback by seeing if it // has a SimpleHapticsController hapticsController = penDevice.SimpleHapticsController; if (hapticsController == null) { statusText.Text = "This pen does not provide tactile feedback"; return; } // Get feedback based on the user's selected waveform currentFeedback = GetSelectedFeedbackOrFallback(out string message); // Send the current feedback to the PenDevice's SimpleHapticsController. // Once sent, inking tactile feedback will be triggered as soon as the pen tip touches // the screen and will be stopped once the pen tip is lifted from the screen. // Also, check to see if the current PenDevice's SimpleHapticsController supports // setting the intensity value of the tactile feedback. If so, set it based // on the slider. If not, send the waveform without custom intensity. if (hapticsController.IsIntensitySupported) { hapticsController.SendHapticFeedback(currentFeedback, intensitySlider.Value / 100); message += "\nIntensity set to " + intensitySlider.Value + "%"; } else { hapticsController.SendHapticFeedback(currentFeedback); message += "\nSetting intensity is not supported by this pen"; } statusText.Text = message; }
// The PointerEnter event will get fired as soon as Pointer input is received in the movableRect. // This event handler implementation will query the device providing input to see if it's a pen and // then check to see the pen supports tactile feedback and, if so, configure the PenDevice // to send the InkContinuous tactile signal. private void MovableRect_Entered(object sender, PointerRoutedEventArgs e) { // If the current Pointer device is not a pen, exit if (e.Pointer.PointerDeviceType != PointerDeviceType.Pen) { return; } // Attempt to retrieve the PenDevice from the current PointerId penDevice = PenDevice.GetFromPointerId(e.Pointer.PointerId); // If a PenDevice cannot be retrieved based on the PointerId, it does not support // advanced pen features, such as tactile feedback if (penDevice == null) { statusText.Text = "Advanced pen features not supported"; return; } // Check to see if the current PenDevice supports tactile feedback by seeing if it // has a SimpleHapticsController hapticsController = penDevice.SimpleHapticsController; if (hapticsController == null) { statusText.Text = "This pen does not provide tactile feedback"; return; } // Send the InkContinuous waveform to the PenDevice's SimpleHapticsController. // Once sent, inking continuous tactile feedback will be triggered as soon as the pen tip touches // the screen and will be stopped once the pen tip is lifted from the screen. // Also, check to see if the current PenDevice's SimpleHapticsController supports // setting the intensity value of the tactile feedback. If so, set it to 0.75. // If not, send the waveform with the default intensity. foreach (var waveform in hapticsController.SupportedFeedback) { if (waveform.Waveform == KnownSimpleHapticsControllerWaveforms.InkContinuous) { if (hapticsController.IsIntensitySupported) { hapticsController.SendHapticFeedback(waveform, 0.75); } else { hapticsController.SendHapticFeedback(waveform); } } } }
private async Task GetController() { var access = await VibrationDevice.RequestAccessAsync(); if (access == VibrationAccessStatus.Allowed) { var mgr = SpatialInteractionManager.GetForCurrentView(); var calendar = new Calendar(); var timestamp = PerceptionTimestampHelper.FromHistoricalTargetTime(calendar.GetDateTime()); controller = (from s in mgr.GetDetectedSourcesAtTimestamp(timestamp) where s.Source.Id == ControllerID select s.Source.Controller.SimpleHapticsController) .FirstOrDefault(); expressions = new Dictionary <ushort, SimpleHapticsControllerFeedback>(5); if (controller != null) { foreach (var fb in controller.SupportedFeedback) { if (fb.Waveform == KnownSimpleHapticsControllerWaveforms.BuzzContinuous) { buzz = fb; } else if (fb.Waveform == KnownSimpleHapticsControllerWaveforms.Click) { click = fb; } else if (fb.Waveform == KnownSimpleHapticsControllerWaveforms.Press) { press = fb; } else if (fb.Waveform == KnownSimpleHapticsControllerWaveforms.Release) { release = fb; } expressions[fb.Waveform] = fb; } } } }
// The PointerEnter event will get fired as soon as Pointer input is received. // This event handler implementation will query the device providing input to see if it's a pen and // then check to see the pen supports tactile feedback and, if so, what features it supports private void Pointer_Entered(object sender, PointerRoutedEventArgs e) { // If the current Pointer device is not a pen, exit if (e.Pointer.PointerDeviceType != PointerDeviceType.Pen) { supportedFeatures.Text = ""; supportedFeedback.Text = ""; return; } // Attempt to retrieve the PenDevice from the current PointerId penDevice = PenDevice.GetFromPointerId(e.Pointer.PointerId); // If a PenDevice cannot be retrieved based on the PointerId, it does not support // advanced pen features, such as tactile feedback if (penDevice == null) { statusText.Text = "Advanced pen features not supported"; supportedFeatures.Text = ""; supportedFeedback.Text = ""; return; } // Check to see if the current PenDevice supports tactile feedback by seeing if it // has a SimpleHapticsController hapticsController = penDevice.SimpleHapticsController; if (hapticsController == null) { statusText.Text = "This pen does not provide tactile feedback"; return; } // Check which tactile feedback features are supported supportedFeatures.Text = "Supported Haptics Features:\n"; if (hapticsController.IsIntensitySupported) { supportedFeatures.Text += "Intensity\n"; } if (hapticsController.IsPlayCountSupported) { supportedFeatures.Text += "PlayCount\n"; } if (hapticsController.IsPlayDurationSupported) { supportedFeatures.Text += "PlayDuration\n"; } if (hapticsController.IsReplayPauseIntervalSupported) { supportedFeatures.Text += "ReplayPauseInterval\n"; } // Check which feedback waveforms are supported supportedFeedback.Text = "Supported Feedback:\n"; foreach (SimpleHapticsControllerFeedback feedback in hapticsController.SupportedFeedback) { ushort waveform = feedback.Waveform; foreach (KeyValuePair <string, ushort> entry in MainPage.WaveformNamesMap) { if (entry.Value == waveform) { supportedFeedback.Text += entry.Key + "\n"; break; } } } statusText.Text = ""; }
// Clear the current penDevice and hapticsController on PointerExit private void Pointer_Exited(object sender, PointerRoutedEventArgs e) { penDevice = null; hapticsController = null; }