Exemple #1
0
        public void Vibrate(int milliseconds)
        {
            if (ApiInformation.IsTypePresent("Windows.Phone.Devices.Notification.VibrationDevice"))
            {
                var v = Task.Run(async() => await VibrationDevice.GetDefaultAsync()).Result;

                if (v == null)
                {
                    System.Diagnostics.Debug.WriteLine("Default vibration device not found.");
                    return;
                }

                if (milliseconds < 0)
                {
                    milliseconds = 0;
                }
                else if (milliseconds > 5000)
                {
                    milliseconds = 5000;
                }

                var time = TimeSpan.FromMilliseconds(milliseconds);
                // v.SimpleHapticsController.SendHapticFeedbackForDuration(new SimpleHapticsControllerFeedback(), 1, TimeSpan.FromMilliseconds(milliseconds));
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Vibration not supported on this device family.");
            }
        }
 public UWPDeviceInformationService()
 {
     easDevice     = new EasClientDeviceInformation();
     accelerometer = Accelerometer.GetDefault();
     gyrometer     = Gyrometer.GetDefault();
     magnetometer  = Magnetometer.GetDefault();
     try
     {
         vibrationDevice = VibrationDevice.GetDefaultAsync().GetResults();
     }
     catch { }
 }
        private async Task GetVbrationDevice()
        {
            if (await VibrationDevice.RequestAccessAsync() != VibrationAccessStatus.Allowed)
            {
                return;
            }
            VibrationDevice = await VibrationDevice.GetDefaultAsync();

            if (VibrationDevice != null)
            {
                BuzzFeedback = FindFeedback();
            }
        }
        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})";
        }
Exemple #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;
                }
            });
        }
        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}");
            }
        }