Resolves #56 by moving kmk.common.* up a level to kmk.*

This commit is contained in:
Josh Klar
2018-10-11 18:02:13 -07:00
parent 30cd5da3f1
commit 00899d1b0f
35 changed files with 85 additions and 88 deletions

33
kmk/kmktime.py Normal file
View File

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