Qt embedded, multitouch and tslib with multitouch support



  • Hello,

    I am interesting in qt embedded with gestures.
    At this moment, I use qt 4.8.4 with tslib using a multitouch screen configurate as single touch an it works fine.

    Now I replace my old tslib library with a new one that it has a multitouch support.
    Using ts_test with debug, library detect all points with your ID and position.

    But now, I dont known how use this in Qt.
    All touch examples only use one finger. If I use two fingers, only one touch is active.

    Has anybody any experience using multitouch with Qt embedded??

    Bestregards


  • Lifetime Qt Champion

    Hi,

    Did you took a look at the "Touch Input Examples" in Qt's documentation ? The Touch Knobs Example might be a starting point

    Hope it helps



  • Thank you.

    And yes, before post I have read all examples about touch.

    @
    QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);

        if (touchEvent->touchPoints().count() == 2) {
            const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first();
            const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last();
    
            QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos());
            QLineF line2(touchPoint1.scenePos(), touchPoint2.scenePos());
    
            rotate(line2.angleTo(line1));
        }
    

    @

    This example need two points to work and I dont know how to send to Qt touch points from TSLIB.

    Perhaps, TSLIB is not de correct plugin and I need to use other different, like LinuxInput or LinuxTP.

    In my embedded system using evtest tell me that my device support the follow ev.codes:
    MT_SLOT
    MT_POSITION_X
    MT_POSITION_Y
    MT_TRANCKING_ID

    Any advice or suggest?


  • Lifetime Qt Champion

    AFAIK tslib is the right plugin to use. However, did you set the Qt::WA_AcceptTouchEvents flag on your widgets ?

    You have a more thorough explication about that in the QTouchEvent documentation



  • And sorry but after read code I think that tslib is not the correct way.
    This is a portion of code of qmousetslib_qws.cpp

    @bool QWSTslibMouseHandlerPrivate::get_sample(struct ts_sample *sample)
    {
    if (!calibrated)
    return (ts_read_raw(dev, sample, 1) == 1);

    return (ts_read(dev, sample, 1) == 1);
    

    }

    int StackCnt;
    void QWSTslibMouseHandlerPrivate::readMouseData()
    {
    if (!qt_screen)
    return;

    for(;;) {
        struct ts_sample sample = lastSample;
        bool pressed = wasPressed;
    
        // Fast return if there's no events.
        if (!get_sample(&sample))
            return;
    
        pressed = (sample.pressure > 0);
    
        // Only return last sample unless there's a press/release event.
        while (pressed == wasPressed) {
            if (!get_sample(&sample))
                break;
            pressed = (sample.pressure > 0);
        }
    
        // work around missing coordinates on mouse release in raw mode
        if (!calibrated && !pressed && sample.x == 0 && sample.y == 0) {
            sample.x = lastSample.x;
            sample.y = lastSample.y;
        }
    
        int dx = sample.x - lastSample.x;
        int dy = sample.y - lastSample.y;
    
        // Remove small movements in oppsite direction
        if (dx * lastdx < 0 && qAbs(dx) < jitter_limit) {
            sample.x = lastSample.x;
            dx = 0;
        }
        if (dy * lastdy < 0 && qAbs(dy) < jitter_limit) {
            sample.y = lastSample.y;
            dy = 0;
        }
    
        if (wasPressed == pressed && dx == 0 && dy == 0)
            return;
    

    #ifdef TSLIBMOUSEHANDLER_DEBUG
    qDebug() << "last" << QPoint(lastSample.x, lastSample.y)
    << "curr" << QPoint(sample.x, sample.y)
    << "dx,dy" << QPoint(dx, dy)
    << "ddx,ddy" << QPoint(dxlastdx, dylastdy)
    << "pressed" << wasPressed << pressed;
    #endif

        lastSample = sample;
        wasPressed = pressed;
        if (dx != 0)
            lastdx = dx;
        if (dy != 0)
            lastdy = dy;
    
        const QPoint p(sample.x, sample.y);
        if (calibrated) {
            // tslib should do all the translation and filtering, so we send a
            // "raw" mouse event
            handler->QWSMouseHandler::mouseChanged(p, pressed);
        } else {
            handler->sendFiltered(p, pressed);
        }
    }
    

    }@

    I could read only one sample and it can not handle slots and trancking_id, then, in my opinion, it is impossible to handle a multitouch events with this code.

    If I want to touch two buttons, I think I need to handle MT_SLOT and MT_TRACKING_ID to determinate how many fingers are pressed touch screen.

    Are you sure that is it possible to have more than one finger and pressed two buttons at the same time??

    Best regards.


  • Lifetime Qt Champion

    Sorry, my bad, I've forgot that it required a little bit of work.

    See this "thread":http://qt-project.org/forums/viewthread/5052 and this "article":http://www.ptrackapp.com/apclassys-notes/embedded-linux-multitouch/ for more information about how to do it



  • Bufffff,

    thank you very much but a lot of work.
    Finally, i am going to create my own mouse handler plugin.

    I only have a bit problem.
    I dont known how to send a touchevevnt from plugin. Do you known?

    Best regards.


  • Lifetime Qt Champion

    AFAIK, you would need to call qt_translateRawTouchEvent at some point



  • [quote author="SGaist" date="1414704241"]AFAIK, you would need to call qt_translateRawTouchEvent at some point[/quote]

    Hello,

    Ok, but I have still a bit problem.

    @qt_translateRawTouchEvent(QWidget *window,
    QTouchEvent::DeviceType deviceType,
    const QListQTouchEvent::TouchPoint &touchPoints);@

    This function need pointer to widget, but in my new mouse plugin I dont known the pointer to widget.

    Is it possible to setup widget as NULL and qt_translateRawTouchEvent send touch events to upper layer???

    Best regards.


  • Lifetime Qt Champion

    I'd try with QApplication::widgetAt


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.