Exemple #1
0
        public IObservable <int> WhenReadingTaken()
        => this.observable ??= Observable.Create <int>(ob =>
        {
            var handler = new EventHandler <PedometerDataUpdatedEventArgs>((sender, args) =>
                                                                           ob.OnNext((int)args.StepCount)
                                                                           );
            var sensor = new Pedometer
            {
                Interval = 1000
            };
            sensor.DataUpdated += handler;
            sensor.Start();

            return(() =>
            {
                sensor.Stop();
                sensor.DataUpdated -= handler;
                sensor.Dispose();
            });
        })
        .Publish()
        .RefCount();
 /// <summary>
 /// Stops receiving sensor data
 /// </summary>
 /// <remarks>
 /// Reduce battery drain by stopping the sensor when it is not needed
 /// </remarks>
 public void Stop()
 {
     _sensor.Stop();
 }
Exemple #3
0
 public void StopReading()
 {
     _pedometer.DataUpdated -= PedometerReadingChanged;
     _pedometer.Stop();
 }
 /// <summary>
 /// Stops sensor and unregisters the listener from a sensor
 /// </summary>
 /// <param name="listener">Event handler registered</param>
 public void Stop(EventHandler <SensorEventArgs> listener)
 {
     sensor.Stop();
     sensor.DataUpdated -= handler;
 }