38 lines
792 B
Python
38 lines
792 B
Python
import time
|
|
|
|
|
|
def delay(secs: float) -> generator:
|
|
end = time.monotonic() + secs
|
|
while time.monotonic() < end:
|
|
yield None
|
|
|
|
|
|
def fps(fps: float) -> generator:
|
|
yield None
|
|
dt = 1 / fps
|
|
until = time.monotonic() + dt
|
|
while True:
|
|
remain = until - time.monotonic()
|
|
if remain > 0:
|
|
time.sleep(remain)
|
|
until += dt
|
|
if remain < -dt:
|
|
# Catch up a bit
|
|
until += -remain / 3
|
|
yield None
|
|
|
|
|
|
def wait(stop: int) -> generator:
|
|
start = time.monotonic()
|
|
while True:
|
|
elapsed = int((time.monotonic() - start) * 1000)
|
|
elapsed = min(stop, elapsed)
|
|
yield elapsed
|
|
if elapsed >= stop:
|
|
break
|
|
|
|
|
|
def test():
|
|
for f in delay(2.0):
|
|
print(utime.ticks_ms())
|