Cruft cleaned, timers more accurate
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user