Qt 5.4带有Tslib的Linux触摸屏输入在Raspberry Pi上无法使用LinuxFB QPA平台插件

时间:2015-03-05 02:27:35

标签: linux qt touch raspberry-pi qt5

我为我的Raspberry Pi买了一台Tontec 2.4英寸触摸屏(http://elinux.org/MZTX-PI-EXT)。触摸屏控制器需要" tsc2007.ko"和" tsp_raspi.ko"内核模块,如elinux帖子中所述。 tsc2007.ko模块位于Raspbian内核树中,但可以在此处找到tsp_raspi.ko:https://github.com/osandov/raspi/tree/master/tsc2007

我已经为这些模块交叉编译了一个新的内核,并且它们加载正常并在Raspbian中创建/ dev / input / event0设备。如果我'evtest'那个设备和触摸屏幕,我得到输出,所以我知道事件是在Linux中提供的:

pi@raspberry /dev/input $ evtest
Available devices:
/dev/input/event0:  TSC2007 Touchscreen
Select the device event number [0-0]: 0
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
Input device name: "TSC2007 Touchscreen"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 330 (BTN_TOUCH)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value   1922
      Min        0
      Max     4095
      Fuzz      64
    Event code 1 (ABS_Y)
      Value   2221
      Min        0
      Max     4095
      Fuzz      64
    Event code 24 (ABS_PRESSURE)
      Value      0
      Min        0
      Max     4095
      Fuzz      64
Properties:
Testing ... (interrupt to exit)
Event: time 1425521704.199489, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 1425521704.199489, type 3 (EV_ABS), code 1 (ABS_Y), value 2085
Event: time 1425521704.199489, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 538
Event: time 1425521704.199489, -------------- SYN_REPORT ------------
Event: time 1425521704.209174, type 3 (EV_ABS), code 0 (ABS_X), value 1455
...

我安装了tslib并运行了一个快速的ts_calibrate。当我触摸屏幕时,我还确保ts_test吐出数据。

我在Qt5中为tslib支持的/ etc / profile添加了以下环境变量:

## For Qt5 Touchscreen Support
export QT_DEBUG_PLUGINS=1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/arm-linux-gnueabihf/
export QT_PLUGIN_PATH=/usr/lib/plugins
export QT_QPA_FONTDIR=/usr/lib/fonts
export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/plugins/platforms
export QT_QPA_PLATFORM=linuxfb
export QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event0
export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event0
export TSLIB_TSEVENTTYPE='INPUT'
export TSLIB_CALIBFILE='/etc/pointercal'
export TSLIB_CONFFILE='/etc/ts.conf'
export TSLIB_CONSOLEDEVICE='none'
export TSLIB_FBDEVICE='/dev/fb0'
export TSLIB_PLUGINDIR='/usr/lib/ts'
export TSLIB_TSDEVICE='/dev/input/event0'

我阅读了Qt5文档以及如何在我的应用中获取触摸事件。我有一个主Widget并在构造函数中设置适当的标志:

MainWidget::MainWidget(QLabel *parent)
    : QLabel(parent)
{

    qDebug() << "Setting WA_AcceptTouchEvents on MainWidget...";

    // Accept touch events
    setAttribute(Qt::WA_AcceptTouchEvents);
    setAttribute(Qt::WA_StaticContents);

}

我设置了一个事件过滤器来尝试捕捉触摸事件:

bool MainWidget::eventFilter( QObject* target, QEvent* e )
{

    qDebug() << "Event Type: " << e->type();

    return false;

    return QLabel::eventFilter(target, e);
}

我像这样启动我的应用程序:

  
    

myapp -platform linuxfb:fb = / dev / fb0 -plugin tslib:/ dev / input / event0

  

我还在Qt的qtslib.cpp源代码中取消注释了一个printf:

void QTsLibMouseHandler::readMouseData()
{
    ts_sample sample;

    while (get_sample(m_dev, &sample, m_rawMode)) {
        bool pressed = sample.pressure;
        int x = sample.x;
        int y = sample.y;

        // work around missing coordinates on mouse release
        if (sample.pressure == 0 && sample.x == 0 && sample.y == 0) {
            x = m_x;
            y = m_y;
        }

        if (!m_rawMode) {
            //filtering: ignore movements of 2 pixels or less
            int dx = x - m_x;
            int dy = y - m_y;
            if (dx*dx <= 4 && dy*dy <= 4 && pressed == m_pressed)
                continue;
        }
        QPoint pos(x, y);

        //printf("handleMouseEvent %d %d %d %ld\n", m_x, m_y, pressed, sample.tv.tv_usec);

        QWindowSystemInterface::handleMouseEvent(0, pos, pos, pressed ? Qt::LeftButton : Qt::NoButton);

        m_x = x;
        m_y = y;
        m_pressed = pressed;
    }
}

当我启动我的Qt应用程序时,我看到插件正在加载正常(甚至显示正确的event0文件)。我还看到qt tslib插件在我触摸屏幕时正在接收触摸事件。问题是事件过滤器永远不会被调用!

以下是推出的应用:

Got keys from plugin meta data ("tslib", "tslibraw")
QFactoryLoader::QFactoryLoader() checking directory path "/home/pi/generic" ...
loaded library "/usr/lib/qt/plugins/generic/libqtslibplugin.so"
QTsLibMouseHandler "tslib" ""
QTsLibMouseHandler "tslib" "/dev/input/event0"
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/qt/plugins/styles" ...
QFactoryLoader::QFactoryLoader() checking directory path "/home/pi/styles" ...
Setting WA_AcceptTouchEvents on MainWidget...

-----------------------------------------
Waiting for data now...
-----------------------------------------

handleMouseEvent 0 0 1 751196
handleMouseEvent 0 0 1 751196
handleMouseEvent 1696 1615 1 771075
handleMouseEvent 1696 1615 1 771075
handleMouseEvent 1679 1622 1 781368
handleMouseEvent 1671 1638 1 781368
handleMouseEvent 1679 1622 1 781368
handleMouseEvent 1671 1638 1 781368
...

我发现了一些论坛帖子,人们在使用linuxfb平台插件时遇到触摸输入问题:

我已经尝试了所有他们的建议但仍然遇到问题 - 我的应用没有收到任何触摸事件,即使Qt tslib插件说它正在接收它们。

似乎tslib插件在将其收到的事件注入到我的应用程序的事件循环中时出现问题:

QWindowSystemInterface::handleMouseEvent(0, pos, pos, pressed ? Qt::LeftButton : Qt::NoButton);

我也尝试过Qt5.4触摸手指画示例并看到相同的行为 - 没有收到任何触摸事件。

我不知道从哪里开始。我非常感谢任何帮助解决这个问题。谢谢!

更新:

我更改了事件过滤器,所以看起来像这样:

bool MainWidget::eventFilter(QObject *obj, QEvent *event)
{

    qDebug() << "Event received" << obj->metaObject()->className() <<  event->type();
    switch (event->type()) {
        case QEvent::TouchBegin:
            qDebug() << "TouchBegin";
        case QEvent::TouchUpdate:
            qDebug() << "TouchUpdate";
        case QEvent::TouchEnd:
            qDebug() << "TouchEnd";
        {

            //        QTouchEvent *touch = static_cast<QTouchEvent *>(event);
            //        QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
            //        foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
            //            switch (touchPoint.state()) {
            //            case Qt::TouchPointStationary:
            //                // don't do anything if this touch point hasn't moved
            //                continue;
            //            default:
            //                {
            //                }
            //                break;
            //            }
            //        }
            //        break;
        }
        //default:
            //return QLabel::event(event);
    }
    //return true;

}

现在我可以看到&#39;套接字通知器&#39;每当我触摸屏幕时,事件就与Qt Tslib Plugin的打印混合在一起。关于为什么事件类型50但没有触摸事件的任何想法?

Event received QSocketNotifier 50
handleMouseEvent 2702 2618 0 557715
Event received QSocketNotifier 50
handleMouseEvent 2698 2612 1 547758
Event received QSocketNotifier 50
handleMouseEvent 2706 2802 1 759928
Event received QSocketNotifier 50
Event received QSocketNotifier 50

更新#2:

我只安装了事件过滤器以尝试捕获任何事件。我在Qt5中不确定将事件类型50(QSocketNotifier)转换为QTouch *或QMouse *事件。

以下是一些更多信息:

  • 当我运行evtest时,我看到屏幕分辨率很大(~2500 x ~2500),实际屏幕为320x240。我试过换了 / dev / fb0 /boot/config.txt中的framebuffer大小为320x240和 重新启动。但evtest和ts_calibrate步骤仍显示巨大 分辨率。
  • 由于分辨率很高,我尝试制作主要的小部件 10000x10000,看看我是否会得到触摸或鼠标事件 - 但我 仍然只得到QSocketNotifier
  • 然后我试图强制tslib插件始终注入事件 屏幕位置X = 50 Y = 50,但我仍然只得到事件类型50 QSocketNotifier中。

1 个答案:

答案 0 :(得分:0)

通过确保在RasbperryPi上安装tslib插件来解决问题。

TSLIB_PLUGINDIR=/usr/lib/ts

Pi上没有目录/ usr / lib / ts。