我有一个在Linux的icoremx6solo上运行的Qt项目。 我已经设置好图形并运行代码,但是我无法处理触摸输入。 使用
启用输入日志记录export QT_LOGGING_RULES =“ qt.qpa.input = true”
我发现没有设置坐标ar,我认为这是主要问题:
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属性运行可执行文件,但输出是相同的。
那么,如何解决触摸屏正在运行的问题?
答案 0 :(得分:0)
查看QT的来源(qevdevtouchhandler.cpp),可直接从设备ioctl获得校准值(最小,最大,压力…)。
在Qt中似乎没有办法更改这些值。
看我控制器的内核源代码(Atmel spi上的ADS7843),似乎没有办法改变用户空间(/ proc,/ sys)中的值。
以下代码片段似乎可以完成任务–读取和写入校准值:
// 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);
答案 1 :(得分:0)
谢谢你! 根据您的回答,我设法让我的 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;
}