~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/kdrive/itsy/ts.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
Import upstream version 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Id: ts.c,v 1.1 1999/11/02 18:39:28 keithp Exp $
 
3
 *
 
4
 * Copyright � 1999 Keith Packard
 
5
 *
 
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.
 
15
 *
 
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.
 
23
 */
 
24
/* $RCSId: xc/programs/Xserver/hw/kdrive/itsy/ts.c,v 1.1 1999/11/19 13:53:54 hohndel Exp $ */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
#include <kdrive-config.h>
 
28
#endif
 
29
#define NEED_EVENTS
 
30
#include "itsy.h"
 
31
#include <X11/Xproto.h>
 
32
#include "inputstr.h"
 
33
#include "Xpoll.h"
 
34
 
 
35
int
 
36
itsyTsReadBytes (int fd, char *buf, int len, int min)
 
37
{
 
38
    int             n, tot;
 
39
    fd_set          set;
 
40
    struct timeval  tv;
 
41
 
 
42
    tot = 0;
 
43
    while (len)
 
44
    {
 
45
        n = read (fd, buf, len);
 
46
        if (n > 0)
 
47
        {
 
48
            tot += n;
 
49
            buf += n;
 
50
            len -= n;
 
51
        }
 
52
        if (tot % min == 0)
 
53
            break;
 
54
        FD_ZERO (&set);
 
55
        FD_SET (fd, &set);
 
56
        tv.tv_sec = 0;
 
57
        tv.tv_usec = 100 * 1000;
 
58
        n = select (fd + 1, &set, 0, 0, &tv);
 
59
        if (n <= 0)
 
60
            break;
 
61
    }
 
62
    return tot;
 
63
}
 
64
 
 
65
void
 
66
itsyTsRead (int tsPort)
 
67
{
 
68
    ts_event        event;
 
69
    long            buf[3];
 
70
    int             n;
 
71
    long            pressure;
 
72
    long            x, y;
 
73
    unsigned long   flags;
 
74
    unsigned long   buttons;
 
75
 
 
76
    n = itsyTsReadBytes (tsPort, (char *) &event, 
 
77
                         sizeof (event), sizeof (event));
 
78
    if (n == sizeof (event))
 
79
    {
 
80
        if (event.pressure)
 
81
        {
 
82
            flags = KD_BUTTON_1;
 
83
            x = event.point.x;
 
84
            y = event.point.y;
 
85
        }
 
86
        else
 
87
        {
 
88
            flags = KD_MOUSE_DELTA;
 
89
            x = 0;
 
90
            y = 0;
 
91
        }
 
92
        KdEnqueueMouseEvent (flags, x, y);
 
93
    }
 
94
}
 
95
 
 
96
#if 0
 
97
#define ITSY_DEBUG_LOW  1
 
98
 
 
99
//
 
100
// Touch screen parameters are stored
 
101
// in the flash. This code is taken from 'wm1'.
 
102
//
 
103
void itsySetTouchCalibration (int mou_filedsc, 
 
104
                              int xs, int xt, int ys, int yt, int xys)
 
105
{
 
106
  int k, ibuf[10];
 
107
 
 
108
  ibuf[0] = xs;
 
109
  ibuf[1] = xt;
 
110
  ibuf[2] = ys;
 
111
  ibuf[3] = yt;
 
112
  ibuf[4] = xys;
 
113
  if ((k=ioctl(mou_filedsc, TS_SET_CALM, ibuf)) != 0) {
 
114
    fprintf(stderr, "ERROR: ioctl TS_SET_CALM returns %d\n", k);
 
115
  }
 
116
}
 
117
 
 
118
 
 
119
int itsyReadFlashBlock(int location, signed char *data, int dbytes) 
 
120
{
 
121
  int offset, bytes;
 
122
  int flashfd;
 
123
 
 
124
  flashfd = open("/dev/flash1", O_RDONLY);
 
125
  if (flashfd < 0) return(0);
 
126
 
 
127
  offset = lseek(flashfd, location, SEEK_SET);
 
128
  if (offset != location) {
 
129
    close(flashfd);
 
130
    return(0);
 
131
  }
 
132
 
 
133
  bytes = read(flashfd, data, dbytes);
 
134
  if (bytes != dbytes) {
 
135
    close(flashfd);
 
136
    return(0);
 
137
  }
 
138
 
 
139
  close(flashfd);
 
140
  return(1);
 
141
}
 
142
 
 
143
/**********************************************************************/
 
144
#define RAMSIZE (0x400000)
 
145
#define MONITOR_BLOCKSIZE (32)
 
146
/**********************************************************************/
 
147
 
 
148
/* code for storing calibration into flash */
 
149
 
 
150
#define CALIBRATE_BLOCKSIZE (32)
 
151
#define CALIBRATE_OFFSET (RAMSIZE-MONITOR_BLOCKSIZE-CALIBRATE_BLOCKSIZE)
 
152
#define CALIBRATE_MAGIC_NUM (0x0babedee)
 
153
 
 
154
 
 
155
static int check_if_calibrated_and_set(int mou_filedsc) 
 
156
{
 
157
  signed char cal_data[CALIBRATE_BLOCKSIZE];
 
158
  int *iptr;
 
159
 
 
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");
 
164
    }
 
165
    return(0);
 
166
  }
 
167
 
 
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]);
 
173
    }
 
174
    itsySetTouchCalibration(mou_filedsc, iptr[1], iptr[2], iptr[3], iptr[4], iptr[5]);
 
175
    return(1);
 
176
  }
 
177
  else {
 
178
    if ( ITSY_DEBUG_LOW ) {
 
179
      fprintf(stderr,"Couldn't calibrate screen\n");
 
180
    }
 
181
    return(0);
 
182
  }
 
183
}
 
184
#endif
 
185
 
 
186
int
 
187
itsyTsInit (void)
 
188
{
 
189
    int tsPort;
 
190
 
 
191
    tsPort = open ("/dev/ts", 0);
 
192
    fprintf (stderr, "tsPort %d\n", tsPort);
 
193
#if 0
 
194
    if (tsPort >= 0)
 
195
        check_if_calibrated_and_set (tsPort);
 
196
#endif
 
197
    return tsPort;
 
198
}
 
199
 
 
200
void
 
201
itsyTsFini (int tsPort)
 
202
{
 
203
    if (tsPort >= 0)
 
204
        close (tsPort);
 
205
}
 
206
 
 
207
KdMouseFuncs itsyTsMouseFuncs = {
 
208
    itsyTsInit,
 
209
    itsyTsRead,
 
210
    itsyTsFini
 
211
};
 
212