1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - Qt/Embedded Pointer Handling</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style></head><body bgcolor="#ffffff">
<p>
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center> Qt/Embedded Pointer Handling</h1><br clear="all">
<p>
Pointer handling in Qt/Embedded works for any mouse-like device such as
a touchpanel, a trackball, or real mouse.
<p>
In a real device, only a small number of pointer devices (usually one)
would be supported, but for demonstration purposes, Qt/Embedded includes
a large number of supported devices.
<p>
<h2>Mouse Protocols</h2>
<p>
Qt/Embedded normally auto-detects the mouse type and device if it is one of
the supported types on <tt>/dev/psaux</tt> or one of the <tt>/dev/ttyS?</tt>
serial lines. If multiple mice are detected, all may be used simultaneously.
<p>
Alternatively, you may set the environment variable QWS_MOUSE_PROTO to
determine which mouse to use. This environment variable may be set to:
<blockquote>
<i><protocol></i><tt>:</tt><i><device></i>
</blockquote>
where <i><protocol></i> is one of:
<ul>
<li>MouseMan
<li>IntelliMouse
<li>Microsoft
</ul>
and <i><device></i> is the mouse device, often <tt>/dev/mouse</tt>.
If no such variable is specified, the built-in default
is <tt>Auto</tt> which enables auto-detection of the mouse protocol
and device.
<p>
To add another protocol, new subclasses of QAutoMouseSubHandler or
QMouseHandler can be written in <tt>kernel/qwsmouse_qws.cpp</tt>.
<p>
<h2>Touch Panels</h2>
<p>
Qt/Embedded ships with support for the NEC Vr41XX touchpanel
and the iPAQ touchpanel.
These are subclasses of QCalibratedMouseHandler which is in turn
a subclass of QMouseHandler in <tt>kernel/qwsmouse_qws.cpp</tt>.
<p>
Writing a custom touch panel handler for Qt/Embedded is not as
hard as the QVrTPanelHandlerPrivate class makes it look.
The Vr41XX touch panel handler is complex; it handles filtering of
noisy input data, and it generates mouse release events by using a
timer.
<p>
Many touch panel devices have a much simpler interface, so a
port to Qt/Embedded can be written in a few minutes, without expert
knowledge of Qt/Embedded.
<p>
The Qt/Embedded release contains an example touch panel handler in the
class QCustomTPanelHandlerPrivate, located in the file
<tt>$QTDIR/src/kernel/qwsmouse_qws.cpp</tt>. It is protected by<tt>#ifdef
QWS_CUSTOMTOUCHPANEL</tt>.
<p>
The example reads data from /dev/ts with the following format:
Each packet consists of 5 bytes.
<ul>
<li>Byte 0 gives status information, in particular, bit 6 (0x40)
is 1 when the stylus is down, 0 if it is released.
<li> Bytes 1 and 2 give the x position;
<li> Bytes 3 and 4 give the y position;
</ul>
<p>
To enable this driver, uncomment the line <tt>#define QWS_CUSTOMTOUCHPANEL</tt>
in the file qwsmouse_qws.cpp.
<p>
Chances are, your touch panel device will not match exactly the
example device. As an example, take a hypothetical device located at
/dev/touchpanel. This device uses 6-byte packets. Byte 0 and 1 give
status and pressure information. In particular, bit 5 (0x20) of byte 1
tells whether the stylus is down or up. Bytes 2 and 3 give x position and
bytes 4 and 5 give y position.
<p>
Pressure information is not necessary for basic Qt/Embedded operation,
so we will ignore that for now. The following shows the modified touch
panel handler for the hypothetical device, with comments marked with
<tt>//***<tt> indicating the changes made. You can also see some printf
calls left over from the (hypothetical) debugging.
<p>
<pre>//*** Modified Trolltech's example handler to handle the
//*** hypothetical touch panel.
QCustomTPanelHandlerPrivate::QCustomTPanelHandlerPrivate( MouseProtocol, QString )
{
//*** changed device name to /dev/touchpanel
if ((mouseFD = open( "/dev/touchpanel", O_RDONLY)) < 0) {
<a href="qapplication.html#290ef4">qWarning</a>( "Cannot open /dev/touchpanel (%s)", strerror(errno));
return;
}
//*** removed the delay since our device does not need it.
//else {
// sleep(1);
//}
<a href="qsocketnotifier.html">QSocketNotifier</a> *mouseNotifier;
mouseNotifier = new <a href="qsocketnotifier.html">QSocketNotifier</a>( mouseFD, QSocketNotifier::Read,
this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
}
QCustomTPanelHandlerPrivate::~QCustomTPanelHandlerPrivate()
{
if (mouseFD >= 0)
close(mouseFD);
}
struct CustomTPdata {
unsigned char status;
unsigned short xpos;
unsigned short ypos;
};
void QCustomTPanelHandlerPrivate::readMouseData()
{
if(!qt_screen)
return;
CustomTPdata data;
//*** changed size to 6 bytes
unsigned char data2[6];
int ret;
//*** read 6 bytes
ret=read(mouseFD,data2,6);
if(ret==6) { //*** change to 6
//*** all the indexes changed:
data.status=data2[1];
data.xpos=(data2[2] << 8) | data2[3];
data.ypos=(data2[4] << 8) | data2[5];
<a href="qpoint.html">QPoint</a> q;
q.<a href="qpoint.html#75b57f">setX</a>(data.xpos);
q.<a href="qpoint.html#c780b4">setY</a>(data.ypos);
mousePos=q;
if(data.status & 0x20) { //*** Changed to 0x20 (bit 5)
emit mouseChanged(mousePos,Qt::LeftButton);
//printf( "Stylus press/move %d,%d\n", data.xpos, data.ypos );
} else {
emit mouseChanged(mousePos,0);
//printf( "Stylus release %d,%d\n", data.xpos, data.ypos );
}
}
if(ret<0) {
<a href="qapplication.html#72e78c">qDebug</a>("Error %s",strerror(errno));
}
}
</pre>
<p>
Once you have your touch panel handler working, you may choose to keep
it like it is. However, if you want to switch between different
mouse/touch panel devices at run time, you will have to modify
QWSServer::newMouseHandler() (also in qwsmouse_qws.cpp) to instantiate
your new handler(s). You will also need to add to the enum
<tt>MouseProtocol</tt> and the table <tt>mouseConfig[]</tt>. Note that
the precise details on how mouse and touch panel drivers are instantiated
may have to be changed in future versions of Qt/Embedded.
<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>
|