Can I use Both the touchscreen and Encoder input devices at once?


Trying to get touchscreen and encoder both to work.

What MCU/Processor/Board and compiler are you using?

ESP32, Arduino via

What do you want to achieve?

Want to use touchscreen and encoder at the same time.

What have you tried so far?

I have ‘doubled up’ the lv_indev parts of the code, trying to combine two working examples into one. Curently if I make a indev_drv2, or I try to ‘reuse’ the same lv_indev, I get the ESP rebooting in a kernel panic endless loop. Thanks for any advice!!

Code to reproduce

static lv_indev_t* encoder_indev; //The input device
static lv_indev_t* touchscreen_indev; //The input device
*Initialize the ENCODER*/
  lv_indev_drv_t indev_drv;
  indev_drv.type = LV_INDEV_TYPE_ENCODER;
  indev_drv.read_cb = read_encoder;
  encoder_indev = lv_indev_drv_register(&indev_drv);
  /*Initialize the touch pad*/
  //lv_indev_drv_t indev_drv;
  lv_indev_drv_init(&indev_drv);          /*Descriptor of a input device driver*/
  indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/
  indev_drv.read_cb = my_touchpad_read;   /*Set your driver function*/
  touchscreen_indev = lv_indev_drv_register(&indev_drv);      /*Finally register the driver*/


Yes, they can be used at same time. Do they work separetly?

Yes. Both of my test files work separately. The code above is from my attempt to combine them. When run it sends the ESP32 into an endless reboot cycle, with a kernel panic message on the terminal. I have working callback\event functions for both. But they do not work together. In addition, the encoder input is very sluggish, but I haven’t tried to figure out why or fix it yet. I am using example code found here:

Can you maybe just say a few brief words on the method(s) one would use to have both? Do I create separate indev_drv objects? Or just one and the two input devices register themselves separately?

Sorry if this should be obvious! I can post all of my code somewhere if it is helpful, but I was thinking a more general bit of advice might be enough. The code I posted above, the top 2 lines are just below all the includes and the 2 bottom blocks are in the setup function.

The touchscreen code is from the arduino LGVL example files. I can find a direct link if it will be helpful

Congratulations on the new website. It looks absolutely great, and your library is awesome! Thanks!

The code found here was the basis for the touchscreen portion of my attempt to get both the touchscreen and encoder working side by side.

There is no detaild docs about how to use 2 indev because it should simply work.

Can you post the ESP log about the crash?

I used a fuction to set all objects and the device into a default group automaticly.
It is needed to add every object manually without the fuction .

void groupset()
    group = lv_group_create();
    lv_indev_set_group(indev_encoder, group);

But I don’t know how to achieve the automatic goal with two type of input device.