Another question about input drivers

Hello all,

I have another question about the LittleVGL input drivers.I have an application that has a touchscreen calibration function. This requires that I change the input callback at runtime. When the program is first run it configures the driver like so:

lv_indev_drv_init(&input_dev_drv);
input_dev_drv.type = LV_INDEV_TYPE_POINTER;
input_dev_drv.read_cb = touchpad_read;
lv_indev_drv_register(&input_dev_drv);

On another screen, I run this code to allow for the calibration to work:

lv_indev_drv_init(&input_dev_drv);
input_dev_drv.type = LV_INDEV_TYPE_POINTER;
input_dev_drv.read_cb = touchpad_read_raw;
lv_indev_drv_register(&input_dev_drv);

At the end of the calibration code, I run this:

lv_indev_drv_init(&input_dev_drv);
input_dev_drv.type = LV_INDEV_TYPE_POINTER;
input_dev_drv.read_cb = touchpad_read;
lv_indev_drv_register(&input_dev_drv);

To reinstate the original touch handler.

I have logging outputs in my two callbacks and when I’m in the touchpad_read_raw callback I also see the text for the touchpad_read function. This indicates that to me, both functions are running somehow.

I suspect this is due to the fact that the input device is registered on two different screens. Whats the best way to get the correct function to run without the other one running as well?

Thanks,

JD

When you first configure the driver:

lv_indev_t * ts = lv_indev_drv_register(&input_dev_drv);

Later, when you change input_dev_drv:

lv_indev_drv_update(ts, &input_dev_drv);

There’s no need to re-register the driver and reset all the fields; just update the ones you care about, then flush the changes using lv_indev_drv_update.