* tslib/plugins/linear.c
*
* Copyright (C) 2001 Russell King.
+ * Copyright (C) 2005 Alberto Mardegan <mardy@sourceforge.net>
*
* This file is placed under the LGPL. Please see the file
* COPYING for more details.
#include <stdio.h>
-#include "tslib.h"
+#include "tslib-private.h"
#include "tslib-filter.h"
struct tslib_linear {
// Linear scaling and offset parameters for x,y (can include rotation)
int a[7];
+
+// Screen resolution at the time when calibration was performed
+ unsigned int cal_res_x;
+ unsigned int cal_res_y;
};
static int
samp->y = ( lin->a[5] +
lin->a[3]*xtemp +
lin->a[4]*ytemp ) / lin->a[6];
+ if (info->dev->res_x && lin->cal_res_x)
+ samp->x = samp->x * info->dev->res_x / lin->cal_res_x;
+ if (info->dev->res_y && lin->cal_res_y)
+ samp->y = samp->y * info->dev->res_y / lin->cal_res_y;
samp->pressure = ((samp->pressure + lin->p_offset)
* lin->p_mult) / lin->p_div;
struct tslib_linear *lin;
struct stat sbuf;
- int pcal_fd;
+ FILE *pcal_fd;
char pcalbuf[200];
int index;
char *tokptr;
* Check calibration file
*/
if( (calfile = getenv("TSLIB_CALIBFILE")) == NULL) calfile = TS_POINTERCAL;
- if(stat(calfile,&sbuf)==0) {
- pcal_fd = open(calfile,O_RDONLY);
- read(pcal_fd,pcalbuf,200);
- lin->a[0] = atoi(strtok(pcalbuf," "));
- index=1;
- while(index<7) {
- tokptr = strtok(NULL," ");
- if(*tokptr!='\0') {
- lin->a[index] = atoi(tokptr);
- index++;
- }
- }
+ if (stat(calfile, &sbuf)==0) {
+ pcal_fd = fopen(calfile, "r");
+ for (index = 0; index < 7; index++)
+ if (fscanf(pcal_fd, "%d", &lin->a[index]) != 1) break;
+ fscanf(pcal_fd, "%d %d", &lin->cal_res_x, &lin->cal_res_y);
#ifdef DEBUG
printf("Linear calibration constants: ");
for(index=0;index<7;index++) printf("%d ",lin->a[index]);
printf("\n");
#endif /*DEBUG*/
+ fclose(pcal_fd);
close(pcal_fd);
}
lib_LTLIBRARIES = libts.la
libts_la_SOURCES = ts_attach.c ts_close.c ts_config.c ts_error.c \
ts_fd.c ts_load_module.c ts_open.c ts_parse_vars.c \
- ts_read.c ts_read_raw.c
+ ts_read.c ts_read_raw.c ts_option.c
libts_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-release $(LT_RELEASE) -export-dynamic
libts_la_LIBADD = -ldl
struct tslib_module_info *list_raw; /* points to position in 'list' where raw reads
come from. default is the position of the
ts_read_raw module. */
+ unsigned int res_x;
+ unsigned int res_y;
+ int rotation;
};
int __ts_attach(struct tsdev *ts, struct tslib_module_info *info);
struct timeval tv;
};
+enum ts_param {
+ TS_SCREEN_RES = 0, /* 2 integer args, x and y */
+ TS_SCREEN_ROT, /* 1 integer arg, 1 = rotate */
+};
+
/*
* Close the touchscreen device, free all resources.
*/
TSAPI int ts_config(struct tsdev *);
/*
+ * Changes a setting.
+ */
+TSAPI int ts_option(struct tsdev *, enum ts_param, ...);
+
+/*
* Change this hook to point to your custom error handling function.
*/
extern TSAPI int (*ts_error_fn)(const char *fmt, va_list ap);
char cal_buffer[256];
char *tsdevice = NULL;
char *calfile = NULL;
- unsigned int i;
+ unsigned int i, len;
signal(SIGSEGV, sig);
signal(SIGINT, sig);
cal_fd = open (TS_POINTERCAL, O_CREAT | O_RDWR,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
}
- sprintf (cal_buffer,"%d %d %d %d %d %d %d",
- cal.a[1], cal.a[2], cal.a[0],
- cal.a[4], cal.a[5], cal.a[3], cal.a[6]);
- write (cal_fd, cal_buffer, strlen (cal_buffer) + 1);
+ len = sprintf(cal_buffer,"%d %d %d %d %d %d %d %d %d",
+ cal.a[1], cal.a[2], cal.a[0],
+ cal.a[4], cal.a[5], cal.a[3], cal.a[6],
+ xres, yres);
+ write (cal_fd, cal_buffer, len);
close (cal_fd);
i = 0;
} else {