Talk Script: Python, asyncio, libgpiod, and Pointless Blinking#
gpiod Intro#
gpiodbasics,BoxShow center on/off
Quickly explain
request_lines()(request.set_value()vs.request.set_values())Show
blink.glt2024.boxUse
Box.matrixinsert
snippets/blink, and use it
asyncio Intro#
threadinginsert
snippets/threadsstrace -f ...⟶ PIDsComplain about threads
Change to
asynciostrace -f ...again ⟶ no PIDs
And blink?#
Explain
on(),sleep(),any(),forever()Pull in snippet
blueprints/snippet-nice-patternAh,
wait_button()Revert to original blinking
Enclose in
any(), limiting it to 3 secons
gpiod, And Interrupts#
blink.base.sleep: timer eventOther events? ⟶ interrupt on GPIO line
Show
blueprints/gpiod-interrupts.pyDiscuss edges, timestamps, bouncing
FALLING,debounce_periodTransform into generator,
events()
Nice, Pythonic!
gpiod, Interrupts, and asyncio#
async def main(); simply iterate overevents()⟶ works
Second button, 19? Hm, tasks.
Wrap
events()iteration inprint_events()Make
print_events()asyncIn
main(), create two tasks aroundprint_events()⟶ one works, the other not
We block! Aha, async all over
Question: how make
events()async? asynchronous generator?Future, loops, blah
And blink?#
Show
wait_buttonback in
blink-demo.py, replacesleep(3)withwait_button()
textual#
My own stuff
$ ./run-menu.pyShow https://pypi.org/project/textual-imageview/
$ vimg ~/IMG<TAB>
python-sdbus#
Start the server:
$ ./dbus-blink-server.py
On another terminal, use busctl
$ busctl --user list
$ busctl --user introspect <TAB>
$ busctl --user call ...