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:
Trent Piepho <tpiepho@gmail.com>
Loading
Please sign in to comment