移植tslib到qt-embedded-free-3.3.8
一、交叉编译tslib1.4。可以参考网上相关资料。
二、编译qt-x11-free-3.38,并把生成的bin目录下的uic文件拷贝到qt-embedded-free-3.3.8的bin目录下
三、交叉编译qt-embedded-free-3.3.8。
1. 配置好交叉编译的环境变量。
2. 添加tslib到Qt3.3.8的接口代码
①在src/embedded目录下添加qmousetslib_qws.h和qmousetslib_qws.cpp文件。
②修改src/embedded目录下的qt_embedded.pri文件。在该文件的186行处添加如下代码:
contains( mouse-drivers, tslib ) {
HEADERS +=$$EMBEDDED_H/qmousetslib_qws.h
SOURCES +=$$EMBEDDED_CPP/qmousetslib_qws.cpp
}
else:DEFINES += QT_NO_QWS_MOUSE_TSLIB
③在include目录下添加qmousetslib_qws.h
④执行配置命令:
./configure -embedded arm -xplatform qws/linux-arm-g++ -prefix ./../qte-3.38-arm -depths 4,8,16,32 -no-qvfb -no-mouse-qvfb -no-mouse-linuxtp -qt-mouse-pc -qt-mouse-tslib –I /home/lishw/omap/tslib/build/include -L /home/lishw/omap/tslib/build/lib
⑤修改lib目录下的libqte.prl文件。在该文件最后添加如下代码:
QMAKE_PRL_LIBS= -L/home/lishw/omap/tslib/build/lib -L/home/lishw/work8/qt-embedded-free-3.3.8/lib -lts -L/home/lishw/omap/tslib/build/lib -L/home/lishw/work8/qt-embedded-free-3.3.8/lib -lm -lrt -lpthread –ldl
⑥make
⑦make install
⑧将生成的lib目录(此处为qte-3.38-arm/lib)拷贝到目标板上
⑨在目标板上配置运行环境变量:
Export QTDIR=上述lib的父目录所在路径
Export QWS_MOUSE_PROTO=tslib:/dev/input/event2
Export LD_LIBRARY_PATH=上述lib目录所在路径
⑩运行测试程序:./test -qws
[qmousetslib_qws.cpp]
- #include "qmousetslib_qws.h"
- #if !defined(QT_NO_QWS_MOUSE_TSLIB) || defined(QT_PLUGIN)
- #include "qwindowsystem_qws.h"
- #include "qsocketnotifier.h"
- #include "qtimer.h"
- #include "qapplication.h"
- #include "qgfx_qws.h"
- #include "qregexp.h"
- #include "qvaluelist.h"
- //#include "qunicodetables_p.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>
- #include <tslib.h>
- #ifdef TSLIBMOUSEHANDLER_DEBUG
- # include <QtCore/QDebug>
- #endif
- /*!
- \internal
- \class QWSTslibMouseHandler
- \ingroup qws
- \brief The QWSTslibMouseHandler class implements a mouse driver
- for the Universal Touch Screen Library, tslib.
- QWSTslibMouseHandler inherits the QWSCalibratedMouseHandler class,
- providing calibration and noise reduction functionality in
- addition to generating mouse events, for devices using the
- Universal Touch Screen Library.
- To be able to compile this mouse handler, \l{Qt for Embedded Linux}
- must be configured with the \c -qt-mouse-tslib option, see the
- \l{Pointer Handling} documentation for details. In addition, the tslib
- headers and library must be present in the build environment. The
- tslib sources can be downloaded from \l
- {}. Use the \c -L and \c -I options
- with \c configure to explicitly specify the location of the
- library and its headers:
- \snippet doc/src/snippets/code/src_gui_embedded_qmousetslib_qws.cpp 0
- In order to use this mouse handler, tslib must also be correctly
- installed on the target machine. This includes providing a \c
- ts.conf configuration file and setting the necessary environment
- variables, see the README file provided with tslib for details.
- The ts.conf file will usually contain the following two lines
- \snippet doc/src/snippets/code/src_gui_embedded_qmousetslib_qws.cpp 1
- To make \l{Qt for Embedded Linux} explicitly choose the tslib mouse
- handler, set the QWS_MOUSE_PROTO environment variable.
- \sa {Pointer Handling}, {Qt for Embedded Linux}
- */
- class QWSTslibMouseHandlerPrivate : public QObject
- {
- Q_OBJECT
- public:
- QWSTslibMouseHandlerPrivate(QWSTslibMouseHandler *h,
- const QString &device);
- ~QWSTslibMouseHandlerPrivate();
- void suspend();
- void resume();
- void calibrate(QWSPointerCalibrationData *data);
- void clearCalibration();
- private:
- QWSTslibMouseHandler *handler;
- struct tsdev *dev;
- QSocketNotifier *mouseNotifier;
- int jitter_limit;
- struct ts_sample lastSample;
- bool wasPressed;
- int lastdx;
- int lastdy;
- bool calibrated;
- QString devName;
- bool open();
- void close();
-
- int qMax(const int &a, const int &b) ;
- int indexOfMutating(const QStringList *that, QRegExp &rx, int from);
- int QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from);
- int qAbs(const int &t);
- // int indexOf(const QRegExp &rx)const;
-
- //char *toLatin1(QString str,int len) const;
- inline bool get_sample(struct ts_sample *sample);
- private slots:
- void readMouseData();
- };
- QWSTslibMouseHandlerPrivate::QWSTslibMouseHandlerPrivate(QWSTslibMouseHandler *h,
- const QString &device)
- : handler(h), dev(0), mouseNotifier(0), jitter_limit(3)
- {
- //QStringList args = device.split(QLatin1Char(':'), QString::SkipEmptyParts);
- QStringList args = QStringList::split(':',device,FALSE);
- //QRegExp jitterRegex(QLatin1String("^jitter_limit=(\\d+)$"));
- QRegExp jitterRegex(QString::fromLatin1("^jitter_limit=(\\d+)$"));
- //int index = args.indexOf(jitterRegex);
- //QValueList &args2=args;
- //QString jitterStr=jitterRegex;
- //int index = args2.findIndex("hello");
- int index = QStringList_indexOf(&args,jitterRegex,0);
- if (index >= 0) {
- jitter_limit = jitterRegex.cap(1).toInt();
- args.remove(args.at(index));
- }
- devName = args.join(QString());
- if (devName.isNull()) {
- const char *str = getenv("TSLIB_TSDEVICE");
- if (str)
- devName = QString::fromLocal8Bit(str);
- }
- if (devName.isNull())
- // devName = QLatin1String("/dev/ts");
- devName = QString::fromLatin1("/dev/ts");
- if (!open())
- return;
- calibrated = true;
- int fd = ts_fd(dev);
- mouseNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
- connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
- resume();
- }
- QWSTslibMouseHandlerPrivate::~QWSTslibMouseHandlerPrivate()
- {
- close();
- }
- bool QWSTslibMouseHandlerPrivate::open()
- {
- dev = ts_open(devName.ascii(), 1);
- if (!dev) {
- qDebug("QWSTslibMouseHandlerPrivate: ts_open() failed"
- " with error: '%s'", strerror(errno));
- qDebug("Please check your tslib installation!");
- return false;
- }
- if (ts_config(dev)) {
- qDebug("QWSTslibMouseHandlerPrivate: ts_config() failed"
- " with error: '%s'", strerror(errno));
- qDebug("Please check your tslib installation!");
- close();
- return false;
- }
- return true;
- }
- void QWSTslibMouseHandlerPrivate::close()
- {
- if (dev)
- ts_close(dev);
- }
- void QWSTslibMouseHandlerPrivate::suspend()
- {
- if (mouseNotifier)
- mouseNotifier->setEnabled(false);
- }
- void QWSTslibMouseHandlerPrivate::resume()
- {
- memset(&lastSample, 0, sizeof(lastSample));
- wasPressed = false;
- lastdx = 0;
- lastdy = 0;
- if (mouseNotifier)
- mouseNotifier->setEnabled(true);
- }
- 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 QWSTslibMouseHandlerPrivate::qAbs(const int &t)
- { return t >= 0 ? t : -t; }
- int QWSTslibMouseHandlerPrivate::qMax(const int &a, const int &b)
- { if (a < b) return b; return a; }
- int QWSTslibMouseHandlerPrivate::indexOfMutating(const QStringList *that, QRegExp &rx, int from)
- {
- if (from < 0)
- from = qMax(from + that->size(), 0);
- for (uint i = from; i < that->size(); ++i) {
- if (rx.exactMatch(*that->at(i)))
- return i;
- }
- return -1;
- }
- int QWSTslibMouseHandlerPrivate::QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from)
- {
- QRegExp rx2(rx);
- return indexOfMutating(that, rx2, from);
- }
- /*
- int QWSTslibMouseHandlerPrivate::indexOf(const QRegExp &rx)const
- {
- return QStringList_indexOf(this, rx, 0);
- return 0;
- }
- */
- /*
- char * QWSTslibMouseHandlerPrivate::toLatin1(QString str,int len) const
- {
- #ifndef QT_NO_TEXTCODEC
- if (QTextCodec::codecForLocale())
- return QTextCodec::codecForLocale()->fromUnicode(*this);
- #endif // QT_NO_TEXTCODEC
- return unicodetoLatin1((QChar *)str,len);
- }
- */
- 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(dx*lastdx, dy*lastdy)
- << "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);
- }
- }
- }
- void QWSTslibMouseHandlerPrivate::clearCalibration()
- {
- suspend();
- close();
- handler->QWSCalibratedMouseHandler::clearCalibration();
- calibrated = false;
- open();
- resume();
- }
- void QWSTslibMouseHandlerPrivate::calibrate(QWSPointerCalibrationData *data)
- {
- suspend();
- close();
- // default implementation writes to /etc/pointercal
- // using the same format as the tslib linear module.
- handler->QWSCalibratedMouseHandler::calibrate(data);
- calibrated = true;
- open();
- resume();
- }
- /*!
- \internal
- */
- QWSTslibMouseHandler::QWSTslibMouseHandler(const QString &driver,
- const QString &device)
- : QWSCalibratedMouseHandler(driver, device)
- {
- d = new QWSTslibMouseHandlerPrivate(this, device);
- }
- /*!
- \internal
- */
- QWSTslibMouseHandler::~QWSTslibMouseHandler()
- {
- delete d;
- }
- /*!
- \reimp
- */
- void QWSTslibMouseHandler::suspend()
- {
- d->suspend();
- }
- /*!
- \reimp
- */
- void QWSTslibMouseHandler::resume()
- {
- d->resume();
- }
- /*!
- \reimp
- */
- void QWSTslibMouseHandler::clearCalibration()
- {
- d->clearCalibration();
- }
- /*!
- \reimp
- */
- void QWSTslibMouseHandler::calibrate(QWSPointerCalibrationData *data)
- {
- d->calibrate(data);
- }
- #include "qmousetslib_qws.moc"
- #endif
qmousetslib_qws.h
#ifndef QMOUSETSLIB_QWS_H
#define QMOUSETSLIB_QWS_H
#include "qmouse_qws.h"
#if !defined(QT_NO_QWS_MOUSE_TSLIB) || defined(QT_PLUGIN)
class QWSTslibMouseHandlerPrivate;
class QWSTslibMouseHandler : public QWSCalibratedMouseHandler
{
public:
explicit QWSTslibMouseHandler(const QString &driver = QString(),
const QString &device = QString());
~QWSTslibMouseHandler();
void suspend();
void resume();
void calibrate(QWSPointerCalibrationData *data);
void clearCalibration();
protected:
friend class QWSTslibMouseHandlerPrivate;
QWSTslibMouseHandlerPrivate *d;
};
#endif // QT_NO_QWS_MOUSE_TSLIB
#endif // QMOUSETSLIB_QWS_H