Corrected data type on S variable to avoid NaN and devices crashing above 200C #10
+197
−185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses an issue when measuring temperatures above 200 C. Here, the
getObjectTemp()
method causes the sensor to reportNaN
values.Even worse, when connecting multiple FIR devices (with different addresses) to the same I2C bus ALL of them would report
NaN
even if only one of them measured above 200C. Weird behaviour.Our solution is on line 283 (278 in the original code):
since the
lowerRAM
andupperRAM
variables are declared asint16_t
the sum seems to overflow. The overflow created a divide-by-zero scenario on the following operations. The solution that we found was by casting and forcing them as doubles.We have successfully tested our solution without further crashing, however, the sensors report a maximum value of 245C, which is well beyond their rated range of 200C (and perhaps in the non-linear range or in the region where the polynomial function is not valid, however, we effectively eliminate the NaN on the current and other devices).
We believe that the rest of the devices connected to the same bus crashed too since a "Global Reset" communication is triggered (address
0x00
during the overflow, as specified by the datasheet on page 24:Please try to carry out further tests and merge this PR if you don't find any conflicts.
Thanks, guys