tslib: add lowpass filter
PATCH 1/3 tslib: add lowpass filter
Add the lowpass filter plugin from OpenMoko.
See http://docs.openmoko.org/trac/ticket/1194
Signed-off-by Gustavo Zacarias <[email protected]>
--- package/tslib/tslib_add_lowpass_filter.patch | 227 ++++++++++++++++++++++++++ 1 files changed, 227 insertions(+), 0 deletions(-) create mode 100644 package/tslib/tslib_add_lowpass_filter.patch
package/tslib/tslib_add_lowpass_filter.patch new file +227 -0
@@ -0,0 +1,227 @@ +diff -Nura tslib-860d69ca/configure.ac tslib-lowpass/configure.ac +--- tslib-860d69ca/configure.ac 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-lowpass/configure.ac 2011-02-21 15:47:21.373313497 -0300 +@@ -51,6 +51,7 @@ + + # filters + TSLIB_CHECK_MODULE([linear], [yes], [Enable building of linear scaling]) ++TSLIB_CHECK_MODULE([lowpass], [yes], [Enable building of lowpass filter]) + TSLIB_CHECK_MODULE([dejitter], [yes], [Enable building of dejitter filter]) + TSLIB_CHECK_MODULE([linear-h2200], [yes], [Enable building of linearizing filter for iPAQ h2200]) + TSLIB_CHECK_MODULE([variance], [yes], [Enable building of variance filter]) +diff -Nura tslib-860d69ca/plugins/Makefile.am tslib-lowpass/plugins/Makefile.am +--- tslib-860d69ca/plugins/Makefile.am 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-lowpass/plugins/Makefile.am 2011-02-23 09:16:46.756364384 -0300 +@@ -48,6 +48,12 @@ + UCB1X00_MODULE = + endif + ++if ENABLE_LOWPASS_MODULE ++LOWPASS_MODULE = lowpass.la ++else ++LOWPASS_MODULE = ++endif ++ + if ENABLE_CORGI_MODULE + CORGI_MODULE = corgi.la + else +@@ -104,6 +110,7 @@ + + pluginexec_LTLIBRARIES = \ + $(LINEAR_MODULE) \ ++ $(LOWPASS_MODULE) \ + $(DEJITTER_MODULE) \ + $(VARIANCE_MODULE) \ + $(PTHRES_MODULE) \ +@@ -130,6 +137,10 @@ + linear_la_LDFLAGS = -module $(LTVSN) + linear_la_LIBADD = $(top_builddir)/src/libts.la + ++lowpass_la_SOURCES = lowpass.c ++lowpass_la_LDFLAGS = -module $(LTVSN) ++lowpass_la_LIBADD = $(top_builddir)/src/libts.la ++ + pthres_la_SOURCES = pthres.c + pthres_la_LDFLAGS = -module $(LTVSN) + pthres_la_LIBADD = $(top_builddir)/src/libts.la +diff -Nura tslib-860d69ca/plugins/lowpass.c tslib-lowpass/plugins/lowpass.c +--- tslib-860d69ca/plugins/lowpass.c 1969-12-31 21:00:00.000000000 -0300 ++++ tslib-lowpass/plugins/lowpass.c 2011-02-23 09:09:09.182850897 -0300 +@@ -0,0 +1,166 @@ ++/* ++ * This file is placed under the LGPL. Please see the file ++ * COPYING for more details. ++ * ++ * Very stupid lowpass dejittering filter ++ */ ++#include <errno.h> ++#include <stdio.h> ++#include <stdlib.h> ++#include <string.h> ++#include <limits.h> ++ ++#include "tslib.h" ++#include "tslib-filter.h" ++ ++struct tslib_lowpass { ++ struct tslib_module_info module; ++ struct ts_sample last; ++ struct ts_sample ideal; ++ float 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 *= var->factor; ++ 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 *= var->factor; ++ 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; ++ 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: ++ printf("threshold is now %d\n",result); ++ 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 *lowpass_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; ++ 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; ++} ++ ++#ifndef TSLIB_STATIC_LOWPASS_MODULE ++ TSLIB_MODULE_INIT(lowpass_mod_init); ++#endif +diff -Nura tslib-860d69ca/plugins/plugins.h tslib-lowpass/plugins/plugins.h +--- tslib-860d69ca/plugins/plugins.h 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-lowpass/plugins/plugins.h 2011-02-23 09:09:30.557850884 -0300 +@@ -3,6 +3,7 @@ + + TSLIB_DECLARE_MODULE(linear); + TSLIB_DECLARE_MODULE(dejitter); ++TSLIB_DECLARE_MODULE(lowpass); + TSLIB_DECLARE_MODULE(linear_h2200); + TSLIB_DECLARE_MODULE(variance); + TSLIB_DECLARE_MODULE(pthres);
Signature · 1 line
1.7.3.4
PATCH 2/3 tslib: add median filter
Add the median filter, see..
https://lists.berlios.de/pipermail/tslib-general/2009-October/000241.html
Signed-off-by Gustavo Zacarias <[email protected]>
--- package/tslib/tslib_add_median_filter.patch | 273 +++++++++++++++++++++++++++ 1 files changed, 273 insertions(+), 0 deletions(-) create mode 100644 package/tslib/tslib_add_median_filter.patch
package/tslib/tslib_add_median_filter.patch new file +273 -0
@@ -0,0 +1,273 @@ +diff -Nura tslib-860d69ca/configure.ac tslib-median/configure.ac +--- tslib-860d69ca/configure.ac 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-median/configure.ac 2011-02-22 10:55:44.678979229 -0300 +@@ -50,6 +50,7 @@ + AC_CHECK_FUNCS([gettimeofday memmove memset munmap select strcasecmp strchr strdup strtoul]) + + # filters ++TSLIB_CHECK_MODULE([median], [yes], [Enable building of median filter]) + TSLIB_CHECK_MODULE([linear], [yes], [Enable building of linear scaling]) + TSLIB_CHECK_MODULE([dejitter], [yes], [Enable building of dejitter filter]) + TSLIB_CHECK_MODULE([linear-h2200], [yes], [Enable building of linearizing filter for iPAQ h2200]) +diff -Nura tslib-860d69ca/etc/ts.conf tslib-median/etc/ts.conf +--- tslib-860d69ca/etc/ts.conf 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-median/etc/ts.conf 2011-02-22 10:54:37.689979230 -0300 +@@ -18,6 +18,9 @@ + + # Uncomment if you're using an IBM Arctic II + # module_raw arctic2 ++# ++# If your panel is giving spiky signal applying median filter might help. ++# module median depth=5 + + module pthres pmin=1 + module variance delta=30 +diff -Nura tslib-860d69ca/plugins/Makefile.am tslib-median/plugins/Makefile.am +--- tslib-860d69ca/plugins/Makefile.am 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-median/plugins/Makefile.am 2011-02-24 19:33:53.039195641 -0300 +@@ -90,6 +90,12 @@ + INPUT_MODULE = + endif + ++if ENABLE_MEDIAN_MODULE ++MEDIAN_MODULE = median.la ++else ++MEDIAN_MODULE = ++endif ++ + if ENABLE_LINEAR_H2200_MODULE + H2200_LINEAR_MODULE = linear_h2200.la + else +@@ -113,6 +119,7 @@ + $(H3600_MODULE) \ + $(MK712_MODULE) \ + $(ARCTIC2_MODULE) \ ++ $(MEDIAN_MODULE) \ + $(TATUNG_MODULE) \ + $(H2200_LINEAR_MODULE) \ + $(INPUT_MODULE) \ +@@ -130,6 +137,10 @@ + linear_la_LDFLAGS = -module $(LTVSN) + linear_la_LIBADD = $(top_builddir)/src/libts.la + ++median_la_SOURCES = median.c ++median_la_LDFLAGS = -module $(LTVSN) ++median_la_LIBADD = $(top_builddir)/src/libts.la ++ + pthres_la_SOURCES = pthres.c + pthres_la_LDFLAGS = -module $(LTVSN) + pthres_la_LIBADD = $(top_builddir)/src/libts.la +diff -Nura tslib-860d69ca/plugins/median.c tslib-median/plugins/median.c +--- tslib-860d69ca/plugins/median.c 1969-12-31 21:00:00.000000000 -0300 ++++ tslib-median/plugins/median.c 2011-02-22 11:25:33.560187810 -0300 +@@ -0,0 +1,199 @@ ++/* ++ * tslib/plugins/median.c ++ * ++ * Copyright (C) 2009 Marel ehf ++ * Author K?ri Dav??sson <[email protected]> ++ * ++ * This file is placed under the LGPL. Please see the file ++ * COPYING for more details. ++ * ++ * $Id:$ ++ * ++ * Media filter incomming data ++ */ ++ ++#include <errno.h> ++#include <stdio.h> ++#include <limits.h> ++#include <string.h> ++#include <stdlib.h> ++ ++#include "config.h" ++#include "tslib.h" ++#include "tslib-filter.h" ++ ++#define PREPARESAMPLE( array, context, member ) { int count = context->size; while( count-- ) { array[count] = context->delay[count].member; } } ++ ++struct median_context { ++ struct tslib_module_info module; ++ int size; ++ struct ts_sample * delay; ++ int withsamples; ++}; ++ ++static int comp_int(const void * n1, const void * n2) ++{ ++ int * i1 = (int *) n1; ++ int * i2 = (int *) n2; ++ ++ return *i1 < *i2 ? -1 : 1; ++} ++ ++static int comp_uint(const void * n1, const void * n2) ++{ ++ unsigned int * i1 = (unsigned int *) n1; ++ unsigned int * i2 = (unsigned int *) n2; ++ ++ return *i1 < *i2 ? -1 : 1; ++} ++ ++static void printsamples( char * prefix, int * samples, size_t count ) ++{ ++#ifdef DEBUG ++ size_t j; ++ ++ printf("%s Using %d samples ", prefix, count); ++ for( j = 0; j < count; j++) ++ { ++ printf(" %d", samples[j]); ++ } ++ printf("\n"); ++#endif ++} ++ ++static void printsample( char * prefix, struct ts_sample * s ) ++{ ++#ifdef DEBUG ++ printf( "%s using Point@(%d,%d) with pressure %u\n", prefix, s->x, s->y, s->pressure); ++#endif ++} ++ ++static int median_read(struct tslib_module_info *inf, struct ts_sample *samp, int nr) ++{ ++ struct median_context *c = (struct median_context *)inf; ++ int ret; ++ ++ ret = inf->next->ops->read(inf->next, samp, nr); ++ if( ret > 0 ) { ++ int i; ++ struct ts_sample * s; ++ ++ for (s = samp, i = 0; i < ret; i++, s++) { ++ int sorted[c->size]; ++ unsigned int usorted[c->size]; ++ unsigned int cpress; ++ ++ cpress = s->pressure; ++ ++ memmove( &c->delay[0], &c->delay[1], (c->size - 1) * sizeof( c->delay[0] ) ); ++ c->delay[c->size -1] = *s; ++ ++ PREPARESAMPLE( sorted, c, x ); ++ printsamples( "X Before", sorted, c->size ); ++ qsort( &sorted[0], c->size, sizeof( sorted[0] ), comp_int); ++ s->x = sorted[c->size / 2]; ++ printsamples( "X After", sorted, c->size ); ++ ++ PREPARESAMPLE( sorted, c, y ); ++ printsamples( "Y Before", sorted, c->size ); ++ qsort( &sorted[0], c->size, sizeof( sorted[0] ), comp_int); ++ s->y = sorted[c->size / 2]; ++ printsamples( "Y After", sorted, c->size ); ++ ++ PREPARESAMPLE( usorted, c, pressure ); ++ printsamples( "Pressure Before", usorted, c->size ); ++ qsort( &usorted[0], c->size, sizeof( usorted[0] ), comp_uint); ++ s->pressure = usorted[ c->size / 2]; ++ printsamples( "Pressure After", usorted, c->size ); ++ ++ printsample( "", s ); ++ ++ if( (cpress == 0) && (c->withsamples != 0) ) ++ { /* We have penup */ ++ /* Flush the line we now must wait for c->size / 2 samples untill we get valid data again */ ++ memset( c->delay, 0, sizeof( struct ts_sample) * c->size ); ++ c->withsamples = 0; ++ printf("Pen Up\n"); ++ s->pressure = cpress; ++ } ++ else if( (cpress != 0) && (c->withsamples == 0) ) ++ { /* We have pen down */ ++ c->withsamples = 1; ++ printf("Pen Down\n"); ++ } ++ } ++ } ++ ++ return ret; ++} ++ ++static int median_fini(struct tslib_module_info *inf) ++{ ++ struct median_context * c = ( struct median_context *) inf; ++ ++ free( c->delay ); ++ free(inf); ++ ++ return 0; ++} ++ ++static const struct tslib_ops __ts_input_ops = { ++ .read = median_read, ++ .fini = median_fini, ++}; ++ ++static int median_depth(struct tslib_module_info *inf, char *str, void *data __attribute__(( unused )) ) ++{ ++ struct median_context *m = (struct median_context *)inf; ++ unsigned long v; ++ int err = errno; ++ ++ v = strtoul(str, NULL, 0); ++ ++ if (v == ULONG_MAX && errno == ERANGE) ++ return -1; ++ ++ errno = err; ++ m->delay = malloc( sizeof( struct ts_sample ) * v ); ++ m->size = v; ++ ++ return 0; ++} ++ ++static const struct tslib_vars raw_vars[] = ++{ ++ { "depth", (void *)1, median_depth }, ++}; ++ ++#define NR_VARS (sizeof(raw_vars) / sizeof(raw_vars[0])) ++ ++TSAPI struct tslib_module_info *median_mod_init(struct tsdev *dev __attribute__((unused)), const char *params) ++{ ++ struct median_context *c; ++ ++ c = malloc(sizeof(struct median_context)); ++ if (c == NULL) ++ return NULL; ++ ++ memset( c, 0, sizeof( struct median_context ) ); ++ ++ c->module.ops = &__ts_input_ops; ++ ++ if (tslib_parse_vars(&c->module, raw_vars, NR_VARS, params)) { ++ free(c); ++ return NULL; ++ } ++ ++ if( c->delay == NULL ) ++ { ++ c->delay = malloc( sizeof( struct ts_sample ) * 3 ); ++ c->size = 3; ++ printf("Using default size of 3\n"); ++ } ++ ++ return &(c->module); ++} ++ ++#ifndef TSLIB_STATIC_MEDIAN_MODULE ++ TSLIB_MODULE_INIT(median_mod_init); ++#endif +diff -Nura tslib-860d69ca/plugins/plugins.h tslib-median/plugins/plugins.h +--- tslib-860d69ca/plugins/plugins.h 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-median/plugins/plugins.h 2011-02-22 10:57:43.658979230 -0300 +@@ -2,6 +2,7 @@ + TSAPI struct tslib_module_info *name##_mod_init(struct tsdev *dev, const char *params) + + TSLIB_DECLARE_MODULE(linear); ++TSLIB_DECLARE_MODULE(median); + TSLIB_DECLARE_MODULE(dejitter); + TSLIB_DECLARE_MODULE(linear_h2200); + TSLIB_DECLARE_MODULE(variance);
Signature · 1 line
1.7.3.4
PATCH 3/3 tslib: add skip module
In reply to Gustavo ZacariasAdd the skip module from Nelson Castillo, see...
https://lists.berlios.de/pipermail/tslib-general/2008-December/000150.html
Signed-off-by Gustavo Zacarias <[email protected]>
--- package/tslib/tslib_add_skip_module.patch | 273 +++++++++++++++++++++++++++++ 1 files changed, 273 insertions(+), 0 deletions(-) create mode 100644 package/tslib/tslib_add_skip_module.patch
package/tslib/tslib_add_skip_module.patch new file +273 -0
@@ -0,0 +1,273 @@ +diff -Nura tslib-860d69ca/configure.ac tslib-skip/configure.ac +--- tslib-860d69ca/configure.ac 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-skip/configure.ac 2011-02-21 15:42:13.430361989 -0300 +@@ -55,6 +55,7 @@ + TSLIB_CHECK_MODULE([linear-h2200], [yes], [Enable building of linearizing filter for iPAQ h2200]) + TSLIB_CHECK_MODULE([variance], [yes], [Enable building of variance filter]) + TSLIB_CHECK_MODULE([pthres], [yes], [Enable building of pthres filter]) ++TSLIB_CHECK_MODULE([skip], [yes], [Enable building of skip filter]) + + # hardware access modules + TSLIB_CHECK_MODULE([ucb1x00], [yes], [Enable building of ucb1x00 raw module (UCB1x00 support)]) +diff -Nura tslib-860d69ca/plugins/Makefile.am tslib-skip/plugins/Makefile.am +--- tslib-860d69ca/plugins/Makefile.am 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-skip/plugins/Makefile.am 2011-02-21 15:41:35.733219994 -0300 +@@ -42,6 +42,12 @@ + PTHRES_MODULE = + endif + ++if ENABLE_SKIP_MODULE ++SKIP_MODULE = skip.la ++else ++SKIP_MODULE = ++endif ++ + if ENABLE_UCB1X00_MODULE + UCB1X00_MODULE = ucb1x00.la + else +@@ -107,6 +113,7 @@ + $(DEJITTER_MODULE) \ + $(VARIANCE_MODULE) \ + $(PTHRES_MODULE) \ ++ $(SKIP_MODULE) \ + $(UCB1X00_MODULE) \ + $(CORGI_MODULE) \ + $(COLLIE_MODULE) \ +@@ -134,6 +141,9 @@ + pthres_la_LDFLAGS = -module $(LTVSN) + pthres_la_LIBADD = $(top_builddir)/src/libts.la + ++skip_la_SOURCES = skip.c ++skip_la_LDFLAGS = -module $(LTVSN) ++ + # hw access + corgi_la_SOURCES = corgi-raw.c + corgi_la_LDFLAGS = -module $(LTVSN) +diff -Nura tslib-860d69ca/plugins/plugins.h tslib-skip/plugins/plugins.h +--- tslib-860d69ca/plugins/plugins.h 2010-12-21 12:19:51.000000000 -0300 ++++ tslib-skip/plugins/plugins.h 2011-02-22 10:32:26.733378036 -0300 +@@ -6,6 +6,7 @@ + TSLIB_DECLARE_MODULE(linear_h2200); + TSLIB_DECLARE_MODULE(variance); + TSLIB_DECLARE_MODULE(pthres); ++TSLIB_DECLARE_MODULE(skip); + + TSLIB_DECLARE_MODULE(ucb1x00); + TSLIB_DECLARE_MODULE(corgi); +diff -Nura tslib-860d69ca/plugins/skip.c tslib-skip/plugins/skip.c +--- tslib-860d69ca/plugins/skip.c 1969-12-31 21:00:00.000000000 -0300 ++++ tslib-skip/plugins/skip.c 2011-02-22 11:24:58.441637249 -0300 +@@ -0,0 +1,213 @@ ++/* ++ * tslib/plugins/skip.c ++ * ++ * (C) 2008 by Openmoko, Inc. ++ * Author: Nelson Castillo <[email protected]> ++ * ++ * This file is placed under the LGPL. Please see the file ++ * COPYING for more details. ++ * ++ * $Id$ ++ * ++ * Skip filter for touchscreen values. ++ * ++ * Problem: With some drivers the first and the last sample is unreliable. ++ * ++ * Solution: ++ * ++ * - Skip N points after pressure != 0 ++ * - Skip M points before pressure == 0 ++ * - Ignore a click if it has less than N + M + 1 points ++ * ++ * Parameters: ++ * ++ * - nhead (means N) ++ * - ntail (means M) ++ * ++ */ ++ ++#include <errno.h> ++#include <stdio.h> ++#include <stdlib.h> ++#include <string.h> ++#include <limits.h> ++ ++#include "config.h" ++#include "tslib.h" ++#include "tslib-filter.h" ++ ++struct tslib_skip { ++ struct tslib_module_info module; ++ ++ int nhead; ++ int N; ++ ++ int ntail; ++ int M; ++ struct ts_sample *buf; ++ int sent; ++}; ++ ++static void reset_skip(struct tslib_skip *s) ++{ ++ s->N = 0; ++ s->M = 0; ++ s->sent = 0; ++} ++ ++static int skip_read(struct tslib_module_info *info, struct ts_sample *samp, ++ int nr) ++{ ++ struct tslib_skip *skip = (struct tslib_skip *)info; ++ int nread = 0; ++ ++ while (nread < nr) { ++ struct ts_sample cur; ++ ++ if (info->next->ops->read(info->next, &cur, 1) < 1) ++ return nread; ++ ++ /* skip the first N samples */ ++ if (skip->N < skip->nhead) { ++ skip->N++; ++ if (cur.pressure == 0) ++ reset_skip(skip); ++ continue; ++ } ++ ++ /* We didn't send DOWN -- Ignore UP */ ++ if (cur.pressure == 0 && skip->sent == 0) { ++ reset_skip(skip); ++ continue; ++ } ++ ++ /* Just accept the sample if ntail is zero */ ++ if (skip->ntail == 0) { ++ samp[nread++] = cur; ++ skip->sent = 1; ++ if (cur.pressure == 0) ++ reset_skip(skip); ++ continue; ++ } ++ ++ /* ntail > 0, Queue current point if we need to */ ++ if (skip->sent == 0 && skip->M < skip->ntail) { ++ skip->buf[skip->M++] = cur; ++ continue; ++ } ++ ++ /* queue full, accept one, queue one */ ++ ++ if (skip->M >= skip->ntail) ++ skip->M = 0; ++ ++ if (cur.pressure == 0) ++ skip->buf[skip->M].pressure = 0; ++ ++ samp[nread++] = skip->buf[skip->M]; ++ ++#ifdef DEBUG ++ fprintf(stderr, "skip---> (X:%d Y:%d) pressure:%d\n", ++ skip->buf[skip->M].x, skip->buf[skip->M].y, ++ skip->buf[skip->M].pressure); ++#endif ++ ++ if (cur.pressure == 0) { ++ reset_skip(skip); ++ } else { ++ skip->buf[skip->M++] = cur; ++ skip->sent = 1; ++ } ++ } ++ ++ return nread; ++} ++ ++static int skip_fini(struct tslib_module_info *info) ++{ ++ struct tslib_skip *skip = (struct tslib_skip *)info; ++ ++ if (skip->buf) ++ free(skip->buf); ++ ++ free(info); ++ ++ return 0; ++} ++ ++static const struct tslib_ops skip_ops = ++{ ++ .read = skip_read, ++ .fini = skip_fini, ++}; ++ ++static int skip_opt(struct tslib_module_info *inf, char *str, void *data) ++{ ++ struct tslib_skip *skip = (struct tslib_skip *)inf; ++ unsigned long v; ++ int err = errno; ++ ++ v = strtoul(str, NULL, 0); ++ ++ if (v == ULONG_MAX && errno == ERANGE) ++ return -1; ++ ++ errno = err; ++ ++ switch ((int)data) { ++ case 1: ++ skip->nhead = v; ++ break; ++ ++ case 2: ++ skip->ntail = v; ++ break; ++ ++ default: ++ return -1; ++ } ++ return 0; ++} ++ ++static const struct tslib_vars skip_vars[] = ++{ ++ { "nhead", (void *)1, skip_opt }, ++ { "ntail", (void *)2, skip_opt }, ++}; ++ ++#define NR_VARS (sizeof(skip_vars) / sizeof(skip_vars[0])) ++ ++TSAPI struct tslib_module_info *skip_mod_init(struct tsdev *dev, const char *params) ++{ ++ struct tslib_skip *skip; ++ ++ skip = malloc(sizeof(struct tslib_skip)); ++ if (skip == NULL) ++ return NULL; ++ ++ memset(skip, 0, sizeof(struct tslib_skip)); ++ skip->module.ops = &skip_ops; ++ ++ skip->nhead = 1; /* by default remove the first */ ++ skip->ntail = 1; /* by default remove the last */ ++ skip->buf = NULL; ++ ++ reset_skip(skip); ++ ++ if (tslib_parse_vars(&skip->module, skip_vars, NR_VARS, params)) { ++ free(skip); ++ return NULL; ++ } ++ ++ if (skip->ntail && ++ !(skip->buf = malloc(sizeof(struct ts_sample) * skip->ntail))) { ++ free(skip); ++ return NULL; ++ } ++ ++ return &skip->module; ++} ++ ++#ifndef TSLIB_STATIC_SKIP_MODULE ++ TSLIB_MODULE_INIT(skip_mod_init); ++#endif
Signature · 1 line
1.7.3.4
PATCH 1/3 tslib: add lowpass filter
In reply to Gustavo ZacariasQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Gustavo" == Gustavo Zacarias <[email protected]> writes:
Gustavo> Add the lowpass filter plugin from OpenMoko. Gustavo> See http://docs.openmoko.org/trac/ticket/1194
Couldn't these patches simply be added upstream now tslib has an active maintainer?
Signature · 1 line
Bye, Peter Korsgaard