summaryrefslogtreecommitdiff
path: root/src/touchscreen.c
blob: 90e0b81536a1b9da6c2daa3d379056a17c8e77e6 (plain)
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
#include "stdio.h"
#include "stdlib.h"
#include "tslib.h"

struct tsdev *ts = NULL;

int InitTouchScreen(void) {
	// Taken directly from tslib test sources, slightly modifed
	char *tsdevice = NULL;

	if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL ) {
		ts = ts_open(tsdevice, 1);
	} else {
		ts = ts_open("/dev/input/event0", 1);
	}

	if (!ts) {
		perror("ts_open");
		return 0;
	}
	if (ts_config(ts)) {
		perror("ts_config");
		return 0;
	}	

	return 1;
}

void DeInitTouchScreen(void) {
	// Nothing to do	
}


// return -1 on error, else pressure value

int getTouchScreen(int *x, int *y) {
	struct ts_sample tsdata;

	if (ts == NULL) return -1;

	if (ts_read(ts, &tsdata, 1) != 1) return -1;

	*x = tsdata.x;
	*y = tsdata.y;
	return tsdata.pressure;
}