我有一个Qt项目在icoremx6solo和linux上运行。我已经设置了图形并运行了代码,但我无法处理触摸输入。使用启用输入日志记录
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;
}
查看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 %dn", absnumber);
printf ("Value : %dn", absval.value);
printf ("Minimum : %dn", absval.minimum);
printf ("Maximum : %dn", absval.maximum);
printf ("Fuzz : %dn", absval.fuzz);
printf ("Flat : %dn", absval.flat);
// printf ("Resolution : %dn", 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);