zoukankan      html  css  js  c++  java
  • 使用手机重量加速器

     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());
    
                });
            }
  • 相关阅读:
    [NOIP2011提高组]聪明的质监员
    NOIP 2010 关押罪犯
    题目:埃及分数
    用scanf输入long long 型的数
    poj 1014 Dividing
    Cactus
    SQLite数据库的增删改查代码
    UltraGrid常用方法属性代码
    维护数据表常用SQL语句
    C#备份收藏夹代码
  • 原文地址:https://www.cnblogs.com/hebeiDGL/p/2471065.html
Copyright © 2011-2022 走看看