• 使用手机重量加速器


     Accelerometer sensor;
            private void ApplicationBarMenuItem_Click_2(object sender, EventArgs e)
            {
                //NavigationService.Navigate(new Uri("/Gyroscope_Test.xaml", UriKind.Relative));
                sensor = new Accelerometer() { TimeBetweenUpdates = TimeSpan.FromSeconds(1) };
                sensor.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(sensor_CurrentValueChanged);
                if (sensor.State == SensorState.NotSupported)
                {
                    MessageBox.Show("本手机不支持加速计。");
                    return;
                }
                try
                {
                    sensor.Start();
                }
                catch (AccelerometerFailedException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
    
            void sensor_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
            {
                Dispatcher.BeginInvoke(delegate
                {
                    if (e.SensorReading.Acceleration.X > 0.4)
                    {
                        if (pivot.SelectedIndex == 4)
                        {
                            pivot.SelectedIndex = 0;
                        }
                        else
                        {
                            pivot.SelectedIndex = pivot.SelectedIndex + 1;
                        }
                    }
    
                    if (e.SensorReading.Acceleration.X < -0.4)
                    {
                        if (pivot.SelectedIndex == 0)
                        {
                            pivot.SelectedIndex = 4;
                        }
                        else
                        {
                            pivot.SelectedIndex = pivot.SelectedIndex - 1;
                        }
                    }
    
                    pivot.Title = string.Format("[{0:0.00},{1:0.00},{2:0.00}] at {3}", e.SensorReading.Acceleration.X, e.SensorReading.Acceleration.Y, e.SensorReading.Acceleration.Z, e.SensorReading.Timestamp.TimeOfDay.ToString());
    
                });
            }
  • 相关阅读:
    假期学习01
    构建之法读后感(二)
    构建之法读后感(一)
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
    每周日报
    每日日报
  • 原文地址:https://www.cnblogs.com/hebeiDGL/p/2471065.html
Copyright © 2020-2023  润新知