免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 8911 | 回复: 23
打印 上一主题 下一主题

qtopia core4移植问题---触摸屏位置不准 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-05 19:42 |只看该作者 |倒序浏览
大家好,贴子有点长,请大家耐着性着看完一下,感激不尽
小弟最近在做qtopia core-4.3.3的移植.起初没有修改过它的源码哈,编译,安装都顺利通过,通过NFS启动系统后.执行那些示例程序,屏幕有反应,点击触摸屏,鼠标也会有反应,但是鼠标的位置却与点击位置出入很大,甚至是在相反的方向...后来我按照网上所说的方法对源码做了修改,即在qmouselinuxtp_qws.h加入
#define QT_QWS_IPAQ
#define QT_QWS_IPAQ_RAW
并修改原来的设备文件dev/h3600_tsraw为/dev/input/ts0,重新编译安装后,但问题依然....请问这是为什么呢?这个问题应该怎样解决呢,谢谢!
我的板子是s3c2440.
我的配置选项:
./configure  -v -little-endian -embedded arm  
我的qmouselinuxtp_qws.cpp文件:
/****************************************************************************
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt ... g/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** In addition, as a special exception, Trolltech gives you certain
** additional rights. These rights are described in the Trolltech GPL
** Exception version 1.0, which can be found at
** http://www.trolltech.com/products/qt/gplexception/ and in the file
** GPL_EXCEPTION.txt in this package.
**
** In addition, as a special exception, Trolltech, as the sole copyright
** holder for Qt Designer, grants users of the Qt/Eclipse Integration
** plug-in the right for the Qt/Eclipse Integration to link to
** functionality provided by Qt Designer and its related libraries.
**
** Trolltech reserves all rights not expressly granted herein.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#include "qmouselinuxtp_qws.h"

#ifndef QT_NO_QWS_MOUSE_LINUXTP
#include "qwindowsystem_qws.h"
#include "qsocketnotifier.h"
#include "qtimer.h"
#include "qapplication.h"
#include "qscreen_qws.h"

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>

#if defined(QT_QWS_IPAQ)
#define QT_QWS_IPAQ_RAW
#define QT_QWS_SCREEN_COORDINATES
typedef struct {
        unsigned short pressure;
        unsigned short x;
        unsigned short y;
        unsigned short pad;
} TS_EVENT;
#elif defined(QT_QWS_EBX)
#define QT_QWS_EBX_RAW
#define QT_QWS_SCREEN_COORDINATES
#ifndef QT_QWS_SHARP
  typedef struct {
        unsigned short pressure;
        unsigned short x;
        unsigned short y;
        unsigned short pad;
  } TS_EVENT;
#else
  typedef struct {
       long y;
       long x;
       long pressure;
       long long millisecs;
  } TS_EVENT;
  #define QT_QWS_TP_SAMPLE_SIZE 10
  #define QT_QWS_TP_MINIMUM_SAMPLES 4
  #define QT_QWS_TP_PRESSURE_THRESHOLD 500
  #define QT_QWS_TP_MOVE_LIMIT 50
  #define QT_QWS_TP_JITTER_LIMIT 2
#endif
#else // not IPAQ, not SHARP
  typedef struct {
    unsigned short pressure;
    unsigned short x;
    unsigned short y;
    unsigned short pad;
  } TS_EVENT;
#endif

#ifndef QT_QWS_TP_SAMPLE_SIZE
#define QT_QWS_TP_SAMPLE_SIZE 5
#endif

#ifndef QT_QWS_TP_MINIMUM_SAMPLES
#define QT_QWS_TP_MINIMUM_SAMPLES 5
#endif

#ifndef QT_QWS_TP_PRESSURE_THRESHOLD
#define QT_QWS_TP_PRESSURE_THRESHOLD 1
#endif

#ifndef QT_QWS_TP_MOVE_LIMIT
#define QT_QWS_TP_MOVE_LIMIT 100
#endif

#ifndef QT_QWS_TP_JITTER_LIMIT
#define QT_QWS_TP_JITTER_LIMIT 2
#endif

class QWSLinuxTPMouseHandlerPrivate : public QObject
{
    Q_OBJECT
public:
    QWSLinuxTPMouseHandlerPrivate(QWSLinuxTPMouseHandler *h, const QString &);
    ~QWSLinuxTPMouseHandlerPrivate();

    void suspend();
    void resume();
private:
    static const int mouseBufSize = 2048;
    int mouseFD;
    QPoint oldmouse;
    QPoint oldTotalMousePos;
    bool waspressed;
    QPolygon samples;
    int currSample;
    int lastSample;
    int numSamples;
    int skipCount;
    int mouseIdx;
    uchar mouseBuf[mouseBufSize];
    QWSLinuxTPMouseHandler *handler;
    QSocketNotifier *mouseNotifier;

private slots:
    void readMouseData();
};

QWSLinuxTPMouseHandler::QWSLinuxTPMouseHandler(const QString &driver, const QString &device)
    : QWSCalibratedMouseHandler(driver, device)
{
    d = new QWSLinuxTPMouseHandlerPrivate(this, device);
}

QWSLinuxTPMouseHandler::~QWSLinuxTPMouseHandler()
{
    delete d;
}

void QWSLinuxTPMouseHandler::suspend()
{
    d->suspend();
}

void QWSLinuxTPMouseHandler::resume()
{
    d->resume();
}

QWSLinuxTPMouseHandlerPrivate::QWSLinuxTPMouseHandlerPrivate(QWSLinuxTPMouseHandler *h,
        const QString &device)
    : samples(QT_QWS_TP_SAMPLE_SIZE), currSample(0), lastSample(0),
    numSamples(0), skipCount(0), handler(h)
{
    QString mousedev;
    if (device.isEmpty()) {
#if defined(QT_QWS_IPAQ)
# ifdef QT_QWS_IPAQ_RAW
        mousedev = QLatin1String("/dev/h3600_tsraw");
# else
        mousedev = QLatin1String("/dev/h3600_ts");
# endif
#else
        mousedev = QLatin1String("/dev/ts");
#endif
    } else {
        mousedev = device;
    }
    if ((mouseFD = open(mousedev.toLatin1().constData(), O_RDONLY | O_NDELAY)) < 0) {
        qWarning("Cannot open %s (%s)", qPrintable(mousedev), strerror(errno));
        return;
    }

    mouseNotifier = new QSocketNotifier(mouseFD, QSocketNotifier::Read,
                                         this);
    connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
    waspressed=false;
    mouseIdx = 0;
}

QWSLinuxTPMouseHandlerPrivate::~QWSLinuxTPMouseHandlerPrivate()
{
    if (mouseFD >= 0)
        close(mouseFD);
}

void QWSLinuxTPMouseHandlerPrivate::suspend()
{
    if (mouseNotifier)
        mouseNotifier->setEnabled(false);
}

void QWSLinuxTPMouseHandlerPrivate::resume()
{
    mouseIdx=0;
    currSample=0;
    lastSample=0;
    numSamples=0;
    skipCount=0;
    if (mouseNotifier)
        mouseNotifier->setEnabled(true);
}


void QWSLinuxTPMouseHandlerPrivate::readMouseData()
{
    if(!qt_screen)
        return;

    int n;
    do {
        n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx);
        if (n > 0)
            mouseIdx += n;
    } while (n > 0 && mouseIdx < mouseBufSize);

    //qDebug("readMouseData()");

    TS_EVENT *data;
    int idx = 0;

    // perhaps we shouldn't be reading EVERY SAMPLE.
    while (mouseIdx-idx >= (int)sizeof(TS_EVENT)) {
        uchar *mb = mouseBuf+idx;
        data = (TS_EVENT *) mb;

        if(data->pressure >= QT_QWS_TP_PRESSURE_THRESHOLD) {
#ifdef QT_QWS_SHARP
            samples[currSample] = QPoint(1000 - data->x, data->y);
#else
            samples[currSample] = QPoint(data->x, data->y);
#endif
            numSamples++;
            if (numSamples >= QT_QWS_TP_MINIMUM_SAMPLES) {
                int sampleCount = qMin(numSamples + 1,samples.count());

                // average the rest
                QPoint mousePos = QPoint(0, 0);
                QPoint totalMousePos = oldTotalMousePos;
                totalMousePos += samples[currSample];
                if(numSamples >= samples.count())
                    totalMousePos -= samples[lastSample];

                mousePos = totalMousePos / (sampleCount - 1);
#if defined(QT_QWS_SCREEN_COORDINATES)
                mousePos = handler->transform(mousePos);
#endif
                if(!waspressed)
                    oldmouse = mousePos;
                QPoint dp = mousePos - oldmouse;
                int dxSqr = dp.x() * dp.x();
                int dySqr = dp.y() * dp.y();
                if (dxSqr + dySqr < (QT_QWS_TP_MOVE_LIMIT * QT_QWS_TP_MOVE_LIMIT)) {
                    if (waspressed) {
                        if ((dxSqr + dySqr > (QT_QWS_TP_JITTER_LIMIT * QT_QWS_TP_JITTER_LIMIT)) || skipCount > 2) {
                            handler->mouseChanged(mousePos,Qt::LeftButton);
                            oldmouse = mousePos;
                            skipCount = 0;
                        } else {
                            skipCount++;
                        }
                    } else {
                        handler->mouseChanged(mousePos,Qt::LeftButton);
                        oldmouse=mousePos;
                        waspressed=true;
                    }

                    // save recuring information
                    currSample++;
                    if (numSamples >= samples.count())
                        lastSample++;
                    oldTotalMousePos = totalMousePos;
                } else {
                    numSamples--; // don't use this sample, it was bad.
                }
            } else {
                // build up the average
                oldTotalMousePos += samples[currSample];
                currSample++;
            }
            if (currSample >= samples.count())
                currSample = 0;
            if (lastSample >= samples.count())
                lastSample = 0;
        } else {
            currSample = 0;
            lastSample = 0;
            numSamples = 0;
            skipCount = 0;
            oldTotalMousePos = QPoint(0,0);
            if (waspressed) {
                handler->mouseChanged(oldmouse,0);
                oldmouse = QPoint(-100, -100);
                waspressed=false;
            }
        }
        idx += sizeof(TS_EVENT);
    }

    int surplus = mouseIdx - idx;
    for (int i = 0; i < surplus; i++)
        mouseBuf = mouseBuf[idx+i];
    mouseIdx = surplus;
}

#include "qmouselinuxtp_qws.moc"
#endif //QT_NO_QWS_MOUSE_LINUXTP


[ 本帖最后由 lpzgbd 于 2008-3-5 21:16 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-03-05 20:10 |只看该作者
楼主的硬件没有问题吧

论坛徽章:
0
3 [报告]
发表于 2008-03-05 21:19 |只看该作者

回复 #2 bitmilong 的帖子

硬件是没有问题的,这点可以确定。因为用厂家提供的qt/e启动系统,很正常。。

论坛徽章:
0
4 [报告]
发表于 2008-03-06 13:12 |只看该作者
你从上层把低层的坐标读出来,看看2个方向是否都有明显的线性的变化,有的话,自己写段小程序转化一下就好了  。

论坛徽章:
0
5 [报告]
发表于 2008-03-06 13:28 |只看该作者

回复 #4 jojolin 的帖子

谢谢 ,这个方法我会试试的。。
但是,还有没有其它什么好方法呢

论坛徽章:
0
6 [报告]
发表于 2008-03-07 11:31 |只看该作者
用tslib这个库,qt好像本身带的

论坛徽章:
0
7 [报告]
发表于 2008-03-07 20:47 |只看该作者

回复 #6 zozowit 的帖子

谢谢 ,我试试。。。。。。。

论坛徽章:
0
8 [报告]
发表于 2008-03-11 11:44 |只看该作者
试了一下,还是不行.
安装tslib库后,运行ts_calibrate和ts_test等测试程序,都没问题,点击位置和鼠标位置相符
但是执行qtopia core的示例程序却发现点击位置和鼠标位置仍然偏差很大,是反的..
应该怎么解决呢???谢谢

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
9 [报告]
发表于 2008-03-11 12:02 |只看该作者
是不是驱动的问题呢????

论坛徽章:
0
10 [报告]
发表于 2008-03-12 09:16 |只看该作者

回复 #9 T-bagwell 的帖子

这个不是太清楚.
不过运行ts_calibrate和ts_test没问题,说明驱动应该没问题.
并且我在qmouselinuxtp_qws.cpp和qmousetslib_qws.cpp中用qwaring()函数加入了一些打印当前点的坐标的语句,可这些语句并未执行..
而且前面的打开的设备为/dev/input/ts0,但我用strace跟踪程序,发现它打开的是/dev/input/mice.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP