Skip to content
Commit 0f219e1e authored by Trent Piepho's avatar Trent Piepho Committed by Anas Nashif
Browse files

drivers/sensor: si7006: Fix math for calculating sensor values



The existing code rounded the result to an integer, then multiplied that
integer by 1000000 to get micro-degrees or micro-percent, and then
divided by 1000000 to get whole degrees/percent and took the modulus to
get fractional degrees/percent.

Obviously, multiplying and then dividing an integer by the same value
has no effect!

The result is the humidity and temperature were always rounded down to
the nearest integer.

Fix this to properly keep the fractional component.  This is done in a
way that avoids any integer divisions, which are slow on all CPUs, but
especially most microcontrollers, e.g. Cortex-M, lack any integer
division instruction.

Avoiding the base 10 math does not require more code.  One just needs to
think in binary and use binary fractions instead of base 10 fractions.

Signed-off-by: default avatarTrent Piepho <tpiepho@gmail.com>
parent 88649dad
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment