drivers: sensor: sgp40: fix humidity formula

Fix the formula used to compute RH/ticks formula according to the Table
9 of the datasheet.

This patch also fixes coverity issue 238360.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-08-26 08:33:37 +02:00 committed by Anas Nashif
commit 09048f843a

View file

@ -82,7 +82,7 @@ static int sgp40_attr_set(const struct device *dev,
int32_t tmp;
tmp = CLAMP(val->val1, SGP40_COMP_MIN_RH, SGP40_COMP_MAX_RH);
rh_ticks = (tmp * 0xFFFF / 100U) + 0.5;
rh_ticks = (tmp * 65535) / 100;
sys_put_be16(rh_ticks, data->rh_param);
data->rh_param[2] = sgp40_compute_crc(rh_ticks);
}