Update sensor code with speed and filespace improvements. #3
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.
Taking the advice offered in #1 , this updated version runs around 6x faster than before and trims down the output file.
Changes:
m/s²
toG
since it's metric/imperial agnostic.lis.read()
directly instead oflis.getEvent()
for a very small speed boost (but mostly to avoid conversion fromG
tom/s²
.201902171830.csv
).µs
,G
) in the header row to reduce disk usage.millis()
from output (same info provided bymicros()
).unsigned long
variables to reduce overhead.unixtime()
just once at start up and usemicros()
to estimate time afterward (shaved off 30ms per loop).Note: The process of writing to disk takes around 10 ms, which is still fairly slow. Ideally a buffered approach which only recorded movement would keep the output file significantly smaller. I hope to add that in a future iteration.
Chart Preview
Output Data Format
Here's a quick comparison of what the output data looks like before and after this change.
Before
After