This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
onewire.py: Optimize timing, enable CRC check and slim the code #62
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.
The reason for a change was the observation, that with about 1 in
300 measurements were wrong, some of them obviously. So I made a few
changes:
to 2 µs by not calling sleep_us() at all and reading the state of the bit
about 8 µs later. That matches better the datasheet.
returns None, when the CRC is wrong
about 5 times faster (1.9 ms -> 0.37 ms for 9 bytes)
Especially caching system call names in local variables for calls
used only once in a functions was dropped and replaced by storing
the callee names in the class. That saves a few microseconds - maybe not worth
the effort.
With change 1, readings with wrong crc are more rare now, about 1 in 15000,
and enabling the crc check allows to detect them.
The crc8 implementation is a Python port of the code published here:
http://lentz.com.au/blog/tag/crc-table-generator