• 使用手机重量加速器


     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());
    
                });
            }
  • 相关阅读:
    Linux内存分析
    mysql 分表
    安装YCM
    c/c++ 之静态库
    ubuntu20 宽带连接
    数据对齐
    计算机中浮点数的表示
    整数的表示
    信息的储存
    SparseTable ST表
  • 原文地址:https://www.cnblogs.com/hebeiDGL/p/2471065.html
Copyright © 2020-2023  润新知