Change EnviromentalSensor reading logic

This commit is contained in:
Denis-Cosmin Nutiu 2019-11-09 19:37:28 +02:00
parent 3ea3c9309b
commit e245ddc961
2 changed files with 13 additions and 12 deletions

View file

@ -3,7 +3,6 @@ using System.Device.I2c;
using System.Threading.Tasks;
using Iot.Device.Bmxx80;
using Iot.Device.Bmxx80.PowerMode;
using Iot.Units;
using Microsoft.Extensions.Logging;
namespace NucuCar.Sensors.EnvironmentSensor
@ -34,6 +33,10 @@ namespace NucuCar.Sensors.EnvironmentSensor
/* Initialize measurement */
_measurement = new Measurement();
_bme680.Reset();
_bme680.SetHumiditySampling(Sampling.UltraLowPower);
_bme680.SetTemperatureSampling(Sampling.UltraHighResolution);
_bme680.SetPressureSampling(Sampling.UltraLowPower);
_sensorState = SensorState.Initialized;
_logger.LogInformation($"{DateTimeOffset.Now}:BME680 Sensor initialization OK.");
@ -50,8 +53,8 @@ namespace NucuCar.Sensors.EnvironmentSensor
{
if (_sensorState != SensorState.Initialized)
{
_logger.LogWarning($"{DateTimeOffset.Now}:BME680: Attempting to take measurement while sensor is not initialized!");
_measurement.SetMeasurement(Temperature.FromCelsius(-1), -1, -1);
_logger.LogWarning(
$"{DateTimeOffset.Now}:BME680: Attempting to take measurement while sensor is not initialized!");
return;
}
@ -85,6 +88,4 @@ namespace NucuCar.Sensors.EnvironmentSensor
_bme680?.Dispose();
}
}
}