コード例 #1
0
        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();
        }
コード例 #2
0
        public async Task CreateAndRemoveStreamAsync()
        {
            byte[][] expected = new byte[][] {
                new byte[] { 0x15, 0x05, 0x01 },
                new byte[] { 0x15, 0x02, 0x01, 0x00 },
                new byte[] { 0x15, 0x01, 0x01 },
                new byte[] { 0x15, 0x01, 0x00 },
                new byte[] { 0x15, 0x02, 0x00, 0x01 },
                new byte[] { 0x15, 0x05, 0x00 }
            };

            var route = await magnetometer.MagneticField.AddRouteAsync(source => source.Stream(null));

            magnetometer.MagneticField.Start();
            magnetometer.Start();

            magnetometer.Stop();
            magnetometer.MagneticField.Stop();
            route.Remove();

            Assert.That(platform.GetCommands(), Is.EqualTo(expected));
        }