Ejemplo n.º 1
0
        public IObservable <MotionReading> WhenReadingTaken()
        {
            this.observable = this.observable ?? Observable.Create <MotionReading>(ob =>
            {
                var handler = new EventHandler <GyroscopeDataUpdatedEventArgs>((sender, args) =>
                                                                               ob.OnNext(new MotionReading(args.X, args.Y, args.Z))
                                                                               );
                var sensor = new Gyroscope
                {
                    Interval = 250
                };
                sensor.DataUpdated += handler;
                sensor.Start();

                return(() =>
                {
                    sensor.Stop();
                    sensor.DataUpdated -= handler;
                    sensor.Dispose();
                });
            })
                              .Publish()
                              .RefCount();

            return(this.observable);
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (_shouldDispose)
            {
                _i2cBus?.Dispose();
            }
            else
            {
                LedMatrix?.Dispose();
                LedMatrix = null !;

                Joystick?.Dispose();
                Joystick = null !;

                Gyroscope?.Dispose();
                Gyroscope = null !;

                Magnetometer?.Dispose();
                Magnetometer = null !;

                TemperatureAndHumidity?.Dispose();
                TemperatureAndHumidity = null !;

                PressureAndTemperature?.Dispose();
                PressureAndTemperature = null !;
            }

            _i2cBus = null !;
        }
Ejemplo n.º 3
0
 private void ClearSensors()
 {
     if (acc != null)
     {
         acc.Dispose();
     }
     if (gyro != null)
     {
         gyro.Dispose();
     }
     if (hum != null)
     {
         hum.Dispose();
     }
     if (ks != null)
     {
         ks.Dispose();
     }
     if (mg != null)
     {
         mg.Dispose();
     }
     if (ps != null)
     {
         ps.Dispose();
     }
     if (tempSen != null)
     {
         tempSen.Dispose();
     }
 }
        /// <summary>
        /// Releases all resources used by the current instance
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _sensor.DataUpdated -= OnSensorDataUpdated;
                    _sensor.Dispose();
                }

                _sensor   = null;
                _disposed = true;
            }
        }