2
* Id: ts.c,v 1.1 1999/11/02 18:39:28 keithp Exp $
4
* Copyright � 1999 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
24
/* $RCSId: xc/programs/Xserver/hw/kdrive/itsy/ts.c,v 1.1 1999/11/19 13:53:54 hohndel Exp $ */
27
#include <kdrive-config.h>
31
#include <X11/Xproto.h>
36
itsyTsReadBytes (int fd, char *buf, int len, int min)
45
n = read (fd, buf, len);
57
tv.tv_usec = 100 * 1000;
58
n = select (fd + 1, &set, 0, 0, &tv);
66
itsyTsRead (int tsPort)
74
unsigned long buttons;
76
n = itsyTsReadBytes (tsPort, (char *) &event,
77
sizeof (event), sizeof (event));
78
if (n == sizeof (event))
88
flags = KD_MOUSE_DELTA;
92
KdEnqueueMouseEvent (flags, x, y);
97
#define ITSY_DEBUG_LOW 1
100
// Touch screen parameters are stored
101
// in the flash. This code is taken from 'wm1'.
103
void itsySetTouchCalibration (int mou_filedsc,
104
int xs, int xt, int ys, int yt, int xys)
113
if ((k=ioctl(mou_filedsc, TS_SET_CALM, ibuf)) != 0) {
114
fprintf(stderr, "ERROR: ioctl TS_SET_CALM returns %d\n", k);
119
int itsyReadFlashBlock(int location, signed char *data, int dbytes)
124
flashfd = open("/dev/flash1", O_RDONLY);
125
if (flashfd < 0) return(0);
127
offset = lseek(flashfd, location, SEEK_SET);
128
if (offset != location) {
133
bytes = read(flashfd, data, dbytes);
134
if (bytes != dbytes) {
143
/**********************************************************************/
144
#define RAMSIZE (0x400000)
145
#define MONITOR_BLOCKSIZE (32)
146
/**********************************************************************/
148
/* code for storing calibration into flash */
150
#define CALIBRATE_BLOCKSIZE (32)
151
#define CALIBRATE_OFFSET (RAMSIZE-MONITOR_BLOCKSIZE-CALIBRATE_BLOCKSIZE)
152
#define CALIBRATE_MAGIC_NUM (0x0babedee)
155
static int check_if_calibrated_and_set(int mou_filedsc)
157
signed char cal_data[CALIBRATE_BLOCKSIZE];
160
if (itsyReadFlashBlock(CALIBRATE_OFFSET,
161
cal_data, CALIBRATE_BLOCKSIZE) == 0) {
162
if ( ITSY_DEBUG_LOW ) {
163
fprintf(stderr,"unable to read calibration data for touch screen\n");
168
iptr = (int *) cal_data;
169
if (iptr[0] == CALIBRATE_MAGIC_NUM) {
170
if ( ITSY_DEBUG_LOW ) {
171
fprintf(stderr,"Calibrating touch screen using %d, %d, %d, %d, %d\n",
172
iptr[1], iptr[2], iptr[3], iptr[4], iptr[5]);
174
itsySetTouchCalibration(mou_filedsc, iptr[1], iptr[2], iptr[3], iptr[4], iptr[5]);
178
if ( ITSY_DEBUG_LOW ) {
179
fprintf(stderr,"Couldn't calibrate screen\n");
191
tsPort = open ("/dev/ts", 0);
192
fprintf (stderr, "tsPort %d\n", tsPort);
195
check_if_calibrated_and_set (tsPort);
201
itsyTsFini (int tsPort)
207
KdMouseFuncs itsyTsMouseFuncs = {