Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ for complete device setup.
## App ownership

Board configs describe hardware. They export neutral pieces such as
`display_drv`, `touch_read`, `host_read`, and `timer_async`; they do not create
`display_drv`, `touch_read`, and `host_read`; they do not create
an application-level `appdev.App`.

Non-LVGL examples in this repo opt into the optional `appdev` coordinator:
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/alien/alien.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ def _tick(_=None):
tft_bitmap.bitmap(tft, alien, col, row)
st["last_col"], st["old_row"] = col, row

app.every(_tick, period=10, async_=app.timer_async)
app.every(_tick, period=10)
main()
2 changes: 1 addition & 1 deletion lib/examples/apollo/apollo.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ def _tick(_=None):


_init_apollo()
app.every(_tick, period=20, async_=app.timer_async)
app.every(_tick, period=20)
2 changes: 1 addition & 1 deletion lib/examples/appdev_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _on_event(e):


print("appdev_simpletest: started — click the canvas to see pointer events")
app.every(_heartbeat, period=2000, async_=app.timer_async)
app.every(_heartbeat, period=2000)

# Subscribe broadly via device type so any pointer/key event prints.
for et in (
Expand Down
6 changes: 3 additions & 3 deletions lib/examples/appdev_touch_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import appdev
import events

from multimer import auto as timer
import multimer

FG, BG, ARM = 0xFFFF, 0x0000, 12
W, H = display_drv.width, display_drv.height
Expand Down Expand Up @@ -66,13 +66,13 @@ def _on_up(e):
% (gx, gy, tx, ty, gx - tx, gy - ty)
)
idx += 1
timer.sleep_ms(400)
multimer.sleep_ms(400)
if idx >= len(TARGETS):
_out("done %s" % (results,))
display_drv.fill_rect(0, 0, W, H, BG)
else:
_show()
timer.sleep_ms(400)
multimer.sleep_ms(400)
finally:
_busy = False

Expand Down
6 changes: 3 additions & 3 deletions lib/examples/audiolive_rack.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,6 @@ def _on_quit(_e=None):
app.on(app.events.QUIT, _on_quit)

_draw_tick()
app.every(_audio_tick, period=AUDIO_MS, async_=app.timer_async)
app.every(_draw_tick, period=DRAW_MS, async_=app.timer_async)
app.every(_next_patch, period=PATCH_MS, async_=app.timer_async)
app.every(_audio_tick, period=AUDIO_MS)
app.every(_draw_tick, period=DRAW_MS)
app.every(_next_patch, period=PATCH_MS)
2 changes: 1 addition & 1 deletion lib/examples/bmp565_scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _tick(_=None):
draw_bg(0, i % display_drv.height, 0, i % image.height)
st["i"] = i + 1

app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)


main()
2 changes: 1 addition & 1 deletion lib/examples/bmp565_scroll_sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _tick(_=None):

app.on(app.events.MOUSEMOTION, _on_motion)
# ~20 fps once scrolling; first columns also tick so quit is always serviced.
app.every(_tick, period=50, async_=app.timer_async)
app.every(_tick, period=50)


main()
2 changes: 1 addition & 1 deletion lib/examples/bmp565_sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def _tick(_=None):
st["pos_i"] = (st["pos_i"] + 1) % len(positions)


app.every(_tick, period=100, async_=app.timer_async)
app.every(_tick, period=100)
2 changes: 1 addition & 1 deletion lib/examples/bmp565_sprite_transparent.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def _tick(_=None):
st["pos_i"] = (st["pos_i"] + 1) % len(positions)


app.every(_tick, period=100, async_=app.timer_async)
app.every(_tick, period=100)
2 changes: 1 addition & 1 deletion lib/examples/bouncing_balls.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def _tick(_=None):
pygraphics.circle(display_drv, int(ball.x), int(ball.y), ball.r, ball.color, True)


app.every(_tick, period=10, async_=app.timer_async)
app.every(_tick, period=10)
2 changes: 1 addition & 1 deletion lib/examples/boxlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ def _tick(_=None):
poll()


app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)
6 changes: 3 additions & 3 deletions lib/examples/calc_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from calc_engine import CalcEngine
import keys
from pygraphics import RGB565, FrameBuffer
from multimer import auto as timer
import multimer
from palettes import get_palette
from appdev import TouchGrid

Expand Down Expand Up @@ -122,7 +122,7 @@ def __init__(self):
# have no grid cell so the touch mapping never indexes them.
keypad_keys = [None] * self.COLS + list(_CODES) + list(_KEY_ALIASES.keys())
self._pending_release = None
self._release_timer = timer.Timer(-1)
self._release_timer = multimer.Timer(-1)
self.keypad = TouchGrid(
app,
0,
Expand Down Expand Up @@ -264,7 +264,7 @@ def _on_press(self, code):
self._handle_press(col, row, label)
self._pending_release = (col, row, label)
self._release_timer.init(
mode=timer.Timer.ONE_SHOT, period=150, callback=self._release
mode=multimer.Timer.ONE_SHOT, period=150, callback=self._release
)
return
# Keyboard alias / digit without a grid cell — feed the engine only.
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/car_cluster/car_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _drain_rails(_t):
if _ui is not None and _ui.rails is not None:
_ui.rails.drain_pending()

app.on_tick(_drain_rails, period=30, async_=False)
app.on_tick(_drain_rails, period=30)
_ui.rails.drain_pending()
if _FREEZE:
freeze(True)
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/color_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ def poll():
def _tick(_=None):
poll()

app.every(_tick, period=1000, async_=app.timer_async)
app.every(_tick, period=1000)
main()
2 changes: 1 addition & 1 deletion lib/examples/dino.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,5 +545,5 @@ def _tick(timer=None):
game.tick(timer)


_tick_subscription = app.every(_tick, period=FRAME_MS, async_=app.timer_async)
_tick_subscription = app.every(_tick, period=FRAME_MS)
game.draw()
2 changes: 1 addition & 1 deletion lib/examples/displaysys_block_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ def _tick(_=None):
app.request_quit()


app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)
2 changes: 1 addition & 1 deletion lib/examples/displaysys_fill_rect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def _tick(_=None):
app.request_quit()


app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)
2 changes: 1 addition & 1 deletion lib/examples/feathers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ def _tick(_=None):
poll()


app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)
2 changes: 1 addition & 1 deletion lib/examples/font_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def main():
def _tick(_=None):
poll()

app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)


main()
2 changes: 1 addition & 1 deletion lib/examples/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ def main():
def _tick(_=None):
poll()

app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)
main()
17 changes: 7 additions & 10 deletions lib/examples/google_photos/google_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _block_if_batch():
path, MCU REPL, PyScript, the example kit) keeps the app alive by itself.
"""
try:
from appdev import _hostloop
from multimer import _hostloop
from display_driver import app

if not _launched_with_m(_hostloop) or _hostloop.ambient():
Expand All @@ -124,19 +124,16 @@ def _block_if_batch():
return
except Exception:
return
if app.strategy != _hostloop.AMBIENT or app.timer_async:
app.run() # "none": blocking service loop (async timers: asyncio.run)
if app.strategy != _hostloop.AMBIENT:
app.run() # "none": blocking service loop
return
# "ambient" was chosen at import time; the timer already drives the app,
# so just hold the main thread until the window closes. Hold it with the
# timer backend's own sleep, never time.sleep: on Windows the timer fires
# only while this thread is in an alertable wait (SleepEx), and a plain
# time.sleep starves it -- the window then never repaints and Windows
# marks it "Not Responding".
from multimer import auto as timer
# so just hold the main thread until the window closes, delivering on
# the way (multimer.sleep_ms serves the timers on every host).
import multimer

while not app.quit_requested:
timer.sleep_ms(50)
multimer.sleep_ms(50)


def _launched_with_m(_hostloop):
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ def main():
def _tick(_=None):
poll()

app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)
main()
33 changes: 11 additions & 22 deletions lib/examples/lv_test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

from board_config import display_drv
from displaydev import env_get
from multimer import auto as timer
import multimer

# Optional logical orientation for LVGL (hw MADCTL/SDL/PG or software rotate).
_lv_rot = env_get("PYDEVICES_LV_ROTATION")
Expand All @@ -61,7 +61,7 @@


def _mode_label():
return "async" if getattr(app, "timer_async", False) else "sync"
return multimer.info().get("source") or "sync"


def get_state():
Expand Down Expand Up @@ -124,18 +124,9 @@ def _lvgl_label():


def _timer_type():
# Deliberately not named ``timer``: that would shadow the module-level
# ``multimer.auto`` import this function falls back to, and the fallback
# then reads None on any provider that has not armed yet.
armed = getattr(app, "_timer", None)
if armed is not None:
return _format_timer_type(type(armed))
try:
from multimer import AsyncTimer

return _format_timer_type(AsyncTimer if app.timer_async else timer.Timer)
except ImportError:
return "?"
# multimer has one Timer class; what differs per host is the wake source.
info = multimer.info()
return "%s/%s" % (info.get("source"), info.get("delivery"))


def get_platform_info():
Expand Down Expand Up @@ -285,9 +276,8 @@ def mock_read():
try:
deadline = time.time() + 1.5
while (pending or get_state()["taps"] < 1) and time.time() < deadline:
# Pump: the host queue is drained from the app tick, which
# pump-based backends only deliver while the main thread sleeps here.
timer.sleep_ms(10)
# multimer.sleep_ms delivers on every host while this thread waits.
multimer.sleep_ms(10)
finally:
queue_dev._read = orig_read
return get_state()["taps"]
Expand Down Expand Up @@ -364,10 +354,9 @@ def _run_kit_sync():
deadline = time.time() + _DURATION_S
clicked_taps = None
while time.time() < deadline:
# timer.sleep_ms, not time.sleep: pump-based backends (threading on
# CircuitPython / Windows CPython, SDL2) deliver callbacks only
# while the main thread pumps. For librt this resolves to a plain sleep.
timer.sleep_ms(10)
# multimer.sleep_ms, not time.sleep: a host with no wake source
# (CircuitPython) delivers only while this thread waits here.
multimer.sleep_ms(10)
if clicked_taps is None and get_state()["seconds"] >= 2:
cx, cy = _button_center(btn)
clicked_taps = _inject_click(cx, cy)
Expand Down Expand Up @@ -405,7 +394,7 @@ def run_kit():
``app.poll()`` while LVGL owns the host queue.
"""
try:
if app.timer_async:
if multimer.loop_running():
payload = app.run_async(_run_kit_async)
if payload is not None and hasattr(payload, "done"):
_quit_and_exit(1)
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/palettes_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ def _tick(_=None):
poll()


app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)
2 changes: 1 addition & 1 deletion lib/examples/pixel_sim_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,4 @@ def _tick(_=None):
_next_at = now


app.every(_tick, period=1, async_=app.timer_async)
app.every(_tick, period=1)
2 changes: 1 addition & 1 deletion lib/examples/proverbs/proverbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _tick(_=None):

st["index"] = (st["index"] + 1) % len(proverbs)

app.every(_tick, period=5000, async_=app.timer_async)
app.every(_tick, period=5000)


main()
2 changes: 1 addition & 1 deletion lib/examples/pydevices_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@ def _on_click(e):

setup_scroll()
redraw()
app.every(_scroll_tick, period=40, async_=app.timer_async)
app.every(_scroll_tick, period=40)
app.on(app.events.MOUSEBUTTONDOWN, _on_click)
6 changes: 3 additions & 3 deletions lib/examples/roku_remote/roku_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
app = appdev.App(board_config)
import keys
from pygraphics import RGB565, Area, FrameBuffer
from multimer import auto as timer
import multimer
from roku_engine import (
FRONTEND_BUTTONS,
app_label,
Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(self, engine=None, start_page="devices"):

self.buttons = []
self._by_id = {}
self._status_timer = timer.Timer(-1)
self._status_timer = multimer.Timer(-1)
self._pending_status = None
self._pending_state = None
self._playback_busy = False
Expand Down Expand Up @@ -311,7 +311,7 @@ def _soft():
# Must not call Timer.deinit from this callback (librt deadlock).
try:
self._status_timer.init(
mode=timer.Timer.PERIODIC,
mode=multimer.Timer.PERIODIC,
period=250,
callback=self._status_pump,
hard=False,
Expand Down
Loading
Loading