void XnaInputHandler() { while (true) { Thread.Sleep(10); if (gameOn) { tickCount++; if (tickCount > ticksBetweenSwitch) { tickCount = 0; indexOfIt = 1 - indexOfIt; // Hack. Alternates between 0 and 1. if (indexOfIt == 0) { roundCount++; } // If we're back to the first Sphero being it, then we've started a new round. if (roundCount >= maxRoundCount) { StopPlaying(null, null); } } } for (int i = 0; i < 4; i++) { index = i; switch (i) { case 0: controllerState = Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One); if (controllerState.IsConnected) { //spheroOneConnectionStatusLabel.Content = "Connected"; if (spheros[i].IsConnected()) { commander = spheros[i]; SendSpheroCommands(); } } break; case 1: controllerState = Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.Two); if (controllerState.IsConnected) { //spheroTwoConnectionStatusLabel.Content = "Connected"; if (spheros[i].IsConnected()) { commander = spheros[i]; SendSpheroCommands(); } } break; case 2: controllerState = Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.Three); if (controllerState.IsConnected) { //spheroThreeConnectionStatusLabel.Content = "Connected"; if (spheros[i].IsConnected()) { commander = spheros[i]; SendSpheroCommands(); } } break; case 3: controllerState = Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.Four); if (controllerState.IsConnected) { //spheroFourConnectionStatusLabel.Content = "Connected"; if (spheros[i].IsConnected()) { commander = spheros[i]; SendSpheroCommands(); } } break; default: controllerState = Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One); if (controllerState.IsConnected) { Debug.WriteLine("Error case: While polling all controllers"); } break; } } } }
private void ConnectSpheroToPort(object sender, RoutedEventArgs e) { Debug.WriteLine("SpheroName: " + SpheroNames.SelectedIndex + " PortName: " + PortNames.SelectedValue); int index = SpheroNames.SelectedIndex; string portName = (string)PortNames.SelectedValue; var listener = new LogListener(this); spheros[index].spheroTrace.Listeners.Add(listener); spheros[index].Initialize(portName); spheros[index].spheroComm.subscribeToAllAsyncPackets(subscriberKey); commander = spheros[index]; SpheroMessageLoop = new Thread(SpheroMessageLoopHandler); SpheroMessageLoop.Start(); spheros[index].GetConfigurationBlock(); spheros[index].SetCollisionDetection(); SetBaseColor(index); }