// Send haptic feedback that matches the selected waveform upon the button being clicked
        private void SendFeedback_Clicked(object sender, RoutedEventArgs e)
        {
            if (hapticsController == null)
            {
                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, unlike inking feedback, this feedback will be played immediately.
            // 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 feedback 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;
        }
Example #2
0
 // 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 HapticCanvas_Exited(object sender, PointerRoutedEventArgs e)
 {
     penDevice       = null;
     statusText.Text = "";
     if (hapticsController != null)
     {
         hapticsController.StopFeedback();
         hapticsController = null;
         currentFeedback   = null;
     }
 }
        private async Task GetVbrationDevice()
        {
            if (await VibrationDevice.RequestAccessAsync() != VibrationAccessStatus.Allowed)
            {
                return;
            }
            VibrationDevice = await VibrationDevice.GetDefaultAsync();

            if (VibrationDevice != null)
            {
                BuzzFeedback = FindFeedback();
            }
        }
Example #4
0
        // 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;
        }
Example #5
0
 static string FeedbackToPattern(SimpleHapticsControllerFeedback feedback)
 {
     if (feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Click)
     {
         return(TapPattern);
     }
     else if (feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Press)
     {
         return(HoldPattern);
     }
     else
     {
         throw new NotSupportedException("Unsupported feedback waveform");
     }
 }
Example #6
0
        // Get feedback which matches the currently selected waveform in the dropdown.
        // To get the feedback, the SimpleHapticsController's SupportedFeedback list must be traversed
        // to see if a matching feedback is present.
        // This is important because InkContinuous is the only Inking waveform required to be
        // supported by every pen with haptics.
        // If no matching feedback is found in the SupportedFeedback list, this method returns
        // InkContinuous as a guaranteed fallback.
        private SimpleHapticsControllerFeedback GetSelectedFeedbackOrFallback(out string message)
        {
            // Look up the waveform the user selected.
            string name     = (string)waveformComboBox.SelectionBoxItem;
            ushort waveform = MainPage.WaveformNamesMap[name];

            // See if the haptics controller supports the selected waveform.
            SimpleHapticsControllerFeedback feedback = MainPage.FindSupportedFeedback(hapticsController, waveform);

            if (feedback != null)
            {
                message = "Waveform set to " + name;
                return(feedback);
            }

            // It does not. Use InkContinuous as a fallback.
            message = name + " is not supported by this pen, so falling back to InkContinuous";
            return(MainPage.FindSupportedFeedback(hapticsController, KnownSimpleHapticsControllerWaveforms.InkContinuous));
        }
Example #7
0
        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;
                    }
                }
            }
        }
Example #8
0
        private async Task GetVibrationDevice()
        {
            _isCheckedForVibrationDevice = true;

            // Requesting access and updating UI must happen on the UI thread
            await _coreDispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                var accessStatus = await VibrationDevice.RequestAccessAsync();
                Debug.WriteLine($"Vibration Access: {accessStatus}.");

                if (accessStatus != VibrationAccessStatus.Allowed)
                {
                    Status.Text = $"Vibration Access denied: {accessStatus}. ";

                    if (accessStatus == VibrationAccessStatus.DeniedByUser)
                    {
                        Status.Text += "Please check UI settings and make sure vibration is turned on.";
                    }

                    // Nothing else to do
                    return;
                }

                _vibrationDevice = await VibrationDevice.GetDefaultAsync();
                var status       = $"Vibration device {(_vibrationDevice == null ? "NOT" : _vibrationDevice.Id)} found. ";
                Debug.WriteLine(status);
                Status.Text = status;

                if (_vibrationDevice != null)
                {
                    _buzzFeedback = FindFeedback();
                    status        = $"Buzz feedback {(_buzzFeedback == null ? "NOT" : "")} supported by this device.";
                    Debug.WriteLine(status);
                    Status.Text += status;
                }
            });
        }
Example #9
0
        public void SendHapticFeedback(SimpleHapticsControllerFeedback feedback)
        {
            if (feedback is null)
            {
                throw new ArgumentNullException(nameof(feedback));
            }

            try
            {
                var tizenFeedback = new Feedback();
                var pattern       = FeedbackToPattern(feedback);
                if (tizenFeedback.IsSupportedPattern(FeedbackType.Vibration, pattern))
                {
                    tizenFeedback.Play(FeedbackType.Vibration, pattern);
                }
            }
            catch (Exception ex)
            {
                if (this.Log().IsEnabled(LogLevel.Error))
                {
                    this.Log().LogError($"Could not send haptic feedback: {ex}");
                }
            }
        }