示例#1
0
        public async Task Start()
        {
            var spheros = await SpheroConnectionProvider.DiscoverSpheros();

            var sphero = spheros.FirstOrDefault();

            if (sphero != null)
            {
                var connection = await SpheroConnectionProvider.CreateConnection(sphero);

                if (connection != null)
                {
                    connection.OnDisconnection += () => Tracer.Trace("Sphero disconnected");
                    _device = new SpheroDevice(connection);
                    Tracer.Trace("Sphero connected");

                    _device.ReinitMacroExecutive(response =>
                    {
                        if (response == MessageResponseCode.ORBOTIX_RSP_CODE_OK)
                        {
                            var flipMacro = new Macro(MacroType.Permanent, FLIP_MACRO);
                            flipMacro.Commands.Add(new SendRawMotorMacroCommand
                            {
                                LeftMode   = MotorMode.Forward,
                                LeftPower  = 255,
                                RightMode  = MotorMode.Forward,
                                RightPower = 255,
                                PCD        = 255
                            });
                            flipMacro.Commands.Add(new DelayMacroCommand {
                                Time = 150
                            });
                            flipMacro.Commands.Add(new SendRawMotorMacroCommand
                            {
                                LeftMode   = MotorMode.Off,
                                LeftPower  = 0,
                                RightMode  = MotorMode.Off,
                                RightPower = 0,
                                PCD        = 255
                            });
                            flipMacro.Commands.Add(new SetStabilizationMacroCommand
                            {
                                Flag = StabilizationStatus.OnWithoutReset,
                                PCD  = 255
                            });
                            _device.SaveMacro(flipMacro, null);

                            Tracer.Trace("Flip macro stored");
                        }
                    });


                    return;
                }
            }

            Tracer.Error("Sphero not found");
        }
示例#2
0
        private async void btnConnection_Click(object sender, RoutedEventArgs e)
        {
            if (SpherosDiscovered.SelectedItem != null)
            {
                SpheroConnection connection = await SpheroConnectionProvider.CreateConnection((SpheroInformation)SpherosDiscovered.SelectedItem);

                Frame.Navigate(typeof(ConnectedPage), connection);
            }
        }
示例#3
0
        private async void btnConnection_Click(object sender, RoutedEventArgs e)
        {
            if (SpherosDiscovered.SelectedItem != null)
            {
                SpheroInformation information = (SpheroInformation)SpherosDiscovered.SelectedItem;
                SpheroConnection  connection  = await SpheroConnectionProvider.CreateConnection(information);

                if (connection == null)
                {
                    MessageBox.Show("Connection failed");
                }
                else
                {
                    App.CurrentConnection = connection;
                    NavigationService.Navigate(new Uri("/MacroPage.xaml", UriKind.RelativeOrAbsolute));
                }
            }
        }
        public static async Task <JediSphero> GetSpheroAsync()
        {
            IEnumerable <SpheroInformation> spheros = await SpheroConnectionProvider.DiscoverSpheros();

            SpheroInformation spheroInfo = spheros.FirstOrDefault();

            if (spheroInfo == null)
            {
                return(null);
            }

            SpheroConnection connection = await SpheroConnectionProvider.CreateConnection(spheroInfo);

            if (connection == null)
            {
                return(null);
            }
            var spheroDevice = new JediSphero(connection);

            return(spheroDevice);
        }