2018-10-07 09:44:04 +02:00
|
|
|
import math
|
2018-10-16 13:04:39 +02:00
|
|
|
import time
|
2018-10-17 07:43:47 +02:00
|
|
|
|
2018-10-16 13:04:39 +02:00
|
|
|
USE_UTIME = False
|
2018-10-07 09:44:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2018-09-28 23:35:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
def ticks_ms():
|
2018-10-07 09:44:04 +02:00
|
|
|
if USE_UTIME:
|
|
|
|
return time.ticks_ms()
|
|
|
|
else:
|
|
|
|
return math.floor(time.monotonic() * 1000)
|
2018-09-28 23:35:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
def ticks_diff(new, old):
|
2018-10-07 09:44:04 +02:00
|
|
|
if USE_UTIME:
|
|
|
|
return time.ticks_diff(new, old)
|
|
|
|
else:
|
|
|
|
return new - old
|