after having implemented the “evdev” module in the UNIX port for Raspberry Pi, I’ve now reached the next step which is to implement a proper event loop (for example, taken care of by the lvesp32 / lvstm32 modules). As a quick-and-dirty hack I used
while True:
lv.tick_inc(1)
lv.task_handler()
sleep_ms(100)
which seems to work. However, in various posts I read that you shouldn’t call them together in the same loop…
Would it be an option to use the “uasyncio” module instead? From what I’ve seen so far, it features timer and task functions…
Hi @gersch07
If I understand correctly, you are using Micropython on Linux with FrameBuffer.
Do you use the modfb.c driver?
This driver handles both the Frame-Buffer display on Linux systems and the periodic calls to tick_inc and task_handler.
If you have your own FrameBuffer driver for some reason, you can use modfb.c as a reference.
Here are the lines of code that create a thread and periodically call tick_inc and task_handler:
This produces a static “Hello World” button that doesn’t react to touch events, unless I use the hacky event loop above.
Could it be that framebuffer and SDL drivers work a bit differently? It looks like in SDL a thread (“mp_thread”, see line 84) is temporarily killed in line 41 to avoid REPL blocking the input. I think this is missing for “modfb.c”…
You are right.
The kill signal is sigusr1 which is not ment to kill, only to interrupt the REPL and give the event loop a chance to run.
I would need to fix that, but I’ll get to it only next week.
Essentially, we need two things:
send the sigusr1 signal periodically
register sigusr1 as an empty signal that does nothing (this prevents killing the application, but enough for interrupting the REPL)
You can try this yourself, or wait for about 1 week until I fix this on modfb code.
I’ve already done this function, but there’s a little problem with performance. I use Python thread to capture touch input events, but the CPU usage is too high.