public MeadowApp() { Console.WriteLine("Initializing..."); // create a trigger for the LA trigger = Device.CreateDigitalOutputPort(Device.Pins.D13); Console.WriteLine("Trigger on D02"); trigger.State = true; // configure our BME280 on the I2C Bus var i2c = Device.CreateI2cBus(); bme280 = new Bme280( i2c, Bme280.I2cAddress.Adddress0x76 //default //Bme280.I2cAddress.Adddress0x77 //default ); // TODO: SPI version // 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) bme280.Subscribe(new FilterableChangeObserver <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.Value) > 1) && (Math.Abs(e.Delta.Pressure.Value) > 5) ); } )); // classical .NET events can also be used: bme280.Updated += (object sender, AtmosphericConditionChangeResult e) => { Console.WriteLine($" Temperature: {e.New.Temperature}°C"); Console.WriteLine($" Pressure: {e.New.Pressure}hPa"); Console.WriteLine($" Relative Humidity: {e.New.Humidity}%"); }; // just for funsies. Console.WriteLine($"ChipID: {bme280.GetChipID():X2}"); //Thread.Sleep(1000); //// is this necessary? if so, it should probably be tucked into the driver //Console.WriteLine("Reset"); //bme280.Reset(); // get an initial reading ReadConditions().Wait(); // start updating continuously bme280.StartUpdating(); }
public TemperatureMonitor(II2cBus i2CBus, Logger logger) { _logger = logger; _bme280 = new Bme280(i2CBus, Bme280.I2cAddress.Adddress0x77); _bme280.Subscribe(new FilterableChangeObserver <AtmosphericConditionChangeResult, AtmosphericConditions>( h => ProcessAtmosphericChange(h.New), e => Math.Abs(e.Delta.Temperature.GetValueOrDefault()) > 0.1 )); // get chip id _logger.LogMessage(() => $"BME280 ChipID: {_bme280.GetChipID():X2}"); // get an initial reading ReadConditions().ContinueWith(t => _bme280.StartUpdating()); }