Exemple #1
0
        public IObservable <T> WhenReadingTaken()
        {
            this.readOb = this.readOb ?? Observable.Create <T>(ob =>
            {
                var mgr = new AcrSensorManager(this.sensorManager);

                mgr.Start(this.type, this.ToSensorDelay(this.ReportInterval), e =>
                {
                    var reading = this.ToReading(e.Values);
                    ob.OnNext(reading);
                });
                return(() => mgr.Stop());
            })
                          .Publish()
                          .RefCount();

            return(this.readOb);
        }
Exemple #2
0
        public IObservable <CompassReading> WhenReadingTaken()
        {
            if (!this.IsAvailable)
            {
                return(Observable.Empty <CompassReading>());
            }

            this.readOb = this.readOb ?? Observable.Create <CompassReading>(ob =>
            {
                var accelMgr = new AcrSensorManager(this.sensorManager);
                var magMgr   = new AcrSensorManager(this.sensorManager);
                accelMgr.Start(SensorType.Accelerometer, SensorDelay.Fastest, e =>
                {
                    lock (this.syncLock)
                    {
                        this.lastAccel = e.Values.ToArray();
                        this.Calc(ob);
                    }
                });
                magMgr.Start(SensorType.MagneticField, SensorDelay.Fastest, e =>
                {
                    lock (this.syncLock)
                    {
                        this.lastMag = e.Values.ToArray();
                        this.Calc(ob);
                    }
                });
                return(() =>
                {
                    accelMgr.Stop();
                    magMgr.Stop();
                });
            })
                          .Publish()
                          .RefCount();

            return(this.readOb);
        }