private void ReadingChangedforVibrator(object sender, AccelerometerReadingChangedEventArgs e) { AccelerometerReading reading = e.Reading; string sMessage = ""; if (Math.Abs(reading.AccelerationX - 0.09) > 0.07 || Math.Abs(reading.AccelerationY - 0.01) > 0.05 || Math.Abs(Math.Abs(reading.AccelerationZ) - 0.96) > 0.4) { sMessage = ""; sMessage += "Round" + TestRound + "->" + TestCount + ":VibrationDevice Success."; sMessage += "\r\n"; Vlog.WriteText(sMessage); } else { sMessage = ""; sMessage += "Round" + TestRound + "->" + TestCount + ":VibrationDevice Failed."; sMessage += "\r\n"; Vlog.WriteText(sMessage); } _accelerometer.ReportInterval = 0; _accelerometer.ReadingChanged -= new Windows.Foundation.TypedEventHandler <Windows.Devices.Sensors.Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChangedforVibrator); if (TestCount >= TestMaxCount) { Vtimer.Cancel(); TestCount = 0; Gtimer = ThreadPoolTimer.CreatePeriodicTimer(Gyrometer_Timer_Tick, TimeSpan.FromMilliseconds(2000)); } }
private async Task GetVbrationDevice() { if (await VibrationDevice.RequestAccessAsync() != VibrationAccessStatus.Allowed) { Vlog.WriteText("VibrationAccessStatus failed."); return; } VibrationDevice = await VibrationDevice.GetDefaultAsync(); if (VibrationDevice != null) { BuzzFeedback = FindFeedback(); } }
private void Vibrator_Timer_Tick(ThreadPoolTimer timer) { TestCount++; string sMessage = ""; if (VibrationDevice == null) { sMessage += "Round" + TestRound + "->" + TestCount + ":VibrationDevice is null.\r\n"; Vlog.WriteText(sMessage); return; } VibrationDevice.SimpleHapticsController.SendHapticFeedbackForDuration(BuzzFeedback, 1, TimeSpan.FromMilliseconds(4000)); //Use Accelerometer value to check vibrator have vibrated or not uint minReportIntervalMsecs = _accelerometer.MinimumReportInterval; _accelerometer.ReportInterval = minReportIntervalMsecs > 16 ? minReportIntervalMsecs : 16; _accelerometer.ReadingChanged += new Windows.Foundation.TypedEventHandler <Windows.Devices.Sensors.Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChangedforVibrator); }