lovyan03 / LovyanGFX

SPI LCD graphics library for ESP32 (ESP-IDF/ArduinoESP32) / ESP8266 (ArduinoESP8266) / SAMD51(Seeed ArduinoSAMD51)
Other
1.14k stars 204 forks source link

Read touch screen in an interrupt #431

Closed elengr closed 1 year ago

elengr commented 1 year ago

Read touch screen in an interrupt

Hey there I hope you are having a great day, I am working on a project with the LovyanGFX library. After finishing the project we wanted to add interrupts to our code. My issue is that I need to read the x and y coordinates for touch. I notice that lcd.getTouch(&x, &y); is frequently used. However, I cannot use this command within an interrupt because, as far as I can tell, it is an interrupt. Do you have any suggestions on what I should do?

Thank you in advance.

lovyan03 commented 1 year ago

In general, you should set some flag in the interrupt function and terminate processing immediately. The actual communication should be done in the main loop. You can do getTouch when the flag is set.

This is the job of the user code, not the GFX.

lovyan03 commented 1 year ago

I mentioned flags earlier, but the recommended method for ESP32 would be to use the FreeRTOS functionality to handle notifications between tasks.

elengr commented 1 year ago

Thanks for your advise :) Have a nice day.