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

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

            return(this.readOb);
        }
Example #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);
        }