Near the beginning of my Rust learning adventure I wrote a small program to handle GPIO events generated by buttons.

The program implemented manual polling, with each of 7 GPIO lines being polled in separate threads. It worked smoothly but was super resource hungry (11% of CPU usage on my Pi3B+).

I rewrote it this weekend with tokio and the async feature of the gpio_cdev crate. CPU usage now sits at 0.0% with memory usage at 0.3%.

:)

Follow

The button program had additional complexities: it ran a JSON-RPC pub-sub server over websockets (lol). A separate menu program subscribed to the button-press events over JSON-RPC and used them to drive changes in a state machine for an OLED menu.

In hindsight, this was a pretty ridiculous arrangement.

The button logic is now included in the menu program. No more JSON-RPC pub-sub. The result is far less code, fewer dependencies, easier readability and major performance gains.

· · Web · 1 · 0 · 1

I love these moments when I can really sense how far I've come in my learning 🖤

Sign in to participate in the conversation
Merveilles

Merveilles is a community project aimed at the establishment of new ways of speaking, seeing and organizing information — A culture that seeks augmentation through the arts of engineering and design. A warm welcome to any like-minded people who feel these ideals resonate with them.