예제 #1
0
        private async void DiscoverSpheros()
        {
            try
            {
                // Discover paired Spheros
                IEnumerable <SpheroInformation> spheroInformations = await SpheroConnectionProvider.DiscoverSpheros();

                if (spheroInformations != null && spheroInformations.Any())
                {
                    // Populate list with Discovered Spheros
                    SpherosDiscovered.ItemsSource = spheroInformations;
                }
                else
                {
                    // No sphero Paired
                    MessageBox.Show("No sphero Paired");
                }
            }

            catch (BluetoothDeactivatedException)
            {
                // Bluetooth deactivated
                MessageBox.Show("Bluetooth deactivated");
            }
        }
예제 #2
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");
        }
예제 #3
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);
            }
        }
예제 #4
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);
        }
예제 #6
0
        private async void DiscoverSpheros()
        {
            try
            {
                // Discover paired Spheros
                List <SpheroInformation> spheroInformations = new List <SpheroInformation>(await SpheroConnectionProvider.DiscoverSpheros());

                if (spheroInformations != null && spheroInformations.Count > 0)
                {
                    // Populate list with Discovered Spheros
                    SpherosDiscovered.ItemsSource = spheroInformations;
                }
                else
                {
                    // No sphero Paired
                    MessageDialog dialogNSP = new MessageDialog("No sphero Paired");
                    await dialogNSP.ShowAsync();
                }
            }
            catch (NoSpheroFoundException)
            {
                MessageDialog dialogNSF = new MessageDialog("No sphero Found");
                dialogNSF.ShowAsync();
            }
            catch (BluetoothDeactivatedException)
            {
                // Bluetooth deactivated
                MessageDialog dialogBD = new MessageDialog("Bluetooth deactivated");
                dialogBD.ShowAsync();
            }
        }