Ejemplo n.º 1
0
 public async Task <bool> RequestVibrationAccess()
 {
     try
     {
         Vibration = await VibrationDevice.RequestAccessAsync();
     }
     catch
     {
         Vibration = null;
     }
     return(Vibration.HasValue);
 }
Ejemplo n.º 2
0
        private async Task GetVbrationDevice()
        {
            if (await VibrationDevice.RequestAccessAsync() != VibrationAccessStatus.Allowed)
            {
                return;
            }
            VibrationDevice = await VibrationDevice.GetDefaultAsync();

            if (VibrationDevice != null)
            {
                BuzzFeedback = FindFeedback();
            }
        }
Ejemplo n.º 3
0
        public async Task LoadAsync()
        {
            var result = await VibrationDevice.RequestAccessAsync();

            if (result == VibrationAccessStatus.Allowed)
            {
                var vibrationDevice = await VibrationDevice.GetDefaultAsync();

                if (vibrationDevice != null)
                {
                    _simpleHapticsController = vibrationDevice.SimpleHapticsController;

                    Status      = "VibrationDevice is available";
                    IsAvailable = true;
                    return;
                }
            }

            Status = $"VibrationDevice is not available ({result})";
        }
Ejemplo n.º 4
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;
                    }
                }
            }
        }
Ejemplo n.º 5
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;
                }
            });
        }
Ejemplo n.º 6
0
        public async void Perform(HapticFeedbackType type)
        {
            try
            {
                if (ApiInformation.IsTypePresent(vibrationDeviceApiType) &&
                    await VibrationDevice.RequestAccessAsync() == VibrationAccessStatus.Allowed)
                {
                    var controller = (await VibrationDevice.GetDefaultAsync())?.SimpleHapticsController;

                    if (controller != null)
                    {
                        var feedback = FindFeedback(controller, ConvertType(type));
                        if (feedback != null)
                        {
                            controller.SendHapticFeedback(feedback);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
            }
        }