File: mk712-raw.c

package info (click to toggle)
tslib 1.22-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: ansic: 18,859; sh: 4,167; makefile: 550
file content (75 lines) | stat: -rw-r--r-- 1,598 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright (C) 2004 Douglas Lowder
 *
 * SPDX-License-Identifier: LGPL-2.1
 */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include "config.h"
#include "tslib-private.h"

struct mk712_ts_event { /* Used in the Hitachi Webpad */
	unsigned int header;
	unsigned int x;
	unsigned int y;
	unsigned int reserved;
};

static int mk712_read(struct tslib_module_info *inf, struct ts_sample *samp,
		      int nr)
{
	struct tsdev *ts = inf->dev;
	struct mk712_ts_event *mk712_evt;
	int ret;
	int nr_read;

	mk712_evt = alloca(sizeof(*mk712_evt) * nr);
	ret = read(ts->fd, mk712_evt, sizeof(*mk712_evt) * nr);
	if (ret > 0) {
		nr_read = ret / sizeof(*mk712_evt);
		while (ret >= (int)sizeof(*mk712_evt)) {
			samp->x = (short)mk712_evt->x;
			samp->y = (short)mk712_evt->y;
			if (mk712_evt->header == 0)
				samp->pressure = 1;
			else
				samp->pressure = 0;
#ifdef DEBUG
	fprintf(stderr, "RAW---------------------------> %d %d %d\n",
		samp->x, samp->y, samp->pressure);
#endif /*DEBUG*/
			gettimeofday(&samp->tv, NULL);
			samp++;
			mk712_evt++;
			ret -= sizeof(*mk712_evt);
		}
	} else {
		return -1;
	}

	ret = nr_read;
	return ret;
}

static const struct tslib_ops mk712_ops = {
	.read	= mk712_read,
};

TSAPI struct tslib_module_info *mk712_mod_init(__attribute__ ((unused)) struct tsdev *dev,
					       __attribute__ ((unused))const char *params)
{
	struct tslib_module_info *m;

	m = malloc(sizeof(struct tslib_module_info));
	if (m == NULL)
		return NULL;

	m->ops = &mk712_ops;
	return m;
}

#ifndef TSLIB_STATIC_MK712_MODULE
	TSLIB_MODULE_INIT(mk712_mod_init);
#endif