private void spheroJoystick_CalibrationReleased(object sender, Sphero.Controls.JoystickCalibrationEventArgs e) { if (_spheroDevice != null) { _spheroDevice.SetHeading(0); } }
public static void ChangeColor(Sphero sphero, String parameter) { if (String.IsNullOrEmpty(parameter)) { Console.WriteLine("Invalid parameter value - {0}", parameter); return; } if (isHelpParameter(parameter)) { Console.WriteLine("Please specify color value, like Red, Green, Blue, etc."); return; } if (sphero == null) { Console.WriteLine("Sphero not connected!"); return; } Color c = Color.FromName(parameter); byte r, g, b; r = c.R; g = c.G; b = c.B; sphero.SetRGBLEDOutput(r, g, b); }
private void spheroJoystick_Moving(object sender, Sphero.Controls.JoystickMoveEventArgs e) { if (_spheroDevice != null) { _spheroDevice.Roll(e.Angle, e.Speed); } }
private SpheroControl(Sphero sphero) { this.sphero = sphero; this.r = this.g = this.b = 0; this.backlightBrightness = 0.0f; this.rotation = 0; }
/* * Callback to receive connection notifications */ private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs) { SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message; if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTED) { // Connect to the robot and move to the next scene designated by the developer if (!m_MultipleSpheros) { m_Title = "CONNECTION SUCCESS"; SpheroDeviceMessenger.SharedInstance.NotificationReceived -= ReceiveNotificationMessage; { if (m_threadSafeLoadLevel != null) { m_threadSafeLoadLevel.LoadLevel(m_NextLevel); } } } } else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTION_FAILED) { Sphero notifiedSphero = m_SpheroProvider.GetSphero(message.RobotID); // Connection only has failed if we are trying to connect to that robot the notification belongs to if (m_ConnectingRobotName.Equals(notifiedSphero.DeviceInfo.Name)) { m_Title = "CONNECTION FAILED"; } } }
private void spheroJoystick_Calibrating(object sender, Sphero.Controls.JoystickCalibrationEventArgs e) { if (_spheroDevice != null) { _spheroDevice.Roll(e.Angle, 0); } }
private void spheroJoystick_Released(object sender, Sphero.Controls.JoystickMoveEventArgs e) { if (_spheroDevice != null) { _spheroDevice.Roll(e.Angle, 0); } }
override public Sphero[] GetConnectedSpheros() { if( m_PairedSpheros[0].ConnectionState == Sphero.Connection_State.Connected ) { Sphero[] connectedSpheros = new Sphero[1]; connectedSpheros[0] = m_PairedSpheros[0]; return connectedSpheros; } return new Sphero[0]; }
void DoWindow(int windowID) { Vector2 listSize = new Vector2(windowRect.width - 2 * listMargin.x, windowRect.height - 2 * listMargin.y); Rect rScrollFrame = new Rect(listMargin.x, listMargin.y, listSize.x, listSize.y); Rect rList = new Rect(0, 0, m_SpheroLabelWidth, m_RobotNames.Length * m_SpheroLabelHeight); scrollPosition = GUI.BeginScrollView(rScrollFrame, scrollPosition, rList, false, false); // Show a list of Spheros that you can connect to if (m_MultipleSpheros) { // Create rows of spinners for (int i = 0; i < m_RobotNames.Length; i++) { m_SpinnerPosition.x = (m_SpinnerSize.x / 2); m_SpinnerPosition.y = (i * m_SpheroLabelHeight) + (m_SpinnerSize.y / 2); // Rotate the object m_SpinnerRect = new Rect(m_SpinnerPosition.x - m_SpinnerSize.x * 0.5f, m_SpinnerPosition.y - m_SpinnerSize.y * 0.5f, m_SpinnerSize.x, m_SpinnerSize.y); m_SpinnerPivotPos = new Vector2(m_SpinnerRect.xMin + m_SpinnerRect.width * 0.5f, m_SpinnerRect.yMin + m_SpinnerRect.height * 0.5f); Sphero sphero = m_SpheroProvider.PairedSpheros[i]; // Draw the spinner rotating if it is connecting if (sphero.ConnectionState == Sphero.Connection_State.Connecting) { Matrix4x4 matrixBackup = GUI.matrix; GUIUtility.RotateAroundPivot(m_SpinnerAngle, m_SpinnerPivotPos); GUI.DrawTexture(m_SpinnerRect, m_Spinner); GUI.matrix = matrixBackup; m_SpinnerAngle += 3; } else if (sphero.ConnectionState == Sphero.Connection_State.Connected) { GUI.DrawTexture(m_SpinnerRect, m_CheckMark); } else if (sphero.ConnectionState == Sphero.Connection_State.Failed) { GUI.DrawTexture(m_SpinnerRect, m_RedX); } // Otherwise draw it normally else { GUI.DrawTexture(m_SpinnerRect, m_Spinner); } // Draw the Sphero Label GUI.Label(new Rect(m_SpinnerSize.x, i * m_SpheroLabelHeight, m_SpheroLabelWidth, m_SpheroLabelHeight), m_RobotNames[i]); } } // Show a grid of potential Spheros to connect to (only can connect to one) else { m_SpheroLabelSelected = GUI.SelectionGrid(new Rect(0, 0, m_SpheroLabelWidth, m_SpheroLabelHeight * m_RobotNames.Length), m_SpheroLabelSelected, m_RobotNames, 1, "toggle"); } GUI.EndScrollView(); }
/* * Get the Robot Provider for Android */ public SpheroProviderIOS() : base() { m_PairedSpheros = new Sphero[1]; m_PairedSpheros[0] = new SpheroIOS(); // DO NOT CHANGE THIS UNTIL MULTIPLE ROBOTS ARE USED ON iOS (if ever) m_PairedSpheros[0].DeviceInfo.UniqueId = "Robot"; m_PairedSpheros[0].DeviceInfo.Name = "Robot"; // Sign up for notifications on Sphero connections SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage; }
/* * Get the Robot Provider for Android */ public SpheroProviderIOS() : base() { m_PairedSpheros = new Sphero[1]; m_PairedSpheros[0] = new SpheroIOS(); // DO NOT CHANGE THIS UNTIL MULTIPLE ROBOTS ARE USED ON iOS (if ever) m_PairedSpheros[0].DeviceInfo.UniqueId = "Robot"; m_PairedSpheros[0].DeviceInfo.Name = "Robot"; // Sign up for notifications on Sphero connections SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage; }
override public Sphero[] GetConnectedSpheros() { if (m_PairedSpheros[0].ConnectionState == Sphero.Connection_State.Connected) { Sphero[] connectedSpheros = new Sphero[1]; connectedSpheros[0] = m_PairedSpheros[0]; return(connectedSpheros); } return(new Sphero[0]); }
//Робот найден! private void OnRobotDiscovered(object sender, Robot robot) { if (m_robot == null) { RobotProvider provider = RobotProvider.GetSharedProvider(); provider.ConnectRobot(robot); ConnectionToggle.OnContent = "Connecting..."; m_robot = (Sphero)robot; SpheroName.Text = string.Format(c_connectingToSphero, robot.BluetoothName); } }
/* * Callback to receive connection notifications */ private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs) { SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message; Sphero notifiedSphero = SpheroProvider.GetSharedProvider().GetSphero(message.RobotID); if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED) { notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected; Application.LoadLevel("NoSpheroConnectedScene"); } }
//! @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); m_robot = (Sphero)robot; } }
private void AttemptToConnect() { connector = new SpheroConnector(); connector.Scan(); foreach (var device in connector.DeviceNames) { if (device.ToLower().Contains("sphero")) { Console.WriteLine($"Attempting to connect to {device}"); sphero = connector.Connect(device); return; } } }
/* * Callback to receive connection notifications */ private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs) { // Event handler that listens for disconnects. An example of when one would be received is when Sphero // goes to sleep. SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message; Sphero notifiedSphero = SpheroProvider.GetSharedProvider().GetSphero(message.RobotID); if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED) { notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected; streaming = false; Application.LoadLevel("NoSpheroConnectedScene"); } }
/* Next block should be moved later */ public static void GoForward(Sphero sphero, byte speed, int duration) { var programLines = new List <string>(); programLines.Add("10 goroll 0, " + speed + ", 2\r"); programLines.Add("20 delay " + duration + "\r"); programLines.Add("30 goroll 0, 0, 0\r"); var area = StorageArea.Temporary; sphero.EraseOrbBasicStorage(area); sphero.SendOrbBasicProgram(area, programLines); sphero.ExecuteOrbBasicProgram(area, 10); }
void _spheroDevice_SensorDataNotification(Sphero.Locator.SensorData data) { // If IMU data are present if (data.FilteredIMU != null) { // Update Sliders with data on UI Thread Dispatcher.BeginInvoke(() => { sldPitch.Value = data.FilteredIMU.Pitch; sldRoll.Value = data.FilteredIMU.Roll; sldYaw.Value = data.FilteredIMU.Yaw; }); } }
/* * Get the Robot Provider for Android */ public SpheroProviderAndroid() : base() { // The SDK uses alot of handlers that need a valid Looper in the thread, so set that up here using (AndroidJavaClass jc = new AndroidJavaClass("android.os.Looper")) { jc.CallStatic("prepare"); } using (AndroidJavaClass jc = new AndroidJavaClass("orbotix.robot.base.RobotProvider")) { m_RobotProvider = jc.CallStatic<AndroidJavaObject>("getDefaultProvider"); } // Sign up for notifications on Sphero connections SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage; m_PairedSpheros = new Sphero[0]; }
//! @brief when a robot is connected, get ready to drive! private void OnRobotConnected(object sender, Robot robot) { SpheroName = string.Format(kSpheroConnected, robot.BluetoothName); Debug.WriteLine(SpheroName); m_robot = (Sphero)robot; ConnectionToggle.IsOn = true; ConnectionToggle.OnContent = "Connected"; SpheroConnected = true; m_robot.SetRGBLED(255, 255, 255); InitializeSensorReading.IsEnabled = true; m_robot.SensorControl.Hz = 15; Debug.WriteLine("SensorControl Hz Set"); //m_robot.CollisionControl.StartDetectionForWallCollisions(); //m_robot.CollisionControl.CollisionDetectedEvent += OnCollisionDetected; }
/* * Get the Robot Provider for Android */ public SpheroProviderAndroid() : base() { // The SDK uses alot of handlers that need a valid Looper in the thread, so set that up here using (AndroidJavaClass jc = new AndroidJavaClass("android.os.Looper")) { jc.CallStatic("prepare"); } using (AndroidJavaClass jc = new AndroidJavaClass("orbotix.robot.base.RobotProvider")) { m_RobotProvider = jc.CallStatic <AndroidJavaObject>("getDefaultProvider"); } // Sign up for notifications on Sphero connections SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage; m_PairedSpheros = new Sphero[0]; }
public void ShutdownRobotConnection() { if (m_robot != null) { if (SpheroConnected) { try { if (!AccelerometerFiltered.close()) { SpheroName = "ERROR: Consult debug."; Debug.WriteLine("Unable to close stream,/n" + "please close application and manually delete file://" + AccelerometerFiltered.filePath); } if (!GyrometerFiltered.close()) { SpheroName = "ERROR: Consult debug."; Debug.WriteLine("Unable to close stream,/n" + "please close application and manually delete file://" + GyrometerFiltered.filePath); } m_robot.SensorControl.StopAll(); m_robot.SensorControl.AccelerometerUpdatedEvent -= OnAccelerometerUpdated; m_robot.SensorControl.GyrometerUpdatedEvent -= OnGyrometerUpdated; m_robot.Sleep(); m_robot.Disconnect(); Debug.WriteLine("Sphero Disconnected"); } catch (Exception) { throw; } } m_robot = null; } SpheroConnected = false; InitializeSensorReading.IsEnabled = false; SpheroName = kNoSpheroConnected; RobotProvider provider = RobotProvider.GetSharedProvider(); provider.DiscoveredRobotEvent -= OnRobotDiscovered; provider.NoRobotsEvent -= OnNoRobotsEvent; provider.ConnectedRobotEvent -= OnRobotConnected; }
/* * Callback to receive connection notifications */ private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs) { SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message; Sphero notifiedSphero = GetSphero(message.RobotID); if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTED) { notifiedSphero.ConnectionState = Sphero.Connection_State.Connected; } else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED) { notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected; } else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTION_FAILED) { notifiedSphero.ConnectionState = Sphero.Connection_State.Failed; } }
override public void FindRobots() { // Only run this stuff if the adapter is enabled if( IsAdapterEnabled() ) { m_RobotProvider.Call("findRobots"); AndroidJavaObject pairedRobots = m_RobotProvider.Call<AndroidJavaObject>("getRobots"); int pairedRobotCount = pairedRobots.Call<int>("size"); // Initialize Sphero array m_PairedSpheros = new Sphero[pairedRobotCount]; // Create Sphero objects for the Paired Spheros for( int i = 0; i < pairedRobotCount; i++ ) { // Set up the Sphero objects AndroidJavaObject robot = pairedRobots.Call<AndroidJavaObject>("get",i); string bt_name = robot.Call<string>("getName"); string bt_address = robot.Call<string>("getUniqueId"); m_PairedSpheros[i] = new SpheroAndroid(robot, bt_name, bt_address); } } }
/* * Callback to receive connection notifications */ private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs) { SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message; Sphero notifiedSphero = m_PairedSpheros[0]; if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTED) { notifiedSphero.ConnectionState = Sphero.Connection_State.Connected; // Consider setting bluetooth device info here } else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED) { notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected; } else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTION_FAILED) { notifiedSphero.ConnectionState = Sphero.Connection_State.Failed; } }
override public void FindRobots() { // Only run this stuff if the adapter is enabled if (IsAdapterEnabled()) { m_RobotProvider.Call("findRobots"); AndroidJavaObject pairedRobots = m_RobotProvider.Call <AndroidJavaObject>("getRobots"); int pairedRobotCount = pairedRobots.Call <int>("size"); // Initialize Sphero array m_PairedSpheros = new Sphero[pairedRobotCount]; // Create Sphero objects for the Paired Spheros for (int i = 0; i < pairedRobotCount; i++) { // Set up the Sphero objects AndroidJavaObject robot = pairedRobots.Call <AndroidJavaObject>("get", i); string bt_name = robot.Call <string>("getName"); string bt_address = robot.Call <string>("getUniqueId"); m_PairedSpheros[i] = new SpheroAndroid(robot, bt_name, bt_address); } } }
// Update is called once per frame void Update () { if (!streaming && SpheroProvider.GetSharedProvider().GetConnectedSpheros().Length > 0) { // Setup streaming for the first time once a Sphero is connected. //// Register the event handler call back with the SpheroDeviceMessenger SpheroDeviceMessenger.SharedInstance.AsyncDataReceived += ReceiveAsyncMessage; //// Get the currently connected Sphero Sphero[] spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros(); m_Sphero = spheros[0]; //// Enable data streaming for controller app. This method turns off stabilization (disables the wheel motors), //// turn on the back LED (negative x axis reference), and sets data streaming at 20 samples/sec (400/20), //// a single sample per packet sent, and turns on accelerometer, quaternion, and IMU (attitude) sampling. m_Sphero.EnableControllerStreaming(20, 1, SpheroDataStreamingMask.AccelerometerFilteredAll | SpheroDataStreamingMask.QuaternionAll | SpheroDataStreamingMask.IMUAnglesFilteredAll); streaming = true; } }
override public Sphero[] GetConnectedSpheros() { List <Sphero> connectedSpheros = new List <Sphero>(); // Create a list of connected Spheros foreach (Sphero sphero in m_PairedSpheros) { if (sphero.ConnectionState == Sphero.Connection_State.Connected) { connectedSpheros.Add(sphero); } } // Create and fill an array of connected spheros Sphero[] spheroArray = new Sphero[connectedSpheros.Count]; int i = 0; foreach (Sphero sphero in connectedSpheros) { spheroArray[i] = sphero; i++; } return(spheroArray); }
// Use this for initialization void Awake() { /*var message = new Server.Message(Server.MessageType.RollSphero); message.AddContent(180.0f); message.AddContent(0.25f); message.AddContent("SPHERO-BOO"); Server.OpenConnection("127.0.0.1", 7777); Server.SendEndianness(); Server.Send(message);*/ Server.Name = "Rollout Server"; Server.StartListening(7777); Sphero boo = new Sphero(); boo.DeviceName = "tty.Sphero-BOO-AMP-SPP"; boo.Health = 96.4f; boo.Shield = 44.5f; boo.Weapons.Add(new SpheroWeapon(SpheroWeaponType.RailGun)); boo.BatteryVoltage = 7.2f; SpheroManager.Instances[boo.DeviceName] = boo; }
void Start() { ARUNController controller = ARUNController.Instance; if (controller != null) { controller.OnVisionUpdate += OnVisionUpdate; } else { //Debug.LogWarning("AureController.Instance not set"); } #if !UNITY_EDITOR // Get first connected Sphero Sphero[] spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros(); if (spheros.Length > 0) { sphero = spheros[0]; sphero.AddDataStreamingMask((ulong)kVisionMask); SpheroDeviceMessenger.SharedInstance.AsyncDataReceived += ReceiveAsyncMessage; } #endif }
// Update is called once per frame void Update() { if (!streaming && SpheroProvider.GetSharedProvider().GetConnectedSpheros().Length > 0) { // Setup streaming for the first time once a Sphero is connected. //// Register the event handler call back with the SpheroDeviceMessenger SpheroDeviceMessenger.SharedInstance.AsyncDataReceived += ReceiveAsyncMessage; //// Get the currently connected Sphero Sphero[] spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros(); m_Sphero = spheros[0]; //// Enable data streaming for controller app. This method turns off stabilization (disables the wheel motors), //// turn on the back LED (negative x axis reference), and sets data streaming at 20 samples/sec (400/20), //// a single sample per packet sent, and turns on accelerometer, quaternion, and IMU (attitude) sampling. m_Sphero.EnableControllerStreaming(20, 1, SpheroDataStreamingMask.AccelerometerFilteredAll | SpheroDataStreamingMask.QuaternionAll | SpheroDataStreamingMask.IMUAnglesFilteredAll); streaming = true; } }
// Use this for initialization void Awake() { /*var message = new Server.Message(Server.MessageType.RollSphero); * message.AddContent(180.0f); * message.AddContent(0.25f); * message.AddContent("SPHERO-BOO"); * * Server.OpenConnection("127.0.0.1", 7777); * * Server.SendEndianness(); * Server.Send(message);*/ Server.Name = "Rollout Server"; Server.StartListening(7777); Sphero boo = new Sphero(); boo.DeviceName = "tty.Sphero-BOO-AMP-SPP"; boo.Health = 96.4f; boo.Shield = 44.5f; boo.Weapons.Add(new SpheroWeapon(SpheroWeaponType.RailGun)); boo.BatteryVoltage = 7.2f; SpheroManager.Instances[boo.DeviceName] = boo; }
public static string GetNextSpheroName() { Sphero s = GetNextSphero(); return((s == null) ? SpectatorName : s.DeviceName); }
override public Sphero[] GetConnectedSpheros() { List<Sphero> connectedSpheros = new List<Sphero>(); // Create a list of connected Spheros foreach( Sphero sphero in m_PairedSpheros ) { if( sphero.ConnectionState == Sphero.Connection_State.Connected ) { connectedSpheros.Add(sphero); } } // Create and fill an array of connected spheros Sphero[] spheroArray = new Sphero[connectedSpheros.Count]; int i = 0; foreach( Sphero sphero in connectedSpheros ) { spheroArray[i] = sphero; i++; } return spheroArray; }
private void ProcessStreamedData(int type) { if (!Enum.IsDefined(typeof(ServerMessageType), type)) { Debug.LogFormat("Uknown type 0x{0:x2}.", type); return; } ServerMessageType messageType = (ServerMessageType)type; Debug.LogFormat("0x{0:x2}.", type); ServerMessage message = new ServerMessage(); switch (messageType) { case ServerMessageType.SpheroShoot: ReadStreamedBytes(6); ReadStreamedBytes(buffer[5], 6); SpheroManager.Shoot(buffer); break; case ServerMessageType.RollSphero: ReadStreamedBytes(9); ReadStreamedBytes(buffer[8], 9); SpheroManager.Roll(buffer); break; case ServerMessageType.SpheroPowerUp: ReadStreamedBytes(2); ReadStreamedBytes(buffer[1], 2); SpheroManager.UsePowerUp(buffer); break; case ServerMessageType.AppInit: ReadStreamedBytes(1); Sphero sphero = null; message.Type = ServerMessageType.AppInit; message.AddContent(BitConverter.IsLittleEndian); if (BitConverter.ToBoolean(buffer, 0) && ((sphero = SpheroManager.GetNextSphero()) != null)) { message.AddContent(sphero.DeviceName); } else { message.AddContent(SpheroManager.SpectatorName); //SpectatorManager.Instances.Add(new Spectator(receivedFrom)); } Send(message); if (sphero != null) { sphero.HasController = true; sphero.Connection = this; Debug.LogFormat("Health: {0}", sphero.Health); sphero.SendStateToController(); } break; case ServerMessageType.RemoveSphero: ReadStreamedBytes(1); ReadStreamedBytes(buffer[0], 1); Close(); // SpheroManager.RemoveSphero(buffer); // Server.TcpConnections.Remove(this); break; default: break; } }
void Start() { ARUNController controller = ARUNController.Instance; if (controller != null) { controller.OnVisionUpdate += OnVisionUpdate; } else { //Debug.LogWarning("AureController.Instance not set"); } #if !UNITY_EDITOR // Get first connected Sphero Sphero[] spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros(); if( spheros.Length > 0 ) { sphero = spheros[0]; sphero.AddDataStreamingMask((ulong)kVisionMask); SpheroDeviceMessenger.SharedInstance.AsyncDataReceived += ReceiveAsyncMessage; } #endif }
static void Main(string[] args) { SpheroConnector spheroConnector = new SpheroConnector(); Sphero sphero = null; string[] parameters = new string[] { "none" }; string command = "none"; while (!string.IsNullOrEmpty(command)) { command = parameters[0]; switch (command) { case "find": spheroConnector.Scan(); var deviceNames = spheroConnector.DeviceNames; for (int i = 0; i < deviceNames.Count; i++) { Console.WriteLine("{0}: {1}", i, deviceNames[i]); } break; case "connect": if (parameters.Length < 2) { break; } int index = -1; if (int.TryParse(parameters[1], out index)) { try { sphero = spheroConnector.Connect(index); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { Console.WriteLine("'{0}' is not a valid device index.", parameters[1]); } break; case "close": spheroConnector.Close(); break; case "sleep": sphero.Sleep(); break; case "setcolor": if (parameters.Length < 2) { break; } ChangeColor(sphero, parameters[1]); break; case "getresponses": { if (parameters.Length < 2) { break; } int count; if (int.TryParse(parameters[1], out count)) { lock (sphero.Listener.SyncRoot) { IEnumerable <SpheroResponsePacket> packets = sphero.Listener.GetLastResponsePackets(count); foreach (var packet in packets) { Console.WriteLine(packet); } } } } break; case "getasync": { if (parameters.Length < 2) { break; } int count; if (int.TryParse(parameters[1], out count)) { lock (sphero.Listener.SyncRoot) { IEnumerable <SpheroAsyncPacket> packets = sphero.Listener.GetLastAsyncPackets(count); foreach (var packet in packets) { Console.WriteLine(packet); } } } } break; case "exit": spheroConnector.Close(); Console.WriteLine("See you soon ... ;) "); Thread.Sleep(1500); return; case "sendprogram": { var area = StorageArea.Temporary; IEnumerable <string> programLines = GetOrbBasicLinesFromFile("orbbasic.txt"); foreach (var programLine in programLines) { Console.WriteLine(programLine); } sphero.EraseOrbBasicStorage(area); sphero.SendOrbBasicProgram(area, programLines); } break; case "runprogram": { StorageArea area = StorageArea.Temporary; sphero.ExecuteOrbBasicProgram(area, 10); } break; case "abortprogram": sphero.AbortOrbBasicProgram(); break; case "diagnostics": { sphero.PerformLevelOneDiagnostics(); } break; case "none": Console.WriteLine("Welcome to Sphero CMD controll application"); break; case "help": Console.WriteLine("HELP will be realized soon."); break; case "goForward": if (parameters.Length < 3) { break; } ChangeColor(sphero, "Red"); GoForward(sphero, Byte.Parse(parameters[1]), int.Parse(parameters[2])); break; default: Console.WriteLine("Unknown command. Please type 'help' for getting list of available commands."); break; } Console.Write("> "); parameters = Console.ReadLine().Split(new char[] { ' ' }); } }