From da2dca21b385bff9f06c9a68f809baf613482f3a Mon Sep 17 00:00:00 2001 From: Grazvydas Ignotas Date: Sun, 4 Dec 2011 02:52:12 +0200 Subject: [PATCH] tslib: add new lowpass filter taken from http://docs.openmoko.org/trac/ticket/1194 --- recipes/tslib/tslib/add_lowpass_plugin.patch | 23 +++ recipes/tslib/tslib/lowpass.c | 158 +++++++++++++++++++ recipes/tslib/tslib_1.0.bb | 12 +- 3 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 recipes/tslib/tslib/add_lowpass_plugin.patch create mode 100644 recipes/tslib/tslib/lowpass.c diff --git a/recipes/tslib/tslib/add_lowpass_plugin.patch b/recipes/tslib/tslib/add_lowpass_plugin.patch new file mode 100644 index 0000000000..a3fd3a721b --- /dev/null +++ b/recipes/tslib/tslib/add_lowpass_plugin.patch @@ -0,0 +1,23 @@ +diff -ur tslib-1.0_/plugins/Makefile.am tslib-1.0/plugins/Makefile.am +--- tslib-1.0_/plugins/Makefile.am 2011-12-04 02:32:07.595566001 +0200 ++++ tslib-1.0/plugins/Makefile.am 2011-12-04 02:36:20.755566002 +0200 +@@ -103,7 +103,8 @@ + $(MK712_MODULE) \ + $(ARCTIC2_MODULE) \ + $(H2200_LINEAR_MODULE) \ +- $(INPUT_MODULE) ++ $(INPUT_MODULE) \ ++ lowpass.la + + variance_la_SOURCES = variance.c + variance_la_LDFLAGS = -module $(LTVSN) +@@ -117,6 +118,9 @@ + pthres_la_SOURCES = pthres.c + pthres_la_LDFLAGS = -module $(LTVSN) + ++lowpass_la_SOURCES = lowpass.c ++lowpass_la_LDFLAGS = -module $(LTVSN) ++ + # hw access + corgi_la_SOURCES = corgi-raw.c + corgi_la_LDFLAGS = -module $(LTVSN) diff --git a/recipes/tslib/tslib/lowpass.c b/recipes/tslib/tslib/lowpass.c new file mode 100644 index 0000000000..8fc7960557 --- /dev/null +++ b/recipes/tslib/tslib/lowpass.c @@ -0,0 +1,158 @@ +/* + * This file is placed under the LGPL. Please see the file + * COPYING for more details. + * + * Very stupid lowpass dejittering filter + * taken from http://docs.openmoko.org/trac/ticket/1194 + */ +#include +#include +#include +#include +#include + +#include "tslib.h" +#include "tslib-filter.h" + +struct tslib_lowpass { + struct tslib_module_info module; + struct ts_sample last; + struct ts_sample ideal; + int factor; + unsigned int flags; + unsigned char threshold; +#define VAR_PENUP 0x00000001 +}; + +static int lowpass_read(struct tslib_module_info *info, struct ts_sample *samp, int nr) +{ + struct tslib_lowpass *var = (struct tslib_lowpass *)info; + struct ts_sample current; + int count = 0; + int delta; + + while (count < nr) { + if (info->next->ops->read(info->next, ¤t, 1) < 1) + return count; + + if (current.pressure == 0) { + var->flags |= VAR_PENUP; + samp [count++] = current; + } else if (var->flags & VAR_PENUP) { + var->flags &= ~VAR_PENUP; + var->last = current; + samp [count++] = current; + } else { + var->ideal = current; + + var->ideal.x = var->last.x; + delta = current.x - var->last.x; + if (delta <= var->threshold && + delta >= -var->threshold) + delta = 0; + delta = delta * var->factor >> 16; + var->ideal.x += delta; + + var->ideal.y = var->last.y; + delta = current.y - var->last.y; + if (delta <= var->threshold && + delta >= -var->threshold) + delta = 0; + delta = delta * var->factor >> 16; + var->ideal.y += delta; + + var->last = var->ideal; + samp [count++] = var->ideal; + } + } + return count; +} + +static int lowpass_fini(struct tslib_module_info *info) +{ + free(info); + return 0; +} + +static const struct tslib_ops lowpass_ops = +{ + .read = lowpass_read, + .fini = lowpass_fini, +}; + +static int lowpass_factor(struct tslib_module_info *inf, char *str, void *data) +{ + struct tslib_lowpass *var = (struct tslib_lowpass *)inf; + long double v; + int err = errno; + + v = strtod(str, NULL); + + if (v > 1 || v < 0) + return -1; + + errno = err; + switch ((int)data) { + case 1: + var->factor = v * 65536; + break; + + default: + return -1; + } + return 0; +} + +static int lowpass_threshold(struct tslib_module_info *inf, char *str, + void *data) +{ + struct tslib_lowpass *var = (struct tslib_lowpass *)inf; + long result; + int err = errno; + + result = strtol(str,NULL,0); + if (errno == ERANGE) + return -1; + + errno = err; + + switch ((int)data) { + case 1: + var->threshold = result; + break; + default: + return -1; + } + return 0; +} + +static const struct tslib_vars lowpass_vars[] = +{ + { "factor", (void *)1, lowpass_factor }, + { "threshold", (void*) 1, lowpass_threshold }, +}; + +#define NR_VARS (sizeof(lowpass_vars) / sizeof(lowpass_vars[0])) + +TSAPI struct tslib_module_info *mod_init(struct tsdev *dev, const char *params) +{ + struct tslib_lowpass *var; + + var = malloc(sizeof(struct tslib_lowpass)); + if (var == NULL) + return NULL; + + memset(var, 0, sizeof *var); + var->module.ops = &lowpass_ops; + + var->factor = 0.4 * 65536; + var->threshold = 2; + var->flags = VAR_PENUP; + + if (tslib_parse_vars(&var->module, lowpass_vars, NR_VARS, params)) { + free(var); + return NULL; + } + + return &var->module; +} diff --git a/recipes/tslib/tslib_1.0.bb b/recipes/tslib/tslib_1.0.bb index 277e0a7c29..fe13f2b222 100644 --- a/recipes/tslib/tslib_1.0.bb +++ b/recipes/tslib/tslib_1.0.bb @@ -2,7 +2,15 @@ SRC_URI = "http://download.berlios.de/tslib/${BP}.tar.bz2 \ file://fix_version.patch;patch=1 \ file://tslib-nopressure.patch;patch=1 \ file://tslib-pluginsld.patch;patch=1 \ - file://newer-libtool-fix.patch;patch=1 " -PR = "${INC_PR}.5" + file://newer-libtool-fix.patch;patch=1 \ + file://add_lowpass_plugin.patch;patch=1 \ + file://lowpass.c \ +" + +PR = "${INC_PR}.6" + +do_configure_prepend() { + cp ${WORKDIR}/lowpass.c ${S}/plugins/ +} include tslib.inc -- 2.39.5