Closed pabigot closed 5 years ago
Thank you for this observation @pabigot. I have added the issue to our internal system and we will evaluate it.
Looking into the code it shows that the fractional part cannot be strictly between 0.7 and 0.8, rendering this logic error nonexistent. This is due to the resolution used for the sensor data.
This code appears to have the same bug reported at sparkfun/Qwiic_BME280_CCS811_Combo#8. Repeating the summary:
The code for configuring the CCS811 ENV_DATA values faithfully represents the instructions in the CCS811 Programming guide section 16, being:
The demonstration code is wrong, as it results in storing a value that is one unit too large when the fractional part is strictly between 0.7 and 0.8. In that case the whole value is incremented and the half-value is added, applying the half-round operation twice.
An appropriate replacement given the limited resolution of humidity data here is probably something like:
to round the MSB of each to the nearest half-unit.