Files
led-controller/stubs/utime.py
T
jimmyandClaude Haiku 5.5 4d8aeb5df8 feat: simulator bridge, rig seed and web UI (in progress)
Work in progress from the same tree as the controller's sequences-v2 changes.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-11-11 14:10:55 +13:00

50 lines
873 B
Python

"""CPython stub for MicroPython ``utime`` (led-simulator)."""
import time as _time
_MS_PERIOD = 1 << 30
_MS_MASK = _MS_PERIOD - 1
_HALF = _MS_PERIOD // 2
_T0 = _time.monotonic()
def sleep_ms(ms):
_time.sleep(max(0, ms) / 1000.0)
def sleep_us(us):
_time.sleep(max(0, us) / 1000000.0)
def sleep(s):
_time.sleep(s)
def ticks_ms():
return int((_time.monotonic() - _T0) * 1000) & _MS_MASK
def ticks_us():
return int((_time.monotonic() - _T0) * 1000000) & _MS_MASK
ticks_cpu = ticks_us
def ticks_add(ticks, delta):
return (int(ticks) + int(delta)) & _MS_MASK
def ticks_diff(t1, t0):
"""Signed difference with wrap-around, like MicroPython."""
return ((int(t1) - int(t0) + _HALF) & _MS_MASK) - _HALF
def time():
"""Whole seconds, like MicroPython."""
return int(_time.time())
def time_ns():
return _time.time_ns()