Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1307657
  • 博文数量: 548
  • 博客积分: 7597
  • 博客等级: 少将
  • 技术积分: 4224
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-15 13:21
个人简介

嵌入式软件工程师&&太极拳

文章分类

全部博文(548)

文章存档

2014年(10)

2013年(76)

2012年(175)

2011年(287)

分类: LINUX

2011-03-08 08:19:40

移植tslibqt-embedded-free-3.3.8

一、交叉编译tslib1.4。可以参考网上相关资料。

 

二、编译qt-x11-free-3.38,并把生成的bin目录下的uic文件拷贝到qt-embedded-free-3.3.8bin目录下

 

三、交叉编译qt-embedded-free-3.3.8

1.       配置好交叉编译的环境变量。

2.       添加tslibQt3.3.8的接口代码

src/embedded目录下添加qmousetslib_qws.hqmousetslib_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]

  1. #include "qmousetslib_qws.h"

  2. #if !defined(QT_NO_QWS_MOUSE_TSLIB) || defined(QT_PLUGIN)

  3. #include "qwindowsystem_qws.h"
  4. #include "qsocketnotifier.h"
  5. #include "qtimer.h"
  6. #include "qapplication.h"
  7. #include "qgfx_qws.h"
  8. #include "qregexp.h"
  9. #include "qvaluelist.h"
  10. //#include "qunicodetables_p.h"


  11. #include <unistd.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <sys/ioctl.h>
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <fcntl.h>
  18. #include <errno.h>
  19. #include <termios.h>

  20. #include <tslib.h>




  21. #ifdef TSLIBMOUSEHANDLER_DEBUG
  22. # include <QtCore/QDebug>
  23. #endif

  24. /*!
  25.     \internal

  26.     \class QWSTslibMouseHandler
  27.     \ingroup qws

  28.     \brief The QWSTslibMouseHandler class implements a mouse driver
  29.     for the Universal Touch Screen Library, tslib.

  30.     QWSTslibMouseHandler inherits the QWSCalibratedMouseHandler class,
  31.     providing calibration and noise reduction functionality in
  32.     addition to generating mouse events, for devices using the
  33.     Universal Touch Screen Library.

  34.     To be able to compile this mouse handler, \l{Qt for Embedded Linux}
  35.     must be configured with the \c -qt-mouse-tslib option, see the
  36.     \l{Pointer Handling} documentation for details. In addition, the tslib
  37.     headers and library must be present in the build environment. The
  38.     tslib sources can be downloaded from \l
  39.     {}. Use the \c -L and \c -I options
  40.     with \c configure to explicitly specify the location of the
  41.     library and its headers:

  42.     \snippet doc/src/snippets/code/src_gui_embedded_qmousetslib_qws.cpp 0

  43.     In order to use this mouse handler, tslib must also be correctly
  44.     installed on the target machine. This includes providing a \c
  45.     ts.conf configuration file and setting the necessary environment
  46.     variables, see the README file provided with tslib for details.

  47.     The ts.conf file will usually contain the following two lines

  48.     \snippet doc/src/snippets/code/src_gui_embedded_qmousetslib_qws.cpp 1

  49.     To make \l{Qt for Embedded Linux} explicitly choose the tslib mouse
  50.     handler, set the QWS_MOUSE_PROTO environment variable.

  51.     \sa {Pointer Handling}, {Qt for Embedded Linux}
  52. */

  53. class QWSTslibMouseHandlerPrivate : public QObject
  54. {
  55.     Q_OBJECT
  56. public:
  57.     QWSTslibMouseHandlerPrivate(QWSTslibMouseHandler *h,
  58.                                 const QString &device);
  59.     ~QWSTslibMouseHandlerPrivate();

  60.     void suspend();
  61.     void resume();

  62.     void calibrate(QWSPointerCalibrationData *data);
  63.     void clearCalibration();

  64. private:
  65.     QWSTslibMouseHandler *handler;
  66.     struct tsdev *dev;
  67.     QSocketNotifier *mouseNotifier;
  68.     int jitter_limit;

  69.     struct ts_sample lastSample;
  70.     bool wasPressed;
  71.     int lastdx;
  72.     int lastdy;

  73.     bool calibrated;
  74.     QString devName;

  75.     bool open();
  76.     void close();
  77.     
  78.     int qMax(const int &a, const int &b) ;
  79.     int indexOfMutating(const QStringList *that, QRegExp &rx, int from);
  80.     int QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from);
  81.         int qAbs(const int &t);
  82. //    int indexOf(const QRegExp &rx)const;

  83.     
  84.         //char *toLatin1(QString str,int len) const;

  85.     inline bool get_sample(struct ts_sample *sample);

  86. private slots:
  87.     void readMouseData();
  88. };

  89. QWSTslibMouseHandlerPrivate::QWSTslibMouseHandlerPrivate(QWSTslibMouseHandler *h,
  90.                                                          const QString &device)
  91.     : handler(h), dev(0), mouseNotifier(0), jitter_limit(3)
  92. {
  93.     //QStringList args = device.split(QLatin1Char(':'), QString::SkipEmptyParts);

  94.     QStringList args = QStringList::split(':',device,FALSE);
  95.     //QRegExp jitterRegex(QLatin1String("^jitter_limit=(\\d+)$"));

  96.     QRegExp jitterRegex(QString::fromLatin1("^jitter_limit=(\\d+)$"));
  97.     //int index = args.indexOf(jitterRegex);

  98.     //QValueList &args2=args;

  99.     //QString jitterStr=jitterRegex;

  100.     //int index = args2.findIndex("hello");

  101.     int index = QStringList_indexOf(&args,jitterRegex,0);
  102.     if (index >= 0) {
  103.         jitter_limit = jitterRegex.cap(1).toInt();
  104.         args.remove(args.at(index));
  105.     }

  106.     devName = args.join(QString());

  107.     if (devName.isNull()) {
  108.         const char *str = getenv("TSLIB_TSDEVICE");
  109.         if (str)
  110.             devName = QString::fromLocal8Bit(str);
  111.     }

  112.     if (devName.isNull())
  113.        // devName = QLatin1String("/dev/ts");

  114.         devName = QString::fromLatin1("/dev/ts");
  115.     if (!open())
  116.         return;

  117.     calibrated = true;

  118.     int fd = ts_fd(dev);
  119.     mouseNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
  120.     connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
  121.     resume();
  122. }

  123. QWSTslibMouseHandlerPrivate::~QWSTslibMouseHandlerPrivate()
  124. {
  125.     close();
  126. }

  127. bool QWSTslibMouseHandlerPrivate::open()
  128. {
  129.     dev = ts_open(devName.ascii(), 1);
  130.     if (!dev) {
  131.         qDebug("QWSTslibMouseHandlerPrivate: ts_open() failed"
  132.                   " with error: '%s'", strerror(errno));
  133.         qDebug("Please check your tslib installation!");
  134.         return false;
  135.     }

  136.     if (ts_config(dev)) {
  137.         qDebug("QWSTslibMouseHandlerPrivate: ts_config() failed"
  138.                   " with error: '%s'", strerror(errno));
  139.         qDebug("Please check your tslib installation!");
  140.         close();
  141.         return false;
  142.     }

  143.     return true;
  144. }

  145. void QWSTslibMouseHandlerPrivate::close()
  146. {
  147.     if (dev)
  148.         ts_close(dev);
  149. }
  150. void QWSTslibMouseHandlerPrivate::suspend()
  151. {
  152.     if (mouseNotifier)
  153.         mouseNotifier->setEnabled(false);
  154. }

  155. void QWSTslibMouseHandlerPrivate::resume()
  156. {
  157.     memset(&lastSample, 0, sizeof(lastSample));
  158.     wasPressed = false;
  159.     lastdx = 0;
  160.     lastdy = 0;
  161.     if (mouseNotifier)
  162.         mouseNotifier->setEnabled(true);
  163. }

  164. bool QWSTslibMouseHandlerPrivate::get_sample(struct ts_sample *sample)
  165. {
  166.     if (!calibrated)
  167.         return (ts_read_raw(dev, sample, 1) == 1);

  168.     return (ts_read(dev, sample, 1) == 1);
  169. }

  170. int QWSTslibMouseHandlerPrivate::qAbs(const int &t)
  171. { return t >= 0 ? t : -t; }

  172. int QWSTslibMouseHandlerPrivate::qMax(const int &a, const int &b)
  173. { if (a < b) return b; return a; }

  174. int QWSTslibMouseHandlerPrivate::indexOfMutating(const QStringList *that, QRegExp &rx, int from)
  175. {
  176.     if (from < 0)
  177.         from = qMax(from + that->size(), 0);
  178.     for (uint i = from; i < that->size(); ++i) {
  179.         if (rx.exactMatch(*that->at(i)))
  180.             return i;
  181.     }
  182.     return -1;
  183. }

  184. int QWSTslibMouseHandlerPrivate::QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from)
  185. {
  186.     QRegExp rx2(rx);
  187.     return indexOfMutating(that, rx2, from);
  188. }
  189. /*
  190. int QWSTslibMouseHandlerPrivate::indexOf(const QRegExp &rx)const
  191. {
  192.     return QStringList_indexOf(this, rx, 0);
  193.     return 0;
  194. }
  195. */
  196. /*
  197. char * QWSTslibMouseHandlerPrivate::toLatin1(QString str,int len) const
  198. {
  199. #ifndef QT_NO_TEXTCODEC
  200.     if (QTextCodec::codecForLocale())
  201.         return QTextCodec::codecForLocale()->fromUnicode(*this);
  202. #endif // QT_NO_TEXTCODEC
  203.     return unicodetoLatin1((QChar *)str,len);
  204. }
  205. */
  206. void QWSTslibMouseHandlerPrivate::readMouseData()
  207. {
  208.     if (!qt_screen)
  209.         return;

  210.     for(;;) {
  211.         struct ts_sample sample = lastSample;
  212.         bool pressed = wasPressed;

  213.         // Fast return if there's no events.

  214.         if (!get_sample(&sample))
  215.             return;
  216.         pressed = (sample.pressure > 0);

  217.         // Only return last sample unless there's a press/release event.

  218.         while (pressed == wasPressed) {
  219.             if (!get_sample(&sample))
  220.                 break;
  221.             pressed = (sample.pressure > 0);
  222.         }

  223.         // work around missing coordinates on mouse release in raw mode

  224.         if (!calibrated && !pressed && sample.x == 0 && sample.y == 0) {
  225.             sample.x = lastSample.x;
  226.             sample.y = lastSample.y;
  227.         }

  228.         int dx = sample.x - lastSample.x;
  229.         int dy = sample.y - lastSample.y;

  230.         // Remove small movements in oppsite direction

  231.         if (dx * lastdx < 0 && qAbs(dx) < jitter_limit) {
  232.             sample.x = lastSample.x;
  233.             dx = 0;
  234.         }
  235.         if (dy * lastdy < 0 && qAbs(dy) < jitter_limit) {
  236.             sample.y = lastSample.y;
  237.             dy = 0;
  238.         }

  239.         if (wasPressed == pressed && dx == 0 && dy == 0)
  240.             return;

  241. #ifdef TSLIBMOUSEHANDLER_DEBUG
  242.         qDebug() << "last" << QPoint(lastSample.x, lastSample.y)
  243.                  << "curr" << QPoint(sample.x, sample.y)
  244.                  << "dx,dy" << QPoint(dx, dy)
  245.                  << "ddx,ddy" << QPoint(dx*lastdx, dy*lastdy)
  246.                  << "pressed" << wasPressed << pressed;
  247. #endif

  248.         lastSample = sample;
  249.         wasPressed = pressed;
  250.         if (dx != 0)
  251.             lastdx = dx;
  252.         if (dy != 0)
  253.             lastdy = dy;

  254.         const QPoint p(sample.x, sample.y);
  255.         if (calibrated) {
  256.             // tslib should do all the translation and filtering, so we send a

  257.             // "raw" mouse event

  258.             handler->QWSMouseHandler::mouseChanged(p, pressed);
  259.         } else {
  260.             handler->sendFiltered(p, pressed);
  261.         }
  262.     }
  263. }

  264. void QWSTslibMouseHandlerPrivate::clearCalibration()
  265. {
  266.     suspend();
  267.     close();
  268.     handler->QWSCalibratedMouseHandler::clearCalibration();
  269.     calibrated = false;
  270.     open();
  271.     resume();
  272. }

  273. void QWSTslibMouseHandlerPrivate::calibrate(QWSPointerCalibrationData *data)
  274. {
  275.     suspend();
  276.     close();
  277.     // default implementation writes to /etc/pointercal

  278.     // using the same format as the tslib linear module.

  279.     handler->QWSCalibratedMouseHandler::calibrate(data);
  280.     calibrated = true;
  281.     open();
  282.     resume();
  283. }

  284. /*!
  285.     \internal
  286. */
  287. QWSTslibMouseHandler::QWSTslibMouseHandler(const QString &driver,
  288.                                            const QString &device)
  289.     : QWSCalibratedMouseHandler(driver, device)
  290. {
  291.     d = new QWSTslibMouseHandlerPrivate(this, device);
  292. }

  293. /*!
  294.     \internal
  295. */
  296. QWSTslibMouseHandler::~QWSTslibMouseHandler()
  297. {
  298.     delete d;
  299. }

  300. /*!
  301.     \reimp
  302. */
  303. void QWSTslibMouseHandler::suspend()
  304. {
  305.     d->suspend();
  306. }

  307. /*!
  308.     \reimp
  309. */
  310. void QWSTslibMouseHandler::resume()
  311. {
  312.     d->resume();
  313. }

  314. /*!
  315.     \reimp
  316. */
  317. void QWSTslibMouseHandler::clearCalibration()
  318. {
  319.     d->clearCalibration();
  320. }

  321. /*!
  322.     \reimp
  323. */
  324. void QWSTslibMouseHandler::calibrate(QWSPointerCalibrationData *data)
  325. {
  326.     d->calibrate(data);
  327. }



  328. #include "qmousetslib_qws.moc"

  329. #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

 

阅读(2057) | 评论(0) | 转发(0) |
0

上一篇:qt&linux

下一篇:嵌入式网站

给主人留下些什么吧!~~