sensors: Redefine SENSOR_CHAN_HUMIDITY in percents, not milli-percents.
Based on the discussion in #5693, the reason why humidity was defined in milli-percent was likely following Linux which defines it as such in its sensor subsystem: http://elixir.free-electrons.com/linux/latest/source/Documentation/ABI/testing/sysfs-bus-iio#L263 However, Linux defines temperature in milli-degrees either, but Zephyr uses degrees (similarly for most other quantities). Typical sensor resolution/precision for humidity is also on the order of 1%. One of the existing drivers, th02.c, already returned values in percents, and few apps showed it without conversion and/or units, leading to confusing output to user like "54500". So, switching units to percents, and update all the drivers and sample apps. For few drivers, there was also optimized conversion arithmetics to avoid u64_t operations. (There're probably more places to optimize it, and temperature conversion could use such optimization too, but that's left for another patch.) Fixes: #5693 Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This commit is contained in:
parent
2ff98636a5
commit
b7623a85b0
9 changed files with 23 additions and 23 deletions
|
@ -168,7 +168,7 @@ static int dht_channel_get(struct device *dev,
|
|||
#if defined(CONFIG_DHT_CHIP_DHT11)
|
||||
/* use only integral data byte */
|
||||
if (chan == SENSOR_CHAN_HUMIDITY) {
|
||||
val->val1 = drv_data->sample[0] * 1000;
|
||||
val->val1 = drv_data->sample[0];
|
||||
val->val2 = 0;
|
||||
} else { /* chan == SENSOR_CHAN_TEMP */
|
||||
val->val1 = drv_data->sample[2];
|
||||
|
@ -183,8 +183,8 @@ static int dht_channel_get(struct device *dev,
|
|||
|
||||
if (chan == SENSOR_CHAN_HUMIDITY) {
|
||||
raw_val = (drv_data->sample[0] << 8) | drv_data->sample[1];
|
||||
val->val1 = raw_val * 100;
|
||||
val->val2 = 0;
|
||||
val->val1 = raw_val / 10;
|
||||
val->val2 = (raw_val % 10) * 100000;
|
||||
} else { /* chan == SENSOR_CHAN_TEMP */
|
||||
raw_val = (drv_data->sample[2] << 8) | drv_data->sample[3];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue