feat(extensions): most of the extensions implementation, by kdb424

This commit is contained in:
Kyle Brown authored and Josh Klar committed 2021-06-20 13:55:16 -07:00
1 parent 9821f7bcc3
commit e72d2b8c34
140 files changed
+3860 -2312

No files matched your search

+13 -19
View File
@@ -1,29 +1,23 @@
import math
import time
USE_UTIME = False
def sleep_ms(ms):
'''
Tries to sleep for a number of milliseconds in a cross-implementation
way. Will raise an ImportError if time is not available on the platform.
'''
if USE_UTIME:
return time.sleep_ms(ms)
else:
return time.sleep(ms / 1000)
return time.sleep(ms / 1000)
def ticks_ms():
if USE_UTIME:
return time.ticks_ms()
else:
return math.floor(time.monotonic() * 1000)
'''Has .25s granularity, but is cheap'''
return time.monotonic() * 1000
def ticks_diff(new, old):
if USE_UTIME:
return time.ticks_diff(new, old)
else:
return new - old
return new - old
def accurate_ticks():
'''Is more expensive, but good for time critical things'''
return time.monotonic_ns()
def accurate_ticks_diff(new, old, ms):
return bool(new - old < ms * 1000000)