LCD 160CR touch callback

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
User avatar
neuromanc
Posts: 5
Joined: Thu Jan 05, 2017 1:52 pm
Contact:

LCD 160CR touch callback

Post by neuromanc » Wed Feb 28, 2018 2:09 pm

Hi,

I've been coming back to a project (to drive my IKEA BEKANT desk automatically) and stumbled upon an issue that I had a while back. Currently I'm reading the touch coordinates of the display by running a `while True` loop and checking the last touched coordinates. What I'd like more is registering a ISR[1] and just call a method from my custom display driver class when the display has actually been touched.

If I recall correctly that wasn't possible half a year ago, due to missing implementation in the driver[2], but I might have been overlooking something.

Has anyone done this before?

For convenience here are the relevant ressources:

* API Doc: http://docs.micropython.org/en/latest/p ... 160cr.html
* [1] ISR tutorial: http://docs.micropython.org/en/latest/p ... rules.html
* [2] Source: https://github.com/micropython/micropyt ... cd160cr.py

Thanks

User avatar
pythoncoder
Posts: 3367
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: LCD 160CR touch callback

Post by pythoncoder » Thu Mar 01, 2018 8:10 am

The solution I use in my LCD160CR touch GUI is to use uasyncio. An interrupt is really overkill in this type of application: latency of a few tens of ms is never going to be noticed in touch applications. This coroutine is how I handle checking for touch events.
Peter Hinch

User avatar
neuromanc
Posts: 5
Joined: Thu Jan 05, 2017 1:52 pm
Contact:

Re: LCD 160CR touch callback

Post by neuromanc » Thu Mar 01, 2018 10:57 am

Hi Peter,

thank you for your reply. I find your user interface for the 160CR extremely useful. I'll throw my existing UI code in the trash and start using yours.

Nevertheless: What makes you say that an interrupt is overkill? To my understanding it's a way to register certain events to blocks of code, like a method of a class. Wouldn't that be exactly the case if I was waiting for a touch event on the display?

Thank you very much for the user interface code, I'm glad that's already been solved :)

User avatar
pythoncoder
Posts: 3367
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: LCD 160CR touch callback

Post by pythoncoder » Thu Mar 01, 2018 5:05 pm

Interrupts are indispensable when you require a microsecond-class response to an event, but their use requires care (see the docs). For user interactions that level of performance is not required. Using a cooperative scheduler (uasyncio) enables a callback to be associated with an action in a way which has no detectable drawback compared with using an interrupt. Interrupts would work, but in the context of a touch interface there is simply no need for them.

In the same vein my code for debouncing switches and pushbuttons uses uasyncio to associate callbacks with events like button pushes, releases and double-clicks without using interrupts, even though they are available. It's simpler, in my opinion, to do it that way.

Glad you like my GUI :D
Peter Hinch

Post Reply