public void StopUpdatesWithMotionType(MotionDataType type)
        {
            switch (graphDataSource)
            {
            case MotionDataType.AccelerometerData:
                if (mManager.AccelerometerActive)
                {
                    mManager.StopAccelerometerUpdates();
                }
                break;

            case MotionDataType.GyroData:
                if (mManager.GyroActive)
                {
                    mManager.StopGyroUpdates();
                }
                break;

            case MotionDataType.DeviceMotion:
                if (mManager.DeviceMotionActive)
                {
                    mManager.StopDeviceMotionUpdates();
                }
                break;
            }
        }
 public GraphViewController(string title, MotionDataType type)
 {
     Title           = title;
     graphDataSource = type;
 }
        public void StartUpdatesWithMotionDataType(MotionDataType type, int sliderValue)
        {
            double updateInterval = 0.00;
            double delta          = 0.005;

            switch (graphDataSource)
            {
            case MotionDataType.AccelerometerData:
                updateInterval = GraphViewController.accelerometrMin + delta * sliderValue;
                if (mManager.AccelerometerAvailable)
                {
                    mManager.AccelerometerUpdateInterval = updateInterval;
                    mManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => {
                        if (primaryGraph == null)
                        {
                            return;
                        }

                        primaryGraph.AddX(data.Acceleration.X, data.Acceleration.Y, data.Acceleration.Z);
                        SetLabelValueX(data.Acceleration.X, data.Acceleration.Y, data.Acceleration.Z);
                    });
                }
                primaryGraphLabel.Text = "AccelerometerData.Acceleration";
                break;

            case MotionDataType.GyroData:
                updateInterval = gyroMin + delta * sliderValue;
                if (mManager.GyroAvailable)
                {
                    mManager.GyroUpdateInterval = updateInterval;
                    mManager.StartGyroUpdates(NSOperationQueue.CurrentQueue, (gyroData, error) => {
                        if (primaryGraph == null)
                        {
                            return;
                        }

                        primaryGraph.AddX(gyroData.RotationRate.x, gyroData.RotationRate.y, gyroData.RotationRate.z);
                        SetLabelValueX(gyroData.RotationRate.x, gyroData.RotationRate.y, gyroData.RotationRate.z);
                    });
                }
                primaryGraphLabel.Text = "GyroData.RotationRate";
                break;

            case MotionDataType.DeviceMotion:
                updateInterval = deviceMotionMin + delta * sliderValue;
                if (mManager.DeviceMotionAvailable)
                {
                    mManager.DeviceMotionUpdateInterval = updateInterval;
                    mManager.StartDeviceMotionUpdates(NSOperationQueue.CurrentQueue, (motion, error) => {
                        graphs [(int)DeviceMotionGraphType.Attitude].AddX(motion.Attitude.Roll, motion.Attitude.Pitch, motion.Attitude.Yaw);
                        graphs [(int)DeviceMotionGraphType.RotationRate].AddX(motion.RotationRate.x, motion.RotationRate.y, motion.RotationRate.z);
                        graphs [(int)DeviceMotionGraphType.Gravity].AddX(motion.Gravity.X, motion.Gravity.Y, motion.Gravity.Z);
                        graphs [(int)DeviceMotionGraphType.UserAcceleration].AddX(motion.UserAcceleration.X, motion.UserAcceleration.Y, motion.UserAcceleration.Z);

                        switch ((DeviceMotionGraphType)SegmentedControl.SelectedSegment)
                        {
                        case DeviceMotionGraphType.Attitude:
                            SetLabelValueRoll(motion.Attitude.Roll, motion.Attitude.Pitch, motion.Attitude.Yaw);
                            break;

                        case DeviceMotionGraphType.RotationRate:
                            SetLabelValueX(motion.RotationRate.x, motion.RotationRate.y, motion.RotationRate.z);
                            break;

                        case DeviceMotionGraphType.Gravity:
                            SetLabelValueX(motion.Gravity.X, motion.Gravity.Y, motion.Gravity.Z);
                            break;

                        case DeviceMotionGraphType.UserAcceleration:
                            SetLabelValueX(motion.UserAcceleration.X, motion.UserAcceleration.Y, motion.UserAcceleration.Z);
                            break;
                        }
                    });
                }
                primaryGraphLabel.Text = graphTitles [SegmentedControl.SelectedSegment];
                break;
            }
            UpdateIntervalLabel.Text = updateInterval.ToString();
        }
		public GraphViewController (string title, MotionDataType type)
		{
			Title = title;
			graphDataSource = type;
		}
		public void StopUpdatesWithMotionType (MotionDataType type)
		{
			switch (graphDataSource) {
			case MotionDataType.AccelerometerData:
				if (mManager.AccelerometerActive)
					mManager.StopAccelerometerUpdates ();
				break;
			case MotionDataType.GyroData:
				if (mManager.GyroActive)
					mManager.StopGyroUpdates ();
				break;
			case MotionDataType.DeviceMotion:
				if (mManager.DeviceMotionActive)
					mManager.StopDeviceMotionUpdates ();
				break;
			}
		}
		public void StartUpdatesWithMotionDataType (MotionDataType type, int sliderValue)
		{
			double updateInterval = 0.00;
			double delta = 0.005;
			switch (graphDataSource) {
			case MotionDataType.AccelerometerData:
				updateInterval = GraphViewController.accelerometrMin + delta * sliderValue;
				if (mManager.AccelerometerAvailable) {
					mManager.AccelerometerUpdateInterval = updateInterval;
					mManager.StartAccelerometerUpdates (NSOperationQueue.CurrentQueue, ( data,  error) => {
						if (primaryGraph == null)
							return;

						primaryGraph.AddX (data.Acceleration.X, data.Acceleration.Y, data.Acceleration.Z);
						SetLabelValueX (data.Acceleration.X, data.Acceleration.Y, data.Acceleration.Z);
					});
				}
				primaryGraphLabel.Text = "AccelerometerData.Acceleration";
				break;
			case MotionDataType.GyroData:
				updateInterval = gyroMin + delta * sliderValue;
				if (mManager.GyroAvailable) {
					mManager.GyroUpdateInterval = updateInterval;
					mManager.StartGyroUpdates (NSOperationQueue.CurrentQueue, (gyroData, error) => {
						if (primaryGraph == null)
							return;

						primaryGraph.AddX (gyroData.RotationRate.x, gyroData.RotationRate.y, gyroData.RotationRate.z);
						SetLabelValueX (gyroData.RotationRate.x, gyroData.RotationRate.y, gyroData.RotationRate.z);
					});
				}
				primaryGraphLabel.Text = "GyroData.RotationRate";
				break;
			case MotionDataType.DeviceMotion:
				updateInterval = deviceMotionMin + delta * sliderValue;
				if (mManager.DeviceMotionAvailable) {
					mManager.DeviceMotionUpdateInterval = updateInterval;
					mManager.StartDeviceMotionUpdates (NSOperationQueue.CurrentQueue, (motion, error) => {

						graphs [(int)DeviceMotionGraphType.Attitude].AddX (motion.Attitude.Roll, motion.Attitude.Pitch, motion.Attitude.Yaw);
						graphs [(int)DeviceMotionGraphType.RotationRate].AddX (motion.RotationRate.x, motion.RotationRate.y, motion.RotationRate.z);
						graphs [(int)DeviceMotionGraphType.Gravity].AddX (motion.Gravity.X, motion.Gravity.Y, motion.Gravity.Z);
						graphs [(int)DeviceMotionGraphType.UserAcceleration].AddX (motion.UserAcceleration.X, motion.UserAcceleration.Y, motion.UserAcceleration.Z);

						switch ((DeviceMotionGraphType) (int)SegmentedControl.SelectedSegment) {
						case DeviceMotionGraphType.Attitude:
							SetLabelValueRoll (motion.Attitude.Roll, motion.Attitude.Pitch, motion.Attitude.Yaw);
							break;
						case DeviceMotionGraphType.RotationRate:
							SetLabelValueX (motion.RotationRate.x, motion.RotationRate.y, motion.RotationRate.z);
							break;
						case DeviceMotionGraphType.Gravity:
							SetLabelValueX (motion.Gravity.X, motion.Gravity.Y, motion.Gravity.Z);
							break;
						case DeviceMotionGraphType.UserAcceleration:
							SetLabelValueX (motion.UserAcceleration.X, motion.UserAcceleration.Y, motion.UserAcceleration.Z);
							break;
						}
					});
				}
				primaryGraphLabel.Text = graphTitles [(int)SegmentedControl.SelectedSegment];
				break;
			}
			UpdateIntervalLabel.Text = updateInterval.ToString ();
		}