Page 1 of 1

Event construction in micropython

Posted: Thu Oct 22, 2020 9:55 pm
by pulkin
Hi there,

I am looking for a good event-driven architecture to develop GUI on ESP32 board. My basic task is to, for example, react on touch screen and other interrupts without writing much code. The payload I am looking into may run for a while so I am probably looking at uasyncio. Can anybody point at a good library/example?

Re: Event construction in micropython

Posted: Thu Oct 22, 2020 11:59 pm
by jimmo

Re: Event construction in micropython

Posted: Fri Oct 23, 2020 8:25 pm
by pulkin
The second one is a monster library compared to my expectations. It looks like it polls touch hardware in a loop: pin_irq is not even used! Besides, it is hard-nailed to pyboard.

Re: Event construction in micropython

Posted: Sat Oct 24, 2020 10:26 am
by pythoncoder
This GUI repo for the official display is capable of running on an ESP32. It uses uasyncio internally: applications can use it if required or simply respond to callbacks. For larger displays there is this one which is also designed for portability.

Polling touch hardware actually works well. IRQ's are great when you need sub-millisecond response times but touch GUI's simply aren't in that category. You simply require a visibly quick response.

As for size, any GUI is likely to involve a significant amount of code. This one has been designed as a Python package so you only import what you need: this minimises RAM use.

Re: Event construction in micropython

Posted: Mon Oct 26, 2020 3:59 pm
by pythoncoder
pulkin wrote:
Fri Oct 23, 2020 8:25 pm
...It looks like it polls touch hardware in a loop: pin_irq is not even used! Besides, it is hard-nailed to pyboard.
I have appended this section to the uasyncio tutorial to justify the use of polling in such applications.

tl;dr With a cooperative scheduler, if you want to trigger a coroutine from a hardware change, interrupts offer no performance gain compared to polling the hardware.

Re: Event construction in micropython

Posted: Mon Oct 26, 2020 10:48 pm
by jimmo
pythoncoder wrote:
Mon Oct 26, 2020 3:59 pm
I have appended this section to the uasyncio tutorial to justify the use of polling in such applications.

tl;dr With a cooperative scheduler, if you want to trigger a coroutine from a hardware change, interrupts offer no performance gain compared to polling the hardware.
Yes, 100% agree. Great explanation.

Re: Event construction in micropython

Posted: Wed Nov 18, 2020 5:24 pm
by pulkin
I have to admit I ended up with the same kind of an infinite loop polling event queue. Events are added via interrupts. I also have to admit that having a single event slot per type instead of a queue seems to be a reasonable choice for touch events at least.

Re: Event construction in micropython

Posted: Thu Nov 19, 2020 8:33 am
by pythoncoder
I have updated the touch GUI for the official display to simplify deployment to the ESP32, and also added new widgets.