Exemplo n.º 1
0
        internal override void CheckAndDisableSensors()
        {
            base.CheckAndDisableSensors();

            if (Accelerometer.ShouldBeDisabled)
            {
                motionManager.StopAccelerometerUpdates();
            }

            if ((Compass.ShouldBeDisabled || Orientation.ShouldBeDisabled) && !Compass.IsEnabled && !Orientation.IsEnabled)
            {
                locationManagerActivated = false;
                locationManager.StopUpdatingHeading();
            }

            if (Gyroscope.ShouldBeDisabled)
            {
                motionManager.StopGyroUpdates();
            }

            if ((UserAcceleration.ShouldBeDisabled || Gravity.ShouldBeDisabled || Orientation.ShouldBeDisabled) && !UserAcceleration.IsEnabled && !Gravity.IsEnabled && !Orientation.IsEnabled)
            {
                motionManager.StopDeviceMotionUpdates();
            }
        }
Exemplo n.º 2
0
        public void StopSensorUpdates()
        {
            if (_motionManager.AccelerometerAvailable)
            {
                _motionManager.StopAccelerometerUpdates();
            }

            if (_motionManager.GyroAvailable)
            {
                _motionManager.StopGyroUpdates();
            }

            if (_motionManager.MagnetometerAvailable)
            {
                _motionManager.StopMagnetometerUpdates();
            }

            if (_motionManager.DeviceMotionAvailable)
            {
                _motionManager.StopDeviceMotionUpdates();
                _pedometer.StopPedometerUpdates();
            }

            IsListening = false;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Stop the specified sensor type reading.
        /// </summary>
        /// <param name="sensorType">Sensor type</param>
        public override void Stop(SensorType sensorType)
        {
            switch (sensorType)
            {
            case SensorType.Accelerometer:
                AccelerometerActive = false;
                motionManager.StopAccelerometerUpdates();
                break;

            case SensorType.Gyroscope:
                GyroActive = false;
                motionManager.StopGyroUpdates();
                break;

            case SensorType.DeviceMotion:
                DeviceMotionActive = false;
                motionManager.StopDeviceMotionUpdates();
                break;

            case SensorType.Compass:
                CompassActive = false;
                locationManager.StopUpdatingHeading();
                break;

            case SensorType.LightLevel:
                LightLevelActive = false;
                break;
            }
        }
 public void Stop()
 {
     motionManager.StopAccelerometerUpdates();
     motionManager.StopGyroUpdates();
     prevAccelTimeStamp = 0;
     prevGyroTimeStamp  = 0;
 }
        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;
            }
        }
        private void CollisionWithExit()
        {
            if (pacman.Frame.IntersectsWith(exit.Frame))
            {
                _motionManager.StopAccelerometerUpdates();
                _pacmanXVelocity = 0;
                _pacmanYVelocity = 0;

                new UIAlertView("Congratulations", "You've won the game!", null, "OK", null).Show();
            }
        }
Exemplo n.º 7
0
        protected override bool StopService()
        {
            _isOrientationUpdateThreadActive = false;

            if (_motionManager != null && IsAvailable())
            {
                _motionManager.StopAccelerometerUpdates();
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Stop the specified sensorType.
        /// </summary>
        /// <param name="sensorType">Sensor type.</param>
        public void Stop(MotionSensorType sensorType)
        {
            switch (sensorType)
            {
            case MotionSensorType.Accelerometer:
                if (motionManager.AccelerometerActive)
                {
                    motionManager.StopAccelerometerUpdates();
                }
                else
                {
                    Debug.WriteLine("Accelerometer not available");
                }
                break;

            case MotionSensorType.Gyroscope:
                if (motionManager.GyroActive)
                {
                    motionManager.StopGyroUpdates();
                }
                else
                {
                    Debug.WriteLine("Gyroscope not available");
                }
                break;

            case MotionSensorType.Magnetometer:
                if (motionManager.MagnetometerActive)
                {
                    motionManager.StopMagnetometerUpdates();
                }
                else
                {
                    Debug.WriteLine("Magnetometer not available");
                }
                break;

            case MotionSensorType.Compass:
                if (CLLocationManager.HeadingAvailable)
                {
                    locationManager.StopUpdatingHeading();
                    locationManager.UpdatedHeading -= OnHeadingChanged;
                }
                else
                {
                    Debug.WriteLine("Compass not available");
                }
                break;
            }
            sensorStatus[sensorType] = false;
        }
Exemplo n.º 9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            motionManager = new CMMotionManager();

            StartButton.TouchUpInside += (sender, e) =>
            {
                motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) =>
                {
                    this.xLabel.Text = data.Acceleration.X.ToString("0.0000");
                    this.yLabel.Text = data.Acceleration.Y.ToString("0.0000");
                    this.zLabel.Text = data.Acceleration.Z.ToString("0.0000");
                });
            };

            StopButton.TouchUpInside += (sender, e) =>
            {
                motionManager.StopAccelerometerUpdates();
            };
        }
Exemplo n.º 10
0
        partial void UIButton25_TouchUpInside(UIButton sender)
        {
            motionManager.StopAccelerometerUpdates();
            stoptime = DateTime.Now;
            builder.Length--;
            builder.Append("],");
            builder.Append("\"EndTime\":\"" + stoptime.ToString() + "\",");
            var alert = UIAlertController.Create("Mode", builder.ToString(), UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create("iOS_Car", UIAlertActionStyle.Default, async action => {
                builder.Append("\"Mode\":\"Car\"}"); await UseContainerSAS(sas, "iOS_Car", builder.ToString());
            }));

            alert.AddAction(UIAlertAction.Create("iOS_Bus", UIAlertActionStyle.Default, async action => {
                builder.Append("\"Mode\":\"Bus\"}"); await UseContainerSAS(sas, "iOS_Bus", builder.ToString());
            }));

            alert.AddAction(UIAlertAction.Create("iOS_Train", UIAlertActionStyle.Default, async action => {
                builder.Append("\"Mode\":\"Train\"}"); await UseContainerSAS(sas, "iOS_Train", builder.ToString());
            }));

            alert.AddAction(UIAlertAction.Create("iOS_Metro", UIAlertActionStyle.Default, async action => {
                builder.Append("\"Mode\":\"Metro\"}"); await UseContainerSAS(sas, "iOS_Metro", builder.ToString());
            }));

            alert.AddAction(UIAlertAction.Create("iOS_Walk", UIAlertActionStyle.Default, async action => {
                builder.Append("\"Mode\":\"Walk\"}"); await UseContainerSAS(sas, "iOS_Walk", builder.ToString());
            }));

            alert.AddAction(UIAlertAction.Create("iOS_Bike", UIAlertActionStyle.Default, async action => {
                builder.Append("\"Mode\":\"Bike\"}"); await UseContainerSAS(sas, "iOS_Bike", builder.ToString());
            }));

            alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
            PresentViewController(alert, animated: true, completionHandler: null);
        }
Exemplo n.º 11
0
 public void Stop()
 {
     motionManager.StopAccelerometerUpdates();
     prevTimeStamp = 0;
 }
 public void StopReading()
 {
     _motionManager.StopAccelerometerUpdates();
 }
Exemplo n.º 13
0
        public override void Update()
        {
            base.Update();

            // Enable/disable supported sensors and update enabled sensors
            if (accelerometerSensor != null)
            {
                bool enable = accelerometerSensor.IsEnabled;
                if (enable != motionManager.AccelerometerActive)
                {
                    if (accelerometerSensor.IsEnabled)
                    {
                        motionManager.StartAccelerometerUpdates();
                    }
                    else
                    {
                        motionManager.StopAccelerometerUpdates();
                    }
                }

                if (enable)
                {
                    var accelerometerData = motionManager.AccelerometerData;
                    accelerometerSensor.Acceleration = accelerometerData != null?CmAccelerationToVector3(accelerometerData.Acceleration) : Vector3.Zero;
                }
            }
            if (compassSensor != null)
            {
                bool enable = compassSensor.IsEnabled;
                if (enable != locationManagerActivated)
                {
                    if (compassSensor.IsEnabled)
                    {
                        locationManager.StartUpdatingHeading();
                    }
                    else
                    {
                        locationManager.StopUpdatingHeading();
                    }

                    locationManagerActivated = compassSensor.IsEnabled;
                }

                if (enable)
                {
                    compassSensor.Heading = GetNorthInRadian(locationManager);
                }
            }
            if (gyroscopeSensor != null)
            {
                bool enable = gyroscopeSensor.IsEnabled;
                if (enable != motionManager.GyroActive)
                {
                    if (gyroscopeSensor.IsEnabled)
                    {
                        motionManager.StartGyroUpdates();
                    }
                    else
                    {
                        motionManager.StopGyroUpdates();
                    }
                }

                if (enable)
                {
                    var gyroData = motionManager.GyroData;
                    gyroscopeSensor.RotationRate = gyroData != null?CmRotationRateToVector3(gyroData.RotationRate) : Vector3.Zero;
                }
            }
            if (userAccelerationSensor != null)
            {
                bool enable = userAccelerationSensor.IsEnabled || gravitySensor.IsEnabled || orientationSensor.IsEnabled;
                if (enable != motionManager.DeviceMotionActive)
                {
                    if (enable)
                    {
                        motionManager.StartDeviceMotionUpdates();
                    }
                    else
                    {
                        motionManager.StopDeviceMotionUpdates();
                    }
                }

                if (enable)
                {
                    var motion = motionManager.DeviceMotion;
                    // Update orientation sensor
                    if (motion != null && motion.Attitude != null)
                    {
                        var q          = motionManager.DeviceMotion.Attitude.Quaternion;
                        var quaternion = new Quaternion((float)q.x, (float)q.z, -(float)q.y, (float)q.w);

                        if (compassSensor != null)
                        {
                            // re-adjust the orientation to align with the north (common behavior on other platforms) TODO current implementation only takes in account the first value.
                            if (firstNorthValue <= 0)
                            {
                                firstNorthValue = GetNorthInRadian(locationManager);
                            }

                            quaternion = Quaternion.RotationY(-firstNorthValue) * quaternion;
                        }

                        orientationSensor.FromQuaternion(quaternion);
                    }
                    else
                    {
                        orientationSensor.Reset();
                    }

                    // Update gravity sensor
                    gravitySensor.Vector = motion != null?CmAccelerationToVector3(motion.Gravity) : Vector3.Zero;

                    // Update user acceleration
                    userAccelerationSensor.Acceleration = motion != null?CmAccelerationToVector3(motion.Gravity) : Vector3.Zero;
                }
            }
        }
Exemplo n.º 14
0
 public override void ViewWillDisappear(bool animated)
 {
     motionManager.StopAccelerometerUpdates();
     motionManager = null;
 }
Exemplo n.º 15
0
 protected override void StopListening()
 {
     _motionManager?.StopAccelerometerUpdates();
 }
Exemplo n.º 16
0
 protected override void StopSensingCore()
 {
     _locationManager.StopUpdatingLocation();
     _sensorManager.StopAccelerometerUpdates();
 }
Exemplo n.º 17
0
 public override void Stop()
 {
     motionManager.StopAccelerometerUpdates();
     started = false;
     state   = SensorState.Disabled;
 }
Exemplo n.º 18
0
 protected override void Stop(CMMotionManager mgr) => mgr.StopAccelerometerUpdates();
Exemplo n.º 19
0
        protected override async Task StopListeningAsync()
        {
            await base.StopListeningAsync();

            _motionManager?.StopAccelerometerUpdates();
        }
Exemplo n.º 20
0
 protected override void StopSensor() {
     _sensorManager.StopAccelerometerUpdates ();
 }
Exemplo n.º 21
0
 private void stopMonitoring()
 {
     motionManager.StopAccelerometerUpdates();
 }
Exemplo n.º 22
0
 public void Stop()
 {
     isRunning = false;
     isData    = false;
     motionManager.StopAccelerometerUpdates();
 }
Exemplo n.º 23
0
 public void Stop()
 {
     motionManager.StopAccelerometerUpdates();
 }