Exemplo n.º 1
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.º 2
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();
            }
        }