コード例 #1
0
        public IObservable <double> WhenReadingTaken()
        {
            this.observable = this.observable ?? Observable.Create <double>(ob =>
            {
                var handler = new EventHandler <HumiditySensorDataUpdatedEventArgs>((sender, args) =>
                                                                                    ob.OnNext(args.Humidity)
                                                                                    );
                var sensor = new HumiditySensor
                {
                    Interval = 250
                };
                sensor.DataUpdated += handler;
                sensor.Start();

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

            return(this.observable);
        }
コード例 #2
0
        /// <summary>
        /// Starts sensor and registers listener to a sensor
        /// </summary>
        /// <param name="listener">Event handler to listen sensor events</param>
        public void Start(EventHandler <SensorEventArgs> listener)
        {
            handler = (sender, e) =>
            {
                listener?.Invoke(this,
                                 new SensorEventArgs(new List <float>()
                {
                    e.Humidity
                }));
            };

            sensor.DataUpdated += handler;
            sensor.Start();
        }