linux - 在嵌入式 qt 项目上校准和配置 evdevtouch

标签 linux qt embedded touchscreen evdev

我有一个 Qt 项目在带有 Linux 的 icoremx6solo 上运行。 我已经设置了图形并运行了代码,但我无法处理触摸输入。 启用输入日志记录

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

我发现坐标没有设置,我认为这是主要问题:

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

但我找不到校准 evdevtouch 的方法。

在执行 ts_calibrate 命令后,我尝试使用 -plugin tslib 属性运行可执行文件,但输出是相同的。

那么,我该如何解决正在运行的触摸屏问题?

最佳答案

谢谢 ianeperson! 根据您的回答,我设法让我的 xpt2046 5 英寸触摸屏与 Qt 一起工作。 我的代码:

#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;
}

关于linux - 在嵌入式 qt 项目上校准和配置 evdevtouch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53299595/

相关文章:

Linux 项目 : bash script to archive and remove files

c++ - 在 Qt 中打印文本编辑

关闭控制台时 C++/Qt 运行函数

c++ - 如何清除串行屏幕?

linux - 在 Mercurial 存储库中,将工作文件夹更改为子文件夹

linux - linux服务器上的服务器空间

linux - 获取 Linux 内核中的网络设备列表

c++ - Qt/C++ CLI 文本到 QLabel

c - 用于嵌入式设备的良好串行通信协议(protocol)/堆栈?

c - 嵌入式:大多数 CRT 启动代码不使用 memcpy/memset——为什么?