Beispiel #1
0
        private void StartClicked(object sender, EventArgs e)
        {
            gyroData = new ObservableCollection <double>();

            motion.Start(MotionSensorType.Gyroscope, MotionSensorDelay.Default);
            if (motion.IsActive(MotionSensorType.Gyroscope))
            {
                motion.SensorValueChanged += (object s, SensorValueChangedEventArgs v) =>
                {
                    // 乱暴ですが、Gyroscopeの各絶対値が4を超えた回数が4回以上(2回シェイク)でシェイクと判定しています。
                    gyroData.Add(((MotionVector)v.Value).X);
                    gyroData.Add(((MotionVector)v.Value).Y);
                    gyroData.Add(((MotionVector)v.Value).Z);
                    var shake = gyroData.Where(gyroData => Math.Abs(gyroData) > 4).Count();
                    if (shake > 3)
                    {
                        motion.Stop(MotionSensorType.Gyroscope);
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            await DisplayAlert("Gyroscope", "Shaked!", "OK");
                        });
                    }

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        xLabel.Text = ((MotionVector)v.Value).X.ToString("0.0000");
                        yLabel.Text = ((MotionVector)v.Value).Y.ToString("0.0000");
                        zLabel.Text = ((MotionVector)v.Value).Z.ToString("0.0000");
                    });
                };
            }
        }
Beispiel #2
0
        public MainPageCS()
        {
            xLabel = new Label {
                Text = "x = "
            };
            yLabel = new Label {
                Text = "y = "
            };
            zLabel = new Label {
                Text = "z = "
            };

            startButton = new Button {
                Text = "Start"
            };
            startButton.Clicked += (_, __) =>
            {
                motion.Start(MotionSensorType.Accelerometer, MotionSensorDelay.Default);
                if (motion.IsActive(MotionSensorType.Accelerometer))
                {
                    motion.SensorValueChanged += (object sender, SensorValueChangedEventArgs e) =>
                    {
                        System.Diagnostics.Debug.WriteLine("X:{0}, Y:{1}, Z:{2}", ((MotionVector)e.Value).X, ((MotionVector)e.Value).Y, ((MotionVector)e.Value).Z);

                        Device.BeginInvokeOnMainThread(() =>
                        {
                            xLabel.Text = ((MotionVector)e.Value).X.ToString("0.0000");
                            yLabel.Text = ((MotionVector)e.Value).Y.ToString("0.0000");
                            zLabel.Text = ((MotionVector)e.Value).Z.ToString("0.0000");
                        });
                    };
                }
            };

            stopButton = new Button {
                Text = "Stop"
            };
            stopButton.Clicked += (_, __) =>
            {
                motion.Stop(MotionSensorType.Accelerometer);
            };

            Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 0);
            Content = new StackLayout
            {
                Children =
                {
                    xLabel,
                    yLabel,
                    zLabel,
                    startButton,
                    stopButton
                }
            };
        }
        public MainPageCS()
        {
            angleLabel = new Label
            {
                Text     = "Angle",
                FontSize = 40,
                HorizontalTextAlignment = TextAlignment.Center,
            };

            startButton = new Button {
                Text = "Start"
            };
            startButton.Clicked += (sender, e) =>
            {
                motion.Start(MotionSensorType.Compass, MotionSensorDelay.Default);
                if (motion.IsActive(MotionSensorType.Compass))
                {
                    motion.SensorValueChanged += (object s, SensorValueChangedEventArgs a) =>
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            angleLabel.Text = string.Format($"{a.Value.Value:N0}");
                        });
                    };
                }
            };

            stopButton = new Button {
                Text = "Stop"
            };
            stopButton.Clicked += (sender, e) =>
            {
                motion.Stop(MotionSensorType.Compass);
            };

            Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 0);
            Content = new StackLayout
            {
                Children =
                {
                    new Frame
                    {
                        Padding = 30,
                        Content = angleLabel,
                    },
                    startButton,
                    stopButton
                }
            };
        }
 private void StopClicked(object sender, EventArgs e)
 {
     motion.Stop(MotionSensorType.Magnetometer);
 }
Beispiel #5
0
 /// <summary>
 /// 加速度センサーの取得を停止
 /// </summary>
 private void StopAccelerometerCapture()
 {
     motion.Stop(MotionSensorType.Accelerometer);
 }
Beispiel #6
0
        public MainPageCS()
        {
            xLabel = new Label {
                Text = "x = "
            };
            yLabel = new Label {
                Text = "y = "
            };
            zLabel = new Label {
                Text = "z = "
            };

            startButton = new Button {
                Text = "Start"
            };
            startButton.Clicked += (_, __) =>
            {
                gyroData = new ObservableCollection <double>();

                motion.Start(MotionSensorType.Gyroscope, MotionSensorDelay.Default);
                if (motion.IsActive(MotionSensorType.Gyroscope))
                {
                    motion.SensorValueChanged += (object sender, SensorValueChangedEventArgs e) =>
                    {
                        // 乱暴ですが、Gyroscopeの各絶対値が4を超えた回数が4回以上(2回シェイク)でシェイクと判定しています。
                        gyroData.Add(((MotionVector)e.Value).X);
                        gyroData.Add(((MotionVector)e.Value).Y);
                        gyroData.Add(((MotionVector)e.Value).Z);
                        var shake = gyroData.Where(gyroData => Math.Abs(gyroData) > 4).Count();
                        if (shake > 3)
                        {
                            motion.Stop(MotionSensorType.Gyroscope);
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                await DisplayAlert("Gyroscope", "Shaked!", "OK");
                            });
                        }

                        Device.BeginInvokeOnMainThread(() =>
                        {
                            xLabel.Text = ((MotionVector)e.Value).X.ToString("0.0000");
                            yLabel.Text = ((MotionVector)e.Value).Y.ToString("0.0000");
                            zLabel.Text = ((MotionVector)e.Value).Z.ToString("0.0000");
                        });
                    };
                }
            };

            stopButton = new Button {
                Text = "Stop"
            };
            stopButton.Clicked += (_, __) =>
            {
                motion.Stop(MotionSensorType.Gyroscope);
            };

            Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 0);
            Content = new StackLayout
            {
                Children =
                {
                    xLabel,
                    yLabel,
                    zLabel,
                    startButton,
                    stopButton,
                }
            };
        }
 private void StopClicked(object sender, EventArgs e)
 {
     motion.Stop(MotionSensorType.Compass);
 }