Results 1 to 3 of 3

Thread: Qt 5.4 Linux Touchscreen Input with Tslib on Raspberry Pi failing with LinuxFB QPA Pl

  1. #1
    Join Date
    Mar 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Qt 5.4 Linux Touchscreen Input with Tslib on Raspberry Pi failing with LinuxFB QPA Pl

    I bought a Tontec 2.4 Inch Touchscreen ( http://elinux.org/MZTX-PI-EXT ) for my Raspberry Pi. The touchscreen controller requires the "tsc2007.ko" and "tsp_raspi.ko" kernel modules as described in the elinux post. The tsc2007.ko module is in the Raspbian Kernel tree but the tsp_raspi.ko can be found here: https://github.com/osandov/raspi/tree/master/tsc2007.

    I've cross compiled a new Kernel for the Pi with those modules and they load fine and create a /dev/input/event0 device in Raspbian. If I 'evtest' that device and touch the screen, I get output so I know the events are being delivered in Linux:

    Qt Code:
    1. pi@raspberry /dev/input $ evtest
    2. Available devices:
    3. /dev/input/event0: TSC2007 Touchscreen
    4. Select the device event number [0-0]: 0
    5. Input driver version is 1.0.1
    6. Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
    7. Input device name: "TSC2007 Touchscreen"
    8. Supported events:
    9. Event type 0 (EV_SYN)
    10. Event type 1 (EV_KEY)
    11. Event code 330 (BTN_TOUCH)
    12. Event type 3 (EV_ABS)
    13. Event code 0 (ABS_X)
    14. Value 1922
    15. Min 0
    16. Max 4095
    17. Fuzz 64
    18. Event code 1 (ABS_Y)
    19. Value 2221
    20. Min 0
    21. Max 4095
    22. Fuzz 64
    23. Event code 24 (ABS_PRESSURE)
    24. Value 0
    25. Min 0
    26. Max 4095
    27. Fuzz 64
    28. Properties:
    29. Testing ... (interrupt to exit)
    30. Event: time 1425521704.199489, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
    31. Event: time 1425521704.199489, type 3 (EV_ABS), code 1 (ABS_Y), value 2085
    32. Event: time 1425521704.199489, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 538
    33. Event: time 1425521704.199489, -------------- SYN_REPORT ------------
    34. Event: time 1425521704.209174, type 3 (EV_ABS), code 0 (ABS_X), value 1455
    35. ...
    To copy to clipboard, switch view to plain text mode 
    I installed tslib and ran a quick ts_calibrate. I also made sure that ts_test spit out data when I touched the screen.

    I added the following environment variables to /etc/profile for tslib support in Qt5:

    Qt Code:
    1. ## For Qt5 Touchscreen Support
    2. export QT_DEBUG_PLUGINS=1
    3. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/arm-linux-gnueabihf/
    4. export QT_PLUGIN_PATH=/usr/lib/plugins
    5. export QT_QPA_FONTDIR=/usr/lib/fonts
    6. export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/plugins/platforms
    7. export QT_QPA_PLATFORM=linuxfb
    8. export QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event0
    9. export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event0
    10. export TSLIB_TSEVENTTYPE='INPUT'
    11. export TSLIB_CALIBFILE='/etc/pointercal'
    12. export TSLIB_CONFFILE='/etc/ts.conf'
    13. export TSLIB_CONSOLEDEVICE='none'
    14. export TSLIB_FBDEVICE='/dev/fb0'
    15. export TSLIB_PLUGINDIR='/usr/lib/ts'
    16. export TSLIB_TSDEVICE='/dev/input/event0'
    To copy to clipboard, switch view to plain text mode 

    I read up on the Qt5 docs and how to get touch events in my app. I have a main Widget and set the appropriate flags in the constructor:

    Qt Code:
    1. MainWidget::MainWidget(QLabel *parent)
    2. : QLabel(parent)
    3. {
    4.  
    5. qDebug() << "Setting WA_AcceptTouchEvents on MainWidget...";
    6.  
    7. // Accept touch events
    8. setAttribute(Qt::WA_AcceptTouchEvents);
    9. setAttribute(Qt::WA_StaticContents);
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    I setup an event filter to try to catch the touch events:

    Qt Code:
    1. bool MainWidget::eventFilter( QObject* target, QEvent* e )
    2. {
    3.  
    4. qDebug() << "Event Type: " << e->type();
    5.  
    6. return false;
    7.  
    8. return QLabel::eventFilter(target, e);
    9. }
    To copy to clipboard, switch view to plain text mode 

    I launch my app like this:

    Qt Code:
    1. >> myapp -platform linuxfb:fb=/dev/fb0 -plugin tslib:/dev/input/event0
    To copy to clipboard, switch view to plain text mode 

    I also uncommented a single printf in Qt's source code for the qtslib.cpp:

    Qt Code:
    1. void QTsLibMouseHandler::readMouseData()
    2. {
    3. ts_sample sample;
    4.  
    5. while (get_sample(m_dev, &sample, m_rawMode)) {
    6. bool pressed = sample.pressure;
    7. int x = sample.x;
    8. int y = sample.y;
    9.  
    10. // work around missing coordinates on mouse release
    11. if (sample.pressure == 0 && sample.x == 0 && sample.y == 0) {
    12. x = m_x;
    13. y = m_y;
    14. }
    15.  
    16. if (!m_rawMode) {
    17. //filtering: ignore movements of 2 pixels or less
    18. int dx = x - m_x;
    19. int dy = y - m_y;
    20. if (dx*dx <= 4 && dy*dy <= 4 && pressed == m_pressed)
    21. continue;
    22. }
    23. QPoint pos(x, y);
    24.  
    25. //printf("handleMouseEvent %d %d %d %ld\n", m_x, m_y, pressed, sample.tv.tv_usec);
    26.  
    27. QWindowSystemInterface::handleMouseEvent(0, pos, pos, pressed ? Qt::LeftButton : Qt::NoButton);
    28.  
    29. m_x = x;
    30. m_y = y;
    31. m_pressed = pressed;
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    When I launch my Qt app I see the plugins are loading OK ( even shows the correct event0 file ). I also see that the qt tslib plugin is receiving touch events when I touch the screen. The problem is that the event filter is NEVER called!

    Here is the app being launched:

    Qt Code:
    1. Got keys from plugin meta data ("tslib", "tslibraw")
    2. QFactoryLoader::QFactoryLoader() checking directory path "/home/pi/generic" ...
    3. loaded library "/usr/lib/qt/plugins/generic/libqtslibplugin.so"
    4. QTsLibMouseHandler "tslib" ""
    5. QTsLibMouseHandler "tslib" "/dev/input/event0"
    6. QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/qt/plugins/styles" ...
    7. QFactoryLoader::QFactoryLoader() checking directory path "/home/pi/styles" ...
    8. Setting WA_AcceptTouchEvents on MainWidget...
    9.  
    10. -----------------------------------------
    11. Waiting for data now...
    12. -----------------------------------------
    13.  
    14. handleMouseEvent 0 0 1 751196
    15. handleMouseEvent 0 0 1 751196
    16. handleMouseEvent 1696 1615 1 771075
    17. handleMouseEvent 1696 1615 1 771075
    18. handleMouseEvent 1679 1622 1 781368
    19. handleMouseEvent 1671 1638 1 781368
    20. handleMouseEvent 1679 1622 1 781368
    21. handleMouseEvent 1671 1638 1 781368
    22. ...
    To copy to clipboard, switch view to plain text mode 

    I found a few forum posts where people are having problems with touch input with the linuxfb platform plugin:

    - http://comments.gmane.org/gmane.comp.lib.qt.user/5686

    - http://qt-project.org/forums/viewthread/35757

    - http://qt-project.org/forums/viewthread/36120/

    I've tried all their suggestions and still have the problem - no touch events are received by my app even though the Qt tslib plugin says it is receiving them.

    It seems that the tslib plugin is having problems injecting the event it receives into my app's event loop with this:

    Qt Code:
    1. QWindowSystemInterface::handleMouseEvent(0, pos, pos, pressed ? Qt::LeftButton : Qt::NoButton);
    To copy to clipboard, switch view to plain text mode 

    I also tried the Qt5.4 touch fingerpaint example and see the same behavior - no touch events are received.

    I'm not sure where to go from here. I would greatly appreciate any help solving this issue. Thanks!

    UPDATE:

    I changed my event filter so it looks like this:

    Qt Code:
    1. bool MainWidget::eventFilter(QObject *obj, QEvent *event)
    2. {
    3.  
    4. qDebug() << "Event received" << obj->metaObject()->className() << event->type();
    5. switch (event->type()) {
    6. case QEvent::TouchBegin:
    7. qDebug() << "TouchBegin";
    8. case QEvent::TouchUpdate:
    9. qDebug() << "TouchUpdate";
    10. case QEvent::TouchEnd:
    11. qDebug() << "TouchEnd";
    12. {
    13.  
    14. // QTouchEvent *touch = static_cast<QTouchEvent *>(event);
    15. // QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
    16. // foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
    17. // switch (touchPoint.state()) {
    18. // case Qt::TouchPointStationary:
    19. // // don't do anything if this touch point hasn't moved
    20. // continue;
    21. // default:
    22. // {
    23. // }
    24. // break;
    25. // }
    26. // }
    27. // break;
    28. }
    29. //default:
    30. //return QLabel::event(event);
    31. }
    32. //return true;
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 

    Now I can see 'socket notifier' events intermingled with Qt Tslib Plugin's prints whenever I touch the screen. Any ideas as to why Event Type 50 but no Touch Events?

    Qt Code:
    1. Event received QSocketNotifier 50
    2. handleMouseEvent 2702 2618 0 557715
    3. Event received QSocketNotifier 50
    4. handleMouseEvent 2698 2612 1 547758
    5. Event received QSocketNotifier 50
    6. handleMouseEvent 2706 2802 1 759928
    7. Event received QSocketNotifier 50
    8. Event received QSocketNotifier 50
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt 5.4 Linux Touchscreen Input with Tslib on Raspberry Pi failing with LinuxFB QP

    UPDATE #2:

    I installed the event filter only to try to catch any events. I'm not sure in Qt5 what translates an event type 50 ( QSocketNotifier ) to a QTouch* or QMouse* event.

    Here is some more information:

    - When I run evtest, I see that the screen resolution is huge ( ~2500 x
    ~2500 ) and the actual screen is 320x240. I tried changed the
    /dev/fb0 framebuffer size in /boot/config.txt to 320x240 and
    rebooted. But the evtest and ts_calibrate steps still show the huge
    resolution.
    - Because of the large resolution, I tried making my main widget
    10000x10000 to see if I would get a touch or mouse event - but I
    still only get the QSocketNotifier
    - I then tried to force the tslib plugin to always inject events at
    screen position X=50 Y=50, but I still only get the event type 50
    QSocketNotifier.

  3. #3
    Join Date
    Jul 2018
    Location
    Minneapolis, MN USA
    Posts
    7
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qt 5.4 Linux Touchscreen Input with Tslib on Raspberry Pi failing with LinuxFB QP

    Did you get this working, I am struggling with similar issues? Thanks!

Similar Threads

  1. Raspberry Pi + touchscreen
    By robal in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 24th March 2014, 13:08
  2. touchscreen tslib kernel event debugging qt application
    By sean_h in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 14th September 2012, 08:30
  3. Touchscreen and Driver Installed but tslib Cannot Calibrate
    By phil999 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 14th August 2012, 16:45
  4. qt tslib touchscreen y-axis reversed
    By gosk in forum Qt Programming
    Replies: 2
    Last Post: 6th September 2011, 17:19
  5. QTEmbedded tslib -> tsharc touchscreen
    By Honta in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 11th February 2009, 06:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.