Example #1
0
        public static void Main()
        {
            Debug.Print("MPL3115A2 Test");
            var mpl3115a2 = new MPL3115A2(updateInterval: 0);

            while (true)
            {
                mpl3115a2.Update();
                Debug.Print("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " +
                            mpl3115a2.Pressure.ToString("f2"));
                Thread.Sleep(1000);
            }
        }
Example #2
0
        public static void Main()
        {
            Debug.Print("MPL3115A2 Test");
            var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);

            mpl3115a2.TemperatureChanged += (s, e) =>
            {
                Debug.Print("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
            };
            mpl3115a2.PressureChanged += (s, e) =>
            {
                Debug.Print("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
            };
            Thread.Sleep(Timeout.Infinite);
        }
Example #3
0
        public MeadowApp()
        {
            Console.WriteLine("Initializing...");

            // configure our BME280 on the I2C Bus
            var i2c = Device.CreateI2cBus();

            mpl3115A2 = new MPL3115A2(
                i2c
                );

            // Example that uses an IObersvable subscription to only be notified
            // when the temperature changes by at least a degree, and humidty by 5%.
            // (blowing hot breath on the sensor should trigger)
            mpl3115A2.Subscribe(new FilterableObserver <AtmosphericConditionChangeResult, AtmosphericConditions>(
                                    h => {
                Console.WriteLine($"Temp and pressure changed by threshold; new temp: {h.New.Temperature}, old: {h.Old.Temperature}");
            },
                                    e => {
                return(
                    (Math.Abs(e.Delta.Temperature) > 1)
                    &&
                    (Math.Abs(e.Delta.Pressure) > 5)
                    );
            }
                                    ));

            // classical .NET events can also be used:
            mpl3115A2.Updated += (object sender, AtmosphericConditionChangeResult e) => {
                Console.WriteLine($"  Temperature: {e.New.Temperature}ÂșC");
                Console.WriteLine($"  Pressure: {e.New.Pressure}hPa");
            };

            // get an initial reading
            ReadConditions().Wait();

            // start updating continuously
            mpl3115A2.StartUpdating();
        }
Example #4
0
 public async void Run(IBackgroundTaskInstance taskInstance)
 {
     MPL3115A2 sensor = new MPL3115A2();
     bool result = await sensor.BeginAsync();
     if (result)
     {
         float altitude = sensor.Altitude;
         float pressure = sensor.Pressure;
         System.Diagnostics.Debug.WriteLine("**************************************************");
         System.Diagnostics.Debug.WriteLine("MPL3115A2 Test Verification");
         System.Diagnostics.Debug.WriteLine("**************************************************");
         System.Diagnostics.Debug.WriteLine("ALTITUDE = [{0}]", altitude);
         System.Diagnostics.Debug.WriteLine("PRESSURE = [{0}]", pressure);
         if (altitude < 0 || pressure < 100000)
         {
             System.Diagnostics.Debug.WriteLine(">>> Failed. Received bad values from sensor");
         }
         else
         {
             System.Diagnostics.Debug.WriteLine(">>> Passed.");
         }
     }
 }
Example #5
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            MPL3115A2 sensor = new MPL3115A2();
            bool      result = await sensor.BeginAsync();

            if (result)
            {
                float altitude = sensor.Altitude;
                float pressure = sensor.Pressure;
                System.Diagnostics.Debug.WriteLine("**************************************************");
                System.Diagnostics.Debug.WriteLine("MPL3115A2 Test Verification");
                System.Diagnostics.Debug.WriteLine("**************************************************");
                System.Diagnostics.Debug.WriteLine("ALTITUDE = [{0}]", altitude);
                System.Diagnostics.Debug.WriteLine("PRESSURE = [{0}]", pressure);
                if (altitude < 0 || pressure < 100000)
                {
                    System.Diagnostics.Debug.WriteLine(">>> Failed. Received bad values from sensor");
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine(">>> Passed.");
                }
            }
        }