OSDN Git Service

Faciliates usage in a different resolution from when it was calibrated.
authorChris Larson <clarson@kergoth.com>
Fri, 22 May 2009 16:32:41 +0000 (16:32 +0000)
committerChris Larson <clarson@kergoth.com>
Fri, 22 May 2009 16:32:41 +0000 (16:32 +0000)
This is the first attempt to implement the possibility of using tslib even
from a graphic mode different from the one that was active when calibration
was performed.

*) Modifies ts_calibrate: now the program appends to /etc/pointercal two
additional values, i.e. x and y of current screen resolution.
*) Adds a ts_option function call to tslib API; right now this can be used to
inform tslib about current screen resolution and rotation.
*) Modifies the "linear" plugin to take into account current screen
resolution, and return values scaled accordingly.

Signed-off-by: Alberto Mardegan <mardy@sourceforge.net>
Signed-off-by: Chris Larson <clarson@kergoth.com>
plugins/linear.c
src/Makefile.am
src/tslib-private.h
src/tslib.h
tests/ts_calibrate.c

index 475b09f..3d39961 100644 (file)
@@ -2,6 +2,7 @@
  *  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.
@@ -19,7 +20,7 @@
 
 #include <stdio.h>
 
-#include "tslib.h"
+#include "tslib-private.h"
 #include "tslib-filter.h"
 
 struct tslib_linear {
@@ -33,6 +34,10 @@ 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
@@ -57,6 +62,10 @@ linear_read(struct tslib_module_info *info, struct ts_sample *samp, int nr)
                        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;
@@ -103,7 +112,7 @@ TSAPI struct tslib_module_info *mod_init(struct tsdev *dev, const char *params)
 
        struct tslib_linear *lin;
        struct stat sbuf;
-       int pcal_fd;
+       FILE *pcal_fd;
        char pcalbuf[200];
        int index;
        char *tokptr;
@@ -132,23 +141,17 @@ TSAPI struct tslib_module_info *mod_init(struct tsdev *dev, const char *params)
         * 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);
        }
                
index 1613941..57b1b09 100644 (file)
@@ -18,7 +18,7 @@ include_HEADERS  = tslib.h
 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
index 4e94dd3..f48d791 100644 (file)
@@ -24,6 +24,9 @@ struct tsdev {
        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);
index 99e494e..08cb4ac 100644 (file)
@@ -47,6 +47,11 @@ struct ts_sample {
        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.
  */
@@ -58,6 +63,11 @@ TSAPI int ts_close(struct tsdev *);
 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);
index 2662dc7..96121ef 100644 (file)
@@ -196,7 +196,7 @@ int main()
        char cal_buffer[256];
        char *tsdevice = NULL;
        char *calfile = NULL;
-       unsigned int i;
+       unsigned int i, len;
 
        signal(SIGSEGV, sig);
        signal(SIGINT, sig);
@@ -257,10 +257,11 @@ int main()
                        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 {