Beispiel #1
0
 /// <summary>
 /// Raises the magnetometer changed event.
 /// </summary>
 /// <param name="data">Data.</param>
 /// <param name="error">Error.</param>
 void OnMagnetoMeterChanged(CMMagnetometerData data, NSError error)
 {
     if (error == null)
     {
         OnReadingChanged?.Invoke(this, new DeviceSensorReadingEventArgs <VectorReading>(new VectorReading(data.MagneticField.X, data.MagneticField.Y, data.MagneticField.Z)));
     }
     else
     {
         OnReadingError?.Invoke(this, new DeviceSensorReadingErrorEventArgs(error.Description));
     }
 }
 /// <summary>
 /// Raises the accelerometer changed event.
 /// </summary>
 /// <param name="data">Data.</param>
 /// <param name="error">Error.</param>
 void OnAccelerometerChanged(CMAccelerometerData data, NSError error)
 {
     if (error == null)
     {
         OnReadingChanged?.Invoke(this, new DeviceSensorReadingEventArgs <VectorReading>(new VectorReading(data.Acceleration.X, data.Acceleration.Y, data.Acceleration.Z)));
     }
     else
     {
         OnReadingError?.Invoke(this, new DeviceSensorReadingErrorEventArgs(error.Description));
     }
 }
 /// <summary>
 /// Raises the gyroscope changed event.
 /// </summary>
 /// <param name="data">Data.</param>
 /// <param name="error">Error.</param>
 void OnGyroscopeChanged(CMGyroData data, NSError error)
 {
     if (error == null)
     {
         OnReadingChanged?.Invoke(this, new DeviceSensorReadingEventArgs <VectorReading>(new VectorReading(data.RotationRate.x, data.RotationRate.y, data.RotationRate.z)));
     }
     else
     {
         OnReadingError?.Invoke(this, new DeviceSensorReadingErrorEventArgs(error.Description));
     }
 }
        public void StartReading(int reportInterval = -1)
        {
            if (reportInterval >= 0)
            {
                _motionManager.AccelerometerUpdateInterval = reportInterval;
            }

            try
            {
                _motionManager.StartAccelerometerUpdates(NSOperationQueue.MainQueue, OnAccelerometerChanged);
            }
            catch (Exception ex)
            {
                OnReadingError?.Invoke(this, new DeviceSensorReadingErrorEventArgs("Accelerometer - Not called from the UIThread"));
            }
        }
        private void OnPedometerChanged(CMPedometerData pedometerData, NSError error)
        {
            if (error == null)
            {
                var currentReadingTime = DateTime.Now;

                if (firstRead || (currentReadingTime - _lastReadingTime).TotalMilliseconds >= ReadingInterval)
                {
                    lastReading = (int)pedometerData.NumberOfSteps;
                    OnReadingChanged?.Invoke(this, new DeviceSensorReadingEventArgs <int>(lastReading));
                    firstRead = false;
                }
            }
            else
            {
                OnReadingError?.Invoke(this, new DeviceSensorReadingErrorEventArgs(error.Description));
            }
        }
        void OnBarometerChanged(CMAltitudeData data, NSError error)
        {
            if (error == null)
            {
                var currentReadingTime = DateTime.Now;

                if (firstRead || (currentReadingTime - _lastReadingTime).TotalMilliseconds >= ReadingInterval)
                {
                    _lastReading = data.Pressure.DoubleValue;
                    OnReadingChanged?.Invoke(this, new DeviceSensorReadingEventArgs <double>(_lastReading));
                    firstRead = false;
                }
            }
            else
            {
                OnReadingError?.Invoke(this, new DeviceSensorReadingErrorEventArgs(error.Description));
            }
        }
        public void StartReading(int reportingInterval = -1)
        {
            firstRead = true;

            try
            {
                altimeter.Value.StartRelativeAltitudeUpdates(NSOperationQueue.MainQueue, OnBarometerChanged);
            }
            catch (Exception ex)
            {
                OnReadingError?.Invoke(this, new DeviceSensorReadingErrorEventArgs("Barometer - Not called from the UIThread"));
            }

            if (reportingInterval >= 0)
            {
                _readingInterval = reportingInterval;
            }
            isActive = true;
        }