Convert to supervisor ticks

This commit is contained in:
Kyle Brown committed 2021-09-14 07:56:38 -07:00
1 parent ea9625106c
commit 584eee64c6
8 files changed
+42 -46

No files matched your search

+11 -19
View File
@@ -1,23 +1,15 @@
import time
import const
_TICKS_PERIOD = const(1 << 29)
_TICKS_MAX = const(_TICKS_PERIOD - 1)
_TICKS_HALFPERIOD = const(_TICKS_PERIOD // 2)
def sleep_ms(ms):
return time.sleep(ms / 1000)
def ticks_diff(new, start):
diff = (new - start) & _TICKS_MAX
diff = ((diff + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD
return diff
def ticks_ms():
'''Has .25s granularity, but is cheap'''
return time.monotonic() * 1000
def ticks_diff(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)
def check_deadline(new, start, ms):
return ticks_diff(new, start) < ms