NUC-32: Round sensor readings to two decimal points

This commit is contained in:
Denis-Cosmin Nutiu 2020-02-29 12:03:46 +02:00
parent 644d5f36c1
commit f50a81a030
2 changed files with 7 additions and 3 deletions

View file

@ -127,9 +127,9 @@ namespace NucuCar.Sensors.Environment
_bme680.TryReadPressure(out var pressure); _bme680.TryReadPressure(out var pressure);
_bme680.TryReadGasResistance(out var gasResistance); _bme680.TryReadGasResistance(out var gasResistance);
_lastMeasurement.Temperature = temp.Celsius; _lastMeasurement.Temperature = Math.Round(temp.Celsius, 2);
_lastMeasurement.Pressure = pressure.Hectopascal; _lastMeasurement.Pressure = Math.Round(pressure.Hectopascal, 2);
_lastMeasurement.Humidity = humidity; _lastMeasurement.Humidity = Math.Round(humidity, 2);
_lastMeasurement.VolatileOrganicCompounds = Math.Round(gasResistance / 1000, 2); _lastMeasurement.VolatileOrganicCompounds = Math.Round(gasResistance / 1000, 2);
Logger?.LogDebug($"{DateTimeOffset.Now}:BME680: reading"); Logger?.LogDebug($"{DateTimeOffset.Now}:BME680: reading");

View file

@ -54,6 +54,10 @@ namespace NucuCar.Sensors.Health
CurrentState = SensorStateEnum.Error; CurrentState = SensorStateEnum.Error;
_lastTemperatureCelsius = double.NaN; _lastTemperatureCelsius = double.NaN;
} }
else
{
_lastTemperatureCelsius = Math.Round(_lastTemperatureCelsius, 2);
}
} }
Logger?.LogDebug($"{DateTimeOffset.Now}:HealthSensor: reading"); Logger?.LogDebug($"{DateTimeOffset.Now}:HealthSensor: reading");
Logger?.LogInformation($"CPU Temperature {_lastTemperatureCelsius}"); Logger?.LogInformation($"CPU Temperature {_lastTemperatureCelsius}");