Update various internal key handling stuff to be CircuitPython-compatible

This commit is contained in:
Josh Klar
2018-10-07 00:44:04 -07:00
parent d379acfc97
commit a23acc6131
4 changed files with 27 additions and 23 deletions

View File

@@ -1,13 +1,33 @@
import math
try:
import utime
import utime as time
USE_UTIME = True
except ImportError:
pass
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)
def ticks_ms():
return utime.ticks_ms()
if USE_UTIME:
return time.ticks_ms()
else:
return math.floor(time.monotonic() * 1000)
def ticks_diff(new, old):
return utime.ticks_diff(new, old)
if USE_UTIME:
return time.ticks_diff(new, old)
else:
return new - old