private async void Connect(object sender, RoutedEventArgs args)
        {
            int selection = MetawearMacAddresses.SelectedIndex;

            Debug.Print(sensors.ElementAt(selection).Address);
            device = await BluetoothLEDevice.FromIdAsync(sensors.ElementAt(selection).Address);

            board = MbientLab.MetaWear.Win10.Application.GetMetaWearBoard(device);

            ConnectionStatus.Text = "Connecting...";

            await board.InitializeAsync();

            ConnectionStatus.Text = "Connected.";

            ILed led = board.GetModule <ILed>();

            led.EditPattern(MbientLab.MetaWear.Peripheral.Led.Color.Green, MbientLab.MetaWear.Peripheral.Led.Pattern.Blink);
            led.Play();

            ConnectButton.IsEnabled    = false;
            DisconnectButton.IsEnabled = true;

            IAccelerometerBmi160 accelerometer = board.GetModule <IAccelerometerBmi160>();

            accelerometer.Configure(odr: MbientLab.MetaWear.Sensor.AccelerometerBmi160.OutputDataRate._100Hz, range: MbientLab.MetaWear.Sensor.AccelerometerBosch.DataRange._4g);

            await accelerometer.PackedAcceleration.AddRouteAsync(source => source.Stream(async data => await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                accelerationData.Text = data.Value <Acceleration>().ToString();
            })));

            IGyroBmi160 gyro = board.GetModule <IGyroBmi160>();

            gyro.Configure(odr: MbientLab.MetaWear.Sensor.GyroBmi160.OutputDataRate._100Hz, range: MbientLab.MetaWear.Sensor.GyroBmi160.DataRange._250dps);

            await gyro.PackedAngularVelocity.AddRouteAsync(source => source.Stream(async data => await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                gyroData.Text = data.Value <AngularVelocity>().ToString();
            })));

            IMagnetometerBmm150 magnetometer = board.GetModule <IMagnetometerBmm150>();

            magnetometer.Configure(preset: MbientLab.MetaWear.Sensor.MagnetometerBmm150.Preset.HighAccuracy);

            await magnetometer.PackedMagneticField.AddRouteAsync(source => source.Stream(async data => await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                magnetometerData.Text = data.Value <MagneticField>().ToString();
            })));

            accelerometer.PackedAcceleration.Start();
            gyro.PackedAngularVelocity.Start();
            magnetometer.PackedMagneticField.Start();

            accelerometer.Start();
            gyro.Start();
            magnetometer.Start();
        }
        protected async void OnNavigatedTo2(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var samples = 0;
            var model   = (DataContext as MainViewModel).MyModel;

            metawear = MbientLab.MetaWear.Win10.Application.GetMetaWearBoard(e.Parameter as BluetoothLEDevice);
            //accelerometer = metawear.GetModule<IAccelerometer>();
            //gyro = metawear.GetModule<IGyroBmi160>();
            //gyro.Configure();

            //accelerometer.Configure(odr: 100f, range: 8f);
            m_SensorFusion = metawear.GetModule <ISensorFusionBosch>();
            gyro           = metawear.GetModule <IGyroBmi160>();
            gyro.Configure(OutputDataRate._100Hz);
            accelerometer = metawear.GetModule <IAccelerometer>();
            accelerometer.Configure(odr: 100f, range: 8f);

            m_SensorFusion.Configure();
            await m_SensorFusion.EulerAngles.AddRouteAsync(source =>
            {
                source.Stream(async data =>
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        var value = data.Value <EulerAngles>();
                        (model.Series[0] as LineSeries).Points.Add(new DataPoint(samples, value.Pitch));
                        (model.Series[1] as LineSeries).Points.Add(new DataPoint(samples, value.Roll));
                        (model.Series[2] as LineSeries).Points.Add(new DataPoint(samples, value.Yaw));
                        samples++;

                        model.InvalidatePlot(true);
                        if (samples > MainViewModel.MAX_DATA_SAMPLES)
                        {
                            model.Axes[1].Reset();
                            model.Axes[1].Maximum = samples;
                            model.Axes[1].Minimum = (samples - MainViewModel.MAX_DATA_SAMPLES);
                            model.Axes[1].Zoom(model.Axes[1].Minimum, model.Axes[1].Maximum);
                        }
                        GyroText.Text = value.ToString();
                    });
                });
            });

            m_SensorFusion.Start();
            m_SensorFusion.EulerAngles.Start();
        }
Beispiel #3
0
        public async override Task SetUp()
        {
            await base.SetUp();

            gyro = metawear.GetModule <IGyroBmi160>();
        }
Beispiel #4
0
        public override void SetUp()
        {
            base.SetUp();

            gyro = metawear.GetModule <IGyroBmi160>();
        }