1TS_READ(3) tslib TS_READ(3)
2
3
4
6 ts_read, ts_read_raw, ts_read_mt, ts_read_raw_mt - read tslib touch
7 samples
8
10 #include <tslib.h>
11
12 int ts_read(struct tsdev *dev, struct ts_sample *samp, int nr);
13
14 int ts_read_raw(struct tsdev *dev, struct ts_sample *samp, int nr);
15
16 int ts_read_mt(struct tsdev *dev, struct ts_sample_mt **samp, int slots, int nr);
17
18 int ts_read_raw_mt(struct tsdev *dev, struct ts_sample_mt **samp, int slots, int nr);
19
20
21
23 ts_read() reads nr input samples with tslib's filters applied. struct
24 ts_sample is define as follows:
25 struct ts_sample {
26 int x;
27 int y;
28 unsigned int pressure;
29 struct timeval tv;
30 };
31
32 ts_read_mt() reads nr * slots input samples with tslib's filters
33 applied. struct ts_sample_mt is defined as follows:
34 struct ts_sample_mt {
35 /* most recent ABS_MT_* event codes.
36 * see linux/input.h for descriptions */
37 int x;
38 int y;
39 unsigned int pressure;
40 int slot;
41 int tracking_id;
42
43 int tool_type;
44 int tool_x;
45 int tool_y;
46 unsigned int touch_major;
47 unsigned int width_major;
48 unsigned int touch_minor;
49 unsigned int width_minor;
50 int orientation;
51 int distance;
52 int blob_id;
53
54 struct timeval tv;
55
56 /* BTN_TOUCH state */
57 short pen_down;
58
59 /* the TSLIB_MT_VALID bit is set in valid if this sample
60 * contains new data;
61 * valid is set to 0 otherwise */
62 short valid;
63 };
64
65 The user has to provide the amount of memory described in nr and slots
66 to hold them.
67
68 ts_read_raw() and ts_read_raw_mt() do the same thing without tslib's
69 filters applied.
70
71
73 The number of actually read samples is returned. Especially when opened
74 in non-blocking mode, see ts_setup() , that can be less than requested
75 in the call. On failure, a negative error number is returned.
76
77
79 The following program continuously reads tslib multitouch input samples
80 and prints slot and position values to stdout as the touch screen is
81 touched.
82
83 #include <stdio.h>
84 #include <stdlib.h>
85 #include <fcntl.h>
86
87 #include <tslib.h>
88
89 #define READ_SAMPLES 1
90 #define MAX_SLOTS 5
91
92 int main(int argc, char **argv)
93 {
94 struct tsdev *ts;
95 struct ts_sample_mt **samp_mt = NULL;
96 int i, j;
97 int ret;
98
99 ts = ts_setup(NULL, 0);
100 if (!ts)
101 return -1;
102
103 samp_mt = malloc(READ_SAMPLES * sizeof(struct ts_sample_mt **));
104 if (!samp_mt)
105 return -1;
106
107 for (i = 0; i < READ_SAMPLES; i++) {
108 samp_mt[i] = calloc(MAX_SLOTS, sizeof(struct ts_sample_mt));
109 if (!samp_mt[i])
110 return -1;
111 }
112
113 while(1) {
114 ret = ts_read_mt(ts, samp_mt, MAX_SLOTS, READ_SAMPLES);
115 for (i = 0; i < ret; i++) {
116 printf("sample nr %d0, i);
117 for (j = 0; i < MAX_SLOTS; j++) {
118 if (!(samp_mt[i][j].valid & TSLIB_MT_VALID))
119 continue;
120
121 printf("slot %d: X:%d Y: %d0,
122 samp_mt[i][j].slot,
123 samp_mt[i][j].x,
124 samp_mt[i][j].y);
125 }
126 }
127 }
128 }
129
131 ts_setup(3), ts_config(3), ts_open(3), ts_close(3), ts.conf(5)
132
133
134
135 TS_READ(3)