问题:重新插拔设备,需要软件重启才能接收到触摸事件
愿因:是因为qt程序的tslib库的操作逻辑是在构造函数里面连接一次usb触摸设备,具体看如下文件内容:
/home/forlinx/OK113i-linux-sdk/buildroot/buildroot-201902/dl/qt5base/qtbase/src/platformsupport/input/tslib/qtslib.cpp;
所以重新插拔usb后,qt程序并没有重新连接usb触摸设备,导致没有触摸数据接收;
解决方案:
参考:https://blog.csdn.net/alone4together/article/details/115269753
参考方案中的代码需要更改一下,完整的qtslib.cpp更改内容如下:
QTsLibMouseHandler::QTsLibMouseHandler(const QString &key,
const QString &specification,
QObject *parent)
: QObject(parent),
m_notify(0), m_x(0), m_y(0), m_pressed(0), m_rawMode(false)
{
m_dev=0;
qCDebug(qLcTsLib) << "Initializing tslib plugin" << key << specification;
setObjectName(QLatin1String("TSLib Mouse Handler"));
...
...
else
{
qErrnoWarning(errno, "tslib: Cannot open input device %s", device.constData());
}
QFileSystemWatcher *m_fileWatcher = new QFileSystemWatcher(this);
// QString dev_=device;
m_fileWatcher->addPath(QLatin1String("/dev/input/")); // "dev/input/"
connect(m_fileWatcher, &QFileSystemWatcher::directoryChanged, this, &QTsLibMouseHandler::handleHotPlugWatch);
}
void QTsLibMouseHandler::handleHotPlugWatch(const QString &path)
{
QByteArray device = qgetenv("TSLIB_TSDEVICE");
QFile file(QString::fromLocal8Bit(device)); // shoud be TSLIB_TSDEVICE
qCDebug(qLcTsLib) << path << "is changing";
if (file.exists())
{
qCDebug(qLcTsLib) << "tslib device disconnected .., try connecting ...";
disconnect(m_notify, 0, 0, 0);
if (m_notify){
delete m_notify;
m_notify = 0;
}
// QByteArray device = qgetenv("TSLIB_TSDEVICE");
m_dev = ts_open(device.constData(), 1);
if (!m_dev)
{
qCDebug(qLcTsLib) << " touchscreen doesn't exist";
qErrnoWarning(errno, "ts_open() failed");
}
else
{
if (ts_config(m_dev)){
qErrnoWarning(errno, "ts_config() failed");
}
int fd = ts_fd(m_dev);
if (fd >= 0)
{
qCDebug(qLcTsLib) << "tslib device is" << device;
m_notify = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(m_notify, &QSocketNotifier::activated, this, &QTsLibMouseHandler::readMouseData);
}
else
{
qErrnoWarning(errno, "tslib: Cannot open input device %s", device.constData());
}
return;
}
qCDebug(qLcTsLib) << path << "is added";
}
else
{
if (m_dev){
ts_close(m_dev);
m_dev = 0;
}
qCDebug(qLcTsLib) << path << "is removed";
}
}
改完qtslib.cpp需要编译buildroot,编译后的qtslib.cpp会在如下路径:
/home/OK113i-linux-sdk/out/t113_i/ok113i/longan/buildroot/build/qt5base-5.12.5/src/platformsupport/input/tslib/qtslib.cpp
需要注意单独编译的buildroot后,还需要全编译,才会将根文件系统镜像rootfs.ext2更新到系统镜像;