/// <summary> /// Get measurements from sensors /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void _timer_Tick(object sender, object e) { try { if (_magnetometer.Connected) { var m = await _magnetometer.GetReadingAsync(); Debug.WriteLine("Magnetometer: " + m); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { MagX.Text = $"{m.X:f2} uT"; MagY.Text = $"{m.Y:f2} uT"; MagZ.Text = $"{m.Z:f2} uT"; }); } if (_barometer.Connected) { // Use HW oversample for less noise _barometer.OverSampling = 3; var b = await _barometer.GetReadingAsync(); Debug.WriteLine("Barometer: " + b); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { BarPressure.Text = $"{b.Pressure:f2} hPa"; BarTemp.Text = $"{b.Temperature:f2}°C"; }); } if (_tempHum.Connected) { // Bmp180 humidity sensor has a heater we can turn on if humidity is very high. // Heating reduces sensor wetting and stiction on high humidity conditions. // It also causes a temp gradient within the sensor and affects our dewpoint calculations. var th = await _tempHum.GetReadingAsync(); Debug.WriteLine("TempHum: " + th); Debug.WriteLine("Dewpoint: " + th.DewPoint); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { RhTemp.Text = $"{th.Temperature:f2}°C"; RhHum.Text = $"{th.Humidity:f0}%"; RhDew.Text = $"{th.DewPoint:f2}°C"; }); if (th.Humidity > 80) { _tempHum.Heater = true; } else if (th.Humidity < 70) { _tempHum.Heater = false; } } } catch (Exception ex) { // TODO: deal with individual reading failures Debug.WriteLine("A measurement failed: " + ex); } }