From 3ca1162a6a0558f8166807e6467ca1936142ea3b Mon Sep 17 00:00:00 2001 From: Silke Hofstra Date: Wed, 3 Mar 2021 16:18:27 +0100 Subject: [PATCH] driver/bmx280: increase accuracy of SAUL pressure readings The SAUL implementation of the BMx280 currently returns the pressure in hPa. The sensor, however, actually reads the pressure in Pa, leading to a significant loss of precision. Because the operation range of the BME280 and BMP280 is 300 hPa to 1100 hPa, we can safely increase the precision by a factor of 10 without risk of overflow. The only downside is that readings are now presented as `e1 Pa` (eg 10206e1 Pa). --- drivers/bmx280/bmx280_saul.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/bmx280/bmx280_saul.c b/drivers/bmx280/bmx280_saul.c index e5c27c25a3..4c91177b15 100644 --- a/drivers/bmx280/bmx280_saul.c +++ b/drivers/bmx280/bmx280_saul.c @@ -35,9 +35,11 @@ static int read_temperature(const void *dev, phydat_t *res) static int read_pressure(const void *dev, phydat_t *res) { - res->val[0] = bmx280_read_pressure((bmx280_t *)dev) / 100; res->unit = UNIT_PA; - res->scale = 2; + res->scale = 0; + + int32_t val = bmx280_read_pressure((bmx280_t *)dev); + phydat_fit(res, &val, 1); return 1; }