Improve speed of temperature retrieval and allow non-blocking measurement #19
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.
According to the MAX31856 datasheet, a one-shot temperature measurement takes approximately 160ms, and the ongoing status of the measurement can be queried by looking at the
CRO
register. However the current implementation in this library doesn't do this; it simply callssleep(0.250)
to block for 250ms upon triggering a measurement. Naturally this results in low performance if multiple sensors are used in parallel.This PR improves performance by making the
.temperature
retrieval property return as soon as the measurement is complete.Internally this is accomplished with new functions:
A developer may use these functions to read multiple MAX31856 sensors in parallel simultaneously because one is not blocking the other.
The original
.temperature
property still performs a blocking temperature retrieval to maintain expected behaviour, but it is refactored to use these functions, and now takes ~160ms instead of 250ms.Tested on a Feather ESP32-S2 with two MAX31856 sensors.