drivers: sensor: sgp40: fix temperature formula

Fix the formula that computes T/ticks according to the details found on
Table 9 of the datasheet.

This patch fixes coverity issue 238343.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-08-26 08:30:31 +02:00 committed by Anas Nashif
commit 9dab2b3c5c

View file

@ -71,7 +71,7 @@ static int sgp40_attr_set(const struct device *dev,
int32_t tmp; int32_t tmp;
tmp = CLAMP(val->val1, SGP40_COMP_MIN_T, SGP40_COMP_MAX_T); tmp = CLAMP(val->val1, SGP40_COMP_MIN_T, SGP40_COMP_MAX_T);
t_ticks = ((tmp + 45U) * 0xFFFF / 175U) + 0.5; t_ticks = ((tmp + 45) * 65535) / 175;
sys_put_be16(t_ticks, data->t_param); sys_put_be16(t_ticks, data->t_param);
data->t_param[2] = sgp40_compute_crc(t_ticks); data->t_param[2] = sgp40_compute_crc(t_ticks);
} }