Beispiel #1
0
        protected async override void OnNavigatedTo(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>();
            accelerometer.Configure(odr: 100f, range: 8f);

            await accelerometer.PackedAcceleration.AddRouteAsync(source => source.Stream(async data => {
                var value = data.Value <Acceleration>();
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                    (model.Series[0] as LineSeries).Points.Add(new DataPoint(samples, value.X));
                    (model.Series[1] as LineSeries).Points.Add(new DataPoint(samples, value.Y));
                    (model.Series[2] as LineSeries).Points.Add(new DataPoint(samples, value.Z));
                    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);
                    }
                });
            }));
        }
Beispiel #2
0
        public async Task HandleDataAsync()
        {
            Acceleration expected = null, actual = null;
            await accelerometer.Acceleration.AddRouteAsync(source => source.Stream(data => actual = data.Value <Acceleration>()));

            if (accelerometer is IAccelerometerMma8452q)
            {
                // (-1.450f, -2.555f, 0.792f)

                expected = new Acceleration(
                    BitConverter.ToSingle(new byte[] { 0x9a, 0x99, 0xb9, 0xbf }, 0),
                    BitConverter.ToSingle(new byte[] { 0x1f, 0x85, 0x23, 0xc0 }, 0),
                    BitConverter.ToSingle(new byte[] { 0x83, 0xc0, 0x4a, 0x3f }, 0));

                platform.sendMockResponse(new byte[] { 0x03, 0x04, 0x56, 0xfa, 0x05, 0xf6, 0x18, 0x03 });
            }
            else if (accelerometer is IAccelerometerBmi160)
            {
                // (-1.872f, -2.919f, -1.495f)

                expected = new Acceleration(
                    BitConverter.ToSingle(new byte[] { 0x00, 0xa8, 0xef, 0xbf }, 0),
                    BitConverter.ToSingle(new byte[] { 0x00, 0xd8, 0x3a, 0xc0 }, 0),
                    BitConverter.ToSingle(new byte[] { 0x00, 0x58, 0xbf, 0xbf }, 0));

                accelerometer.Configure(range: 4f);
                platform.sendMockResponse(new byte[] { 0x03, 0x04, 0x16, 0xc4, 0x94, 0xa2, 0x2a, 0xd0 });

                platform.fileSuffix = "bmi160_acc_route";
                await metawear.SerializeAsync();
            }
            else if (accelerometer is IAccelerometerBma255)
            {
                // (-4.7576f, 2.2893f, 2.9182f)

                expected = new Acceleration(
                    BitConverter.ToSingle(new byte[] { 0x00, 0x3e, 0x98, 0xc0 }, 0),
                    BitConverter.ToSingle(new byte[] { 0x00, 0x84, 0x12, 0x40 }, 0),
                    BitConverter.ToSingle(new byte[] { 0x00, 0xc4, 0x3a, 0x40 }, 0));

                accelerometer.Configure(range: 8f);
                platform.sendMockResponse(new byte[] { 0x03, 0x04, 0xe1, 0xb3, 0xa1, 0x24, 0xb1, 0x2e });
            }

            Assert.That(actual, Is.EqualTo(expected));
        }
        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();
        }