stdlib/time: Add time package (wrapping utime) with monotonic function. #502
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.
MicroPython replacement for time.monotonic suitable for timeouts / comparisons
CPython time.monotonic() → float returns the value (in fractional seconds) of a monotonic clock,
i.e. a clock that cannot go backwards. The clock is not affected by system clock updates.
The reference point of the returned value is undefined, so that only the difference between the
results of two calls is valid.
Most micropython ports have single-precision float for size / efficiency reasons, and some do not have
float support at all in hardware (so are very slow).
To support measurements of difference between two time points, time.ticks_ms() and time.ticks.diff()
are generally recommended, however this can complicate efforts to port existing libraries using
time.monotonic.
This library is intended to support being used as a drop-in replacement for many/most use cases of
time.monotonic. It will wrap the ticks functions and handle/hide the 32-bit rollover handling.
Note however if you convert the output of monotonic to int or float, eg
float(monotonic())
thencomparisions between these value are not always valid becasuse they will wrap around back to zero
after a certain length of time. In other words, always do comparisons against the object returned
by monotonic() without type conversion.
See the test_monotonic.py unit test for examples of usage.