private void OnControllerDiscovered(object sender, Robot robot)
 {
     if(robot.BluetoothName.Equals(txtController.Text))
     {
         RobotProvider provider = RobotProvider.GetSharedProvider();
         provider.ConnectRobot(robot);
         m_controller = (Sphero)robot;
     }
 }
示例#2
0
        public async void FindRobots()
        {
            Boolean flag;

            try
            {
                PeerFinder.AllowBluetooth = true;
                PeerFinder.AlternateIdentities["Bluetooth:PAIRED"] = "";
                var deviceInformationCollection = await PeerFinder.FindAllPeersAsync();

                if (!deviceInformationCollection.Any())
                {
                    EventHandler noRobotsEvent = NoRobotsEvent;
                    if (noRobotsEvent != null)
                    {
                        noRobotsEvent.Invoke(this, null);
                    }
                }
                foreach (var item in deviceInformationCollection)
                {
                    if (!item.DisplayName.Contains("Sphero"))
                    {
                        Debug.WriteLine("There needs to be a permission in the app manifest.");
                        Debug.WriteLine("Add UUID of Sphero to manifest: 00001101-0000-1000-8000-00805F9B34FB");
                    }
                    else
                    {
                        Sphero sphero = new Sphero(item);
                        EventHandler <Robot> discoveredRobotEvent = DiscoveredRobotEvent;
                        if (discoveredRobotEvent != null)
                        {
                            discoveredRobotEvent.Invoke(this, sphero);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                if ((uint)exception.HResult == 0x8007048F)
                {
                    MessageBox.Show("Bluetooth is currently switched off");
                }

                Debug.WriteLine(String.Concat("Rfcomm Serial Service failed: ", exception));
            }
        }
        public async void FindRobots()
        {
            Boolean flag;
            try
            {
                PeerFinder.AllowBluetooth = true;
                PeerFinder.AlternateIdentities["Bluetooth:PAIRED"] = ""; 
                var deviceInformationCollection = await PeerFinder.FindAllPeersAsync();

                if (!deviceInformationCollection.Any())
                {
                    EventHandler noRobotsEvent = NoRobotsEvent;
                    if (noRobotsEvent != null)
                    {
                        noRobotsEvent.Invoke(this, null);
                    }
                }
                foreach(var item in deviceInformationCollection)
                {
                    if (!item.DisplayName.Contains("Sphero"))
                    {
                        Debug.WriteLine("There needs to be a permission in the app manifest.");
                        Debug.WriteLine("Add UUID of Sphero to manifest: 00001101-0000-1000-8000-00805F9B34FB");
                    }
                    else
                    {
                        Sphero sphero = new Sphero(item);
                        EventHandler<Robot> discoveredRobotEvent = DiscoveredRobotEvent;
                        if (discoveredRobotEvent != null)
                        {
                            discoveredRobotEvent.Invoke(this, sphero);
                        }
                    }
                }
            }
            catch (Exception exception)
            {

                if ((uint)exception.HResult == 0x8007048F)
                {
                    MessageBox.Show("Bluetooth is currently switched off");
                }

                Debug.WriteLine(String.Concat("Rfcomm Serial Service failed: ", exception));
            }
        }
示例#4
0
        private void OnRobotDiscovered(object sender, Robot robot)
        {
            Debug.WriteLine(string.Format("Discovered \"{0}\"", robot.BluetoothName));

            if (_robot == null)
            {
                var provider = RobotProvider.GetSharedProvider();
                provider.ConnectRobot(robot);
                _robot = (Sphero)robot;
            }
        }
        //! @brief  when a robot is discovered, connect!
        private void OnRobotDiscovered(object sender, Robot robot) {
            Debug.WriteLine(string.Format("Discovered \"{0}\"", robot.BluetoothName));

            if (m_robot == null) {
                RobotProvider provider = RobotProvider.GetSharedProvider();
                provider.ConnectRobot(robot);
                ConnectionToggle.OnContent = "Connecting...";
                m_robot = (Sphero)robot;
                SpheroName.Text = string.Format(kConnectingToSphero, robot.BluetoothName);
            }
        }
示例#6
0
        private void CanvasAnimatedControl_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {


            if (_gameState == GameState.Connecting)
            {
                if (_robot.ConnectionState == ConnectionState.Failed/* ||
                    _robot.ConnectionState == ConnectionState.Disconnected*/)
                {
                    _gameState = GameState.ConnectionFailed;
                }
                return;
            }
            if (_gameState == GameState.ConnectionFailed)
            {
                _robot = null;
                SetupRobotConnection();
                _gameState = GameState.Connecting;
                return;
            }


            ProcessMovementType();

            if (_gameState == GameState.Connected)
            {
                _gameState = GameState.Ready;
            }

            if (_gameState == GameState.Ready || _gameState == GameState.GameOver)
            {
                if (_movType == SpheroMovementType.ShakeIt)
                {
                    _points = 0;
                    _numFails = 0;
                    _currentLevel = 0;
                    _currentBeatTime = 0;
                    _gameState = GameState.ThreeTwoOneGo;
                    _currentSequence = _gameSequence[_currentLevel]; // starting sequence
                                                                     //if (_posSpheroSeq == Vector2.Zero)
                                                                     //{
                    _posSpheroSeq = new Vector2((float)sender.Size.Width - 300, ((float)sender.Size.Height / 2f) + 20);
                    //}
                    _robot.SetRGBLED(255, 0, 0);
                }
            }

            ProcessLevel(args);
        }
 private void OnTargetDiscovered(object sender, Robot robot)
 {
     if (robot.BluetoothName.Equals(txtTarget.Text))
     {
         RobotProvider provider = RobotProvider.GetSharedProvider();
         provider.ConnectRobot(robot);
         m_target = (Sphero)robot;
     }
 }