コード例 #1
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 ) {
			// Go to the desired scene
			Application.LoadLevel (m_NextLevel); 
		}
	}
コード例 #2
0
	/*
	 * Callback to receive connection notifications 
	 */
	private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
	{
		SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;
		if( message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED ) {
			SpheroDeviceMessenger.SharedInstance.AsyncDataReceived -= ReceiveAsyncMessage;
			SpheroDeviceMessenger.SharedInstance.NotificationReceived -=
			 ReceiveNotificationMessage;
		}
	}
コード例 #3
0
ファイル: HelloWorld.cs プロジェクト: gustuvhx94/UNITY-PLUGIN
	/*
	 * 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");
		}
	}
コード例 #4
0
	/*
	 * 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;
		}
	}
コード例 #5
0
	/*
	 * 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;
		}
	}
コード例 #6
0
ファイル: UpdateValues.cs プロジェクト: PuxBotix/UNITY-PLUGIN
    private void ReceiveAsyncMessage(object sender, 
			SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        // Handler method for the streaming data. This code copies the data values
        // to instance variables, which are updated on the screen in the OnGUI method.
        SpheroDeviceSensorsAsyncData message =
            (SpheroDeviceSensorsAsyncData)eventArgs.Message;
        SpheroDeviceSensorsData sensorsData = message.Frames[0];

        acceleration = sensorsData.AccelerometerData.Normalized;

        pitch = sensorsData.AttitudeData.Pitch;
        roll = sensorsData.AttitudeData.Roll;
        yaw = sensorsData.AttitudeData.Yaw;

        q0 = sensorsData.QuaternionData.Q0;
        q1 = sensorsData.QuaternionData.Q1;
        q2 = sensorsData.QuaternionData.Q2;
        q3 = sensorsData.QuaternionData.Q3;
    }
コード例 #7
0
	private void ReceiveAsyncMessage(object sender, 
			SpheroDeviceMessenger.MessengerEventArgs eventArgs)
	{
		// Event Handler function 
		SpheroDeviceSensorsAsyncData message = 
			(SpheroDeviceSensorsAsyncData)eventArgs.Message;
		
		SpheroDeviceSensorsData sensorsData = message.Frames[0];
		
		// Get the yaw value which is used to rotate the on screen Sphero
		yaw1 = sensorsData.AttitudeData.Yaw;
		
		// Update the on screen Sphero position using the accelerometer values for x and y
		float xAcceleration = sensorsData.AccelerometerData.Normalized.X;
		float yAcceleration = sensorsData.AccelerometerData.Normalized.Y;
		Vector3 currentPosition = transform.position;
		
		// Create a new position by filtering the accelerometer data using the low pass
		// filtering formula (alpha * filteredValue + (1 - alpha) * newValue)
		position = new Vector3((0.9f * currentPosition.x + 0.1f * xAcceleration), 
			(0.9f * currentPosition.y + 0.1f * yAcceleration), 0.0f);
	}
コード例 #8
0
    private void ReceiveAsyncMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        // Handler method for the streaming data. This code copies the data values
        SpheroDeviceSensorsAsyncData message =
            (SpheroDeviceSensorsAsyncData)eventArgs.Message;
        SpheroDeviceSensorsData sensorsData = message.Frames[0];

        // There can be some discontinuation with vision data coming in, and what we requested,
        // so check if the data actually exists
        SpheroAttitudeData attitudeData = sensorsData.AttitudeData;
        if( attitudeData != null ) {
            SpheroYaw = sensorsData.AttitudeData.Yaw;
        }

        SpheroQuaternionData quaternionData = sensorsData.QuaternionData;
        if( quaternionData != null ) {
            SpheroQuaternion = new Quaternion(sensorsData.QuaternionData.Q1,
                                          	  sensorsData.QuaternionData.Q2,
                                              sensorsData.QuaternionData.Q3,
                                          	  sensorsData.QuaternionData.Q0);
        }
    }
コード例 #9
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;
				Application.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";
			}
		}
	}
コード例 #10
0
	static SpheroDeviceMessenger() 
	{
		sharedInstance = new SpheroDeviceMessenger();
		_RegisterRecieveDeviceMessageCallback(ReceiveDeviceMessage);
	}
コード例 #11
0
ファイル: UpdateValues.cs プロジェクト: PuxBotix/UNITY-PLUGIN
 /*
  * 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;
         if (m_threadSafeLoadLevel != null)
         {
             m_threadSafeLoadLevel.LoadLevel("NoSpheroConnectedScene");
         }
     }
 }
コード例 #12
0
 static SpheroDeviceMessenger()
 {
     sharedInstance = new SpheroDeviceMessenger();
     _RegisterRecieveDeviceMessageCallback(ReceiveDeviceMessage);
 }