Calibrating and configuring evdevtouch on embedded qt project

2.5k views Asked by At

I have a Qt project running on a icoremx6solo with linux. I've setted up the graphics and run the code, but i can't handle touch inputs. Enabling the input logging with

export QT_LOGGING_RULES="qt.qpa.input=true"

i discovered that the coordinates ar not setted, i think that this is the main problem with that:

qt.qpa.input: evdevtouch: /dev/input/event0: Protocol type B  (multi)   
qt.qpa.input: evdevtouch: /dev/input/event0: min X: 0 max X: -1
qt.qpa.input: evdevtouch: /dev/input/event0: min Y: 0 max Y: -1
qt.qpa.input: evdevtouch: /dev/input/event0: min pressure: 0 max pressure: 0      
qt.qpa.input: evdevtouch: /dev/input/event0: device name: EP0790M09

but i can't find a way to calibrate that evdevtouch.

I tried runnin the executable with -plugin tslib attribute after executing the ts_calibrate command but the output is the same.

so, how can i fix that having a running touchscreen?

2

There are 2 answers

0
ianeperson On

Looking at QT's source (qevdevtouchhandler.cpp) the calibration values (min, max, pressure…) are obtained directly from the device ioctl.

There doesn't seem to be a way in Qt to change these values.

Looking at the kernel source for my controller (ADS7843 on Atmel spi) there doesn't seem to a way to change the values from user space (/proc, /sys).

The following snippet seems to do the job – reading and writing the calibration values:

    // check the parameter count
    if (argc != 3 && argc != 5) {
        puts ("Get usage: evgetset device absnumber");
        puts ("Set usage: evgetset device absnumber valname value");
        return (1);
    }

    // the first parameter is the device file name
    fd = open(argv[1], O_RDONLY);
    if (fd < 0) {
            puts ("Could not open device file - are you running as root");
        return (1);
    }

    // the second parameter is the parameter number
    absnumber = atoi (argv[2]);
    if (absnumber < 0 || absnumber > ABS_MAX) {
        puts ("absnumber out of range");
        return (1);
    }

    // Read the ioctl and display the current values
    ioctl(fd, EVIOCGABS(absnumber), &absval);
    printf ("Properties for %d\n", absnumber);
    printf ("Value : %d\n", absval.value);
    printf ("Minimum : %d\n", absval.minimum);
    printf ("Maximum : %d\n", absval.maximum);
    printf ("Fuzz : %d\n", absval.fuzz);
    printf ("Flat : %d\n", absval.flat);
//  printf ("Resolution : %d\n", absval.resolution);

    // check if a write is wanted - and do it
    if (argc == 5) {
        valvalue = atoi (argv[4]);
        if (!strcmp ("Value", argv[3])) absval.value = valvalue;
        if (!strcmp ("Minimum", argv[3])) absval.minimum = valvalue;
        if (!strcmp ("Maximum", argv[3])) puts ("Got Maximum");
        if (!strcmp ("Maximum", argv[3])) absval.maximum = valvalue;
        if (!strcmp ("Fuzz", argv[3])) absval.fuzz = valvalue;
        if (!strcmp ("Flat", argv[3])) absval.flat = valvalue;
//      if (!strcmp ("Resolution", argv[2]) absval.resolution = valvalue;
        ioctl(fd, EVIOCSABS(absnumber), &absval);
    }
    // all done
    close(fd);
0
Wooyay On

Thank you ianeperson! From your answer I managed to get my xpt2046 5 inch touch screen working with Qt. My code:

#include "setuptouchscreen.h"
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#include <string.h>
#include <dirent.h>
#include <qdebug.h>

#define DEVICE_NAME "ADS7846 Touchscreen"
#define INPUT_PATH "/dev/input"

// got these values from file https://github.com/goodtft/LCD-show/blob/master/usr/99-calibration.conf-5-0
#define X_MIN 140
#define X_MAX 3951
#define Y_MIN 261
#define Y_MAX 3998

int setupTouchScreen() {


    DIR* directory = opendir(INPUT_PATH);
    if (!directory) {
        qDebug("setupTouchScreen:: Failed to open %s.", INPUT_PATH);
        return -1;
    }

    bool found = false;
    struct dirent *entry = NULL;
    while (!found && (entry = readdir(directory))) {

        if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
            continue;
        }

        char pathname[NAME_MAX + 1];   /* should always be big enough */
        sprintf( pathname, "%s/%s", INPUT_PATH, entry->d_name );
        qDebug("setupTouchScreen:: Path name: %s",  entry->d_name);
        int fd = open(pathname, O_RDONLY);

        if (fd == NULL) {
            puts ("setupTouchScreen:: Could not open device file - are you running as root");
        }
        else
        {

            char name[256] = "Unknown";
            ioctl (fd, EVIOCGNAME(sizeof(name)), name);
            qDebug("setupTouchScreen:: Input device name: %s", name);
            if(strcmp(name, DEVICE_NAME ) != 0 ) {
                qDebug("setupTouchScreen:: This is not the event file of the touchscreen: %s. Value is: %s", DEVICE_NAME, name);

            } else {
                qDebug("setupTouchScreen:: Found input file!");
                found = true;

                struct input_absinfo absval;

                // Read the ioctl and display the current values
                qDebug("setupTouchScreen:: Writing event struct ABS_X");
                ioctl(fd, EVIOCGABS(ABS_X), &absval);

                // check if a write is wanted - and do it

                absval.minimum = X_MIN;
                absval.maximum = X_MAX;

                ioctl(fd, EVIOCSABS(ABS_X), &absval);

                /////////////////
                qDebug("setupTouchScreen:: Writing event struct ABS_Y");
                ioctl(fd, EVIOCGABS(ABS_Y), &absval);

                absval.minimum = Y_MIN;
                absval.maximum = Y_MAX;

                ioctl(fd, EVIOCSABS(ABS_Y), &absval);

            }
        }
        close(fd);

    }
    closedir(directory);
    if(!found)
    {
        qDebug("setupTouchScreen:: Could not find device file for device %s", DEVICE_NAME);
        return -1;
    }
    qDebug("setupTouchScreen:: Success!");
    return 0;
}