drivers: sensor: shtcx: fix val2 calculation

The calculation of the sensor val2 did not correctly take the sign into
account.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
This commit is contained in:
Thomas Stranger 2023-06-15 14:12:43 +02:00 committed by Anas Nashif
commit c9f8b8b78a

View file

@ -53,7 +53,7 @@ static void shtcx_temperature_from_raw(uint16_t raw, struct sensor_value *val)
tmp = (int32_t)raw * 175U - (45 << 16);
val->val1 = tmp / 0x10000;
/* x * 1.000.000 / 65.536 == x * 15625 / 2^10 */
val->val2 = ((tmp % 0x10000) * 15625U) / 1024;
val->val2 = ((tmp % 0x10000) * 15625) / 1024;
}
/* val = 100 * sample / (2^16) */