Exemplo n.º 1
0
 private void back_Click(object sender, RoutedEventArgs e)
 {
     if (!metawear.InMetaBootMode)
     {
         metawear.TearDown();
         metawear.GetModule <IDebug>().DisconnectAsync();
     }
     Frame.GoBack();
 }
Exemplo n.º 2
0
        static async Task SetupLogger(IMetaWearBoard metawear)
        {
            var acc = metawear.GetModule <IAccelerometer>();
            await acc.Acceleration.AddRouteAsync(source => source.Log(_ => {
                Console.WriteLine($"{_.FormattedTimestamp} -> {_.Value<Acceleration>()}");
            }));

            // Tell firmware to start logging
            metawear.GetModule <ILogging>().Start();
            acc.Acceleration.Start();
            acc.Start();
        }
Exemplo n.º 3
0
        internal static Task Stop(IMetaWearBoard metawear)
        {
            var acc = metawear.GetModule <IAccelerometer>();

            // Put accelerometer back into standby mode
            acc.Stop();
            // Stop accelerationi data
            acc.Acceleration.Stop();

            // Have remote device close the connection
            return(metawear.GetModule <IDebug>().DisconnectAsync());
        }
Exemplo n.º 4
0
        static async Task DownloadData(IMetaWearBoard metawear)
        {
            var logging = metawear.GetModule <ILogging>();
            var acc     = metawear.GetModule <IAccelerometer>();

            acc.Stop();
            acc.Acceleration.Stop();
            logging.Stop();

            metawear.GetModule <ISettings>().EditBleConnParams(maxConnInterval: 7.5f);
            await Task.Delay(1500);

            await logging.DownloadAsync();
        }
        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();
        }
Exemplo n.º 6
0
        public void StartMotorPattern(ulong pMacAdress, ushort pDurationMs, float pIntensity, ushort pSleepMs, int pPatternIterations)
        {
            // Cancel the Previous Task if Any.
            if (_motorPatternCancellationToken != null)
            {
                _motorPatternCancellationToken.Cancel();
            }

            // Run the new Task.
            _motorPatternCancellationToken = new CancellationTokenSource();
            Task.Run(() =>
            {
                IMetaWearBoard board = _mwBoardsManager.GetBoard(pMacAdress);
                if (board != null)
                {
                    IHaptic haptic = board.GetModule <IHaptic>();
                    if (haptic != null)
                    {
                        // Set 120ms as the minimal duration between Bluetooth' stream of successives commands.
                        // Below this value, pattern can be broken by pushing too frequently on the BLE connection.
                        // Better solution should be to implement the vibration pattern directly on the MetaWearBoard.
                        int sleep = Math.Max((int)pSleepMs, 120) + pDurationMs;
                        while (pPatternIterations-- > 0)
                        {
                            haptic.StartMotor(pDurationMs, pIntensity);
                            Thread.Sleep(sleep);
                        }
                    }
                }
            }, _motorPatternCancellationToken.Token);
        }
Exemplo n.º 7
0
        private async Task Disconnect()
        {
            if (m_Metaware != null)
            {
                var led = m_Metaware.GetModule <ILed>();
                led.Stop(true);
                await m_Metaware.DisconnectAsync();

                m_Metaware.TearDown();
                m_Metaware  = null;
                m_Connected = false;
            }

            //Scanner.Start();
            btnConnect.Content = "Connect";
        }
Exemplo n.º 8
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);
                    }
                });
            }));
        }
Exemplo n.º 9
0
        internal static void Start(IMetaWearBoard metawear)
        {
            var acc = metawear.GetModule <IAccelerometer>();

            // Start the acceleration data
            acc.Acceleration.Start();
            // Put accelerometer in active mode
            acc.Start();
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var samples  = 0;
            var samples2 = 0;
            var model    = (DataContext as MainViewModel).MyModel;
            var model2   = (DataContext as MainViewModel).MyLocal;


            //Sensor Configuration
            metawear     = MbientLab.MetaWear.Win10.Application.GetMetaWearBoard(e.Parameter as BluetoothLEDevice);
            sensorfusion = metawear.GetModule <ISensorFusionBosch>();
            sensorfusion.Configure(mode: Mode.Ndof, ar: AccRange._2g, gr: GyroRange._500dps);
            //-----------------------

            //await sensorfusion.Quaternion.AddRouteAsync(source => source.Stream(async data => {
            //    var value = data.Value<Quaternion>();
            //    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => {

            //        (model.Series[0] as LineSeries).Points.Add(new DataPoint(samples, value.W));
            //        (model.Series[1] 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);
            //        }
            //    });
            //}));

            //===== This is for the Linear Acceleration =====

            await sensorfusion.LinearAcceleration.AddRouteAsync(source => source.Stream(async data =>
            {
                var value2 = data.Value <CorrectedAcceleration>();
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                {
                    (model2.Series[0] as LineSeries).Points.Add(new DataPoint(samples2, value2.X));
                    (model2.Series[1] as LineSeries).Points.Add(new DataPoint(samples2, value2.Y));
                    (model2.Series[2] as LineSeries).Points.Add(new DataPoint(samples2, value2.Z));
                    samples2++;

                    model2.InvalidatePlot(true);
                    if (samples > MainViewModel.MAX_DATA_SAMPLES)
                    {
                        model2.Axes[1].Reset();
                        model2.Axes[1].Maximum = samples2;
                        model2.Axes[1].Minimum = (samples2 - MainViewModel.MAX_DATA_SAMPLES);
                        model2.Axes[1].Zoom(model2.Axes[1].Minimum, model2.Axes[1].Maximum);
                    }
                });
            }));
        }
Exemplo n.º 11
0
        internal static async Task Setup(IMetaWearBoard metawear)
        {
            var mwSwitch = metawear.GetModule <ISwitch>();
            await mwSwitch.State.AddRouteAsync(source => {
                var led   = metawear.GetModule <ILed>();
                var count = source.Filter(Comparison.Eq, 1).Count().Name("press-count");

                var colors = Enum.GetValues(typeof(Color)).Cast <Color>();
                count.Filter(Comparison.Eq, colors.Count() + 1).React(token => {
                    led.Stop(true);
                    metawear.GetModule <IDataProcessor>().Edit <ICounterEditor>("press-count").Reset();
                });
                foreach (var c in colors)
                {
                    count.Filter(Comparison.Eq, ((int)c) + 1).React(token => {
                        led.Stop(true);
                        led.EditPattern(c, Pattern.Solid);
                        led.Play();
                    });
                }
            });
        }
Exemplo n.º 12
0
        static async Task <IScheduledTask> Setup(IMetaWearBoard metawear)
        {
            var temperature = metawear.GetModule <ITemperature>();
            var thermistor  = temperature.FindSensors(SensorType.PresetThermistor)[0];

            await thermistor.AddRouteAsync(source => source.Stream(_ => {
                Console.WriteLine($"{_.FormattedTimestamp} -> {_.Value<float>()}");
            }));

            // Temperature is classified as a forced data producer
            // Schedule periodic `Read` calls in the firmware, do it after route is setup
            return(await metawear.ScheduleAsync(1000, false, () => thermistor.Read()));
        }
Exemplo n.º 13
0
        public void StartBuzzer(ulong pMacAdress, ushort pDurationMs)
        {
            IMetaWearBoard board = _mwBoardsManager.GetBoard(pMacAdress);

            if (board != null)
            {
                IHaptic haptic = board.GetModule <IHaptic>();
                if (haptic != null)
                {
                    haptic.StartBuzzer(pDurationMs);
                }
            }
        }
Exemplo n.º 14
0
        internal static async Task Setup(IMetaWearBoard metawear, Dictionary <IMetaWearBoard, uint> samples)
        {
            var acc = metawear.GetModule <IAccelerometer>();

            // Set the data rate to 100Hz and data range to +/-16g, or closest valid values
            acc.Configure(odr: 100f, range: 16f);
            // Use data route framework to tell the MetaMotion to stream accelerometer data to the host device
            // https://mbientlab.com/csdocs/latest/data_route.html#stream
            await acc.Acceleration.AddRouteAsync(source => source.Stream(data => {
                Console.WriteLine($"{metawear.MacAddress} -> {data.Value<Acceleration>()}");
                samples[metawear]++;
            }));
        }
Exemplo n.º 15
0
        private void start_Click(object sender, RoutedEventArgs e)
        {
            metawear.GetModule <ILogging>().Start();

            var accelerometer = metawear.GetModule <IAccelerometer>();

            accelerometer.Acceleration.Start();
            accelerometer.Start();
        }
Exemplo n.º 16
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            metawear = MbientLab.MetaWear.Win10.Application.GetMetaWearBoard(e.Parameter as BluetoothLEDevice);

            var accelerometer = metawear.GetModule <IAccelerometer>();

            accelerometer.Configure(odr: 50f);
            await accelerometer.Acceleration.AddRouteAsync(source =>
                                                           source.Map(Function1.Rss).LowPass(4).Find(Threshold.Binary, 0.5f)
                                                           .Multicast()
                                                           .To().Filter(Comparison.Eq, -1).Log(data => System.Diagnostics.Debug.WriteLine("In FreeFall"))
                                                           .To().Filter(Comparison.Eq, 1).Log(data => System.Diagnostics.Debug.WriteLine("Not in FreeFall"))
                                                           );
        }
Exemplo n.º 17
0
        private async void _CloseBoard(IMetaWearBoard pBoard, BluetoothLEDevice pBLEDevice, bool pTearDown)
        {
            pBLEDevice.ConnectionStatusChanged -= _OnConnectionStatusChanged;

            if (!pBoard.InMetaBootMode)
            {
                if (pTearDown)
                {
                    pBoard.TearDown();
                }
                await pBoard.GetModule <IDebug>().DisconnectAsync();
            }

            if (pTearDown)
            {
                MbientLab.MetaWear.Win10.Application.RemoveMetaWearBoard(pBLEDevice, true);
            }
        }
Exemplo n.º 18
0
        static async Task Main(string[] args)
        {
            IMetaWearBoard board   = null;
            bool           succeed = false;
            int            retries = 5;
            //while (!succeed && retries > 0)
            {
                //try
                {
                    board = MbientLab.MetaWear.NetStandard.Application.GetMetaWearBoard(args[0]);
                    //var board = BLEMetawear.Application.GetMetaWearBoard(args[0]);
                    board.TimeForResponse         = 100000;
                    board.OnUnexpectedDisconnect += OnDisconneted;
                    await board.InitializeAsync();

                    succeed = true;
                }
                //catch
                {
                    retries--;
                }
            }

            ILed led = null;
            ISensorFusionBosch sensor = null;

            if (board.IsConnected)
            {
                led = board.GetModule <ILed>();
                led.EditPattern(MbientLab.MetaWear.Peripheral.Led.Color.Green, MbientLab.MetaWear.Peripheral.Led.Pattern.Solid);
                led.Play();

                sensor = board.GetModule <ISensorFusionBosch>();
                sensor.Configure();

                var rout = await sensor.EulerAngles.AddRouteAsync(source =>
                {
                    try
                    {
                        source.Stream(data =>
                        {
                            var value       = data.Value <EulerAngles>();
                            var AngularRead = (int)value.Roll;
                            var OrbitalRead = (int)value.Pitch;
                            //Console.Clear();
                            Console.Write($"\rroll: {value.Roll} pitch:{value.Pitch} Yaw:{value.Yaw}      ");



                            //Rotate(-value.Pitch, 0 , -value.Yaw);
                        });
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                        //LogException(LoggerCategory, ex, "Could not initialize IMU stream callback");
                        throw;
                    }
                });

                sensor.EulerAngles.Start();
                sensor.Start();
            }
            ConsoleKeyInfo key = new ConsoleKeyInfo();

            while (key.Key != ConsoleKey.Q)
            {
                key = Console.ReadKey();
            }
            if (board.IsConnected)
            {
                if (led != null)
                {
                    led.Stop(true);
                }
                if (sensor != null)
                {
                    sensor.EulerAngles.Stop();
                    sensor.Stop();
                }

                await board.DisconnectAsync();

                //board.TearDown();
            }
        }
        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>();
            //gyro = metawear.GetModule<IGyroBmi160>();
            //gyro.Configure();

            //accelerometer.Configure(odr: 100f, range: 8f);
            m_SensorFusion = metawear.GetModule <ISensorFusionBosch>();
            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);
                        }
                    });
                });
            });

            //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);
            //        }
            //    });
            //}));

            //await gyro.AngularVelocity.AddRouteAsync(source =>
            //        {
            //            source.Stream(async data=>
            //            {
            //                var dt = data.Value<AngularVelocity>();
            //                 await Dispatcher.RunAsync(CoreDispatcherPriority.High, async () =>
            //                 {
            //                     GyroText.Text = dt.ToString();//=$" X = {dt.X}";
            //                 });
            //            }
            //            );
            //        });
            //await gyro.PullConfigAsync();
            //gyro.Start();
            //gyro.AngularVelocity.Start();
            m_SensorFusion.Start();
            m_SensorFusion.EulerAngles.Start();
        }