From: Chris Bagwell <ch...@cnpbagwell.com>

The two filter routines were doing exact same math.
The only different is some devices needed to filter
tilt X/Y values in addition to standard X/Y.

Storing of raw samples had already been converted to detect
tilt generically.  Now Convert filter routine to detect
generically which then makes it usable by all tools.

Signed-off-by: Chris Bagwell <ch...@cnpbagwell.com>
---

While I'm testing filter improvements, it seems a waste to make
changes in two places. when functionality is mean to be same.

 src/wcmFilter.c |   94 ++++++++++++++----------------------------------------
 src/wcmFilter.h |    2 -
 src/wcmUSB.c    |   41 ++++++++++++------------
 3 files changed, 45 insertions(+), 92 deletions(-)

diff --git a/src/wcmFilter.c b/src/wcmFilter.c
index 4af4911..ff3c68f 100644
--- a/src/wcmFilter.c
+++ b/src/wcmFilter.c
@@ -35,7 +35,6 @@ static void filterCurveToLine(int* pCurve, int nMax, double 
x0, double y0,
 static int filterOnLine(double x0, double y0, double x1, double y1,
                double a, double b);
 static void filterLine(int* pCurve, int nMax, int x0, int y0, int x1, int y1);
-static void filterIntuosStylus(WacomCommonPtr common, WacomChannelPtr 
pChannel, WacomDeviceStatePtr ds);
 void wcmTilt2R(WacomDeviceStatePtr ds);
 
 
@@ -263,19 +262,19 @@ static void storeRawSample(WacomCommonPtr common, 
WacomChannelPtr pChannel,
                }
        }
 }
+
 /*****************************************************************************
- * filterIntuosStylus --
- *   Correct some hardware defects we've been seeing in Intuos pads,
- *   but also cuts down quite a bit on jitter.
+ * wcmFilterCoord -- provide noise correction to all transducers
  ****************************************************************************/
 
-static void filterIntuosStylus(WacomCommonPtr common,
-                              WacomChannelPtr pChannel,
-                              WacomDeviceStatePtr ds)
+int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr pChannel,
+       WacomDeviceStatePtr ds)
 {
        int x=0, y=0, tx=0, ty=0, i;
        WacomFilterState *state;
 
+       DBG(10, common, "common->wcmRawSample = %d \n", common->wcmRawSample);
+
        storeRawSample(common, pChannel, ds);
 
        state = &pChannel->rawFilter;
@@ -284,74 +283,31 @@ static void filterIntuosStylus(WacomCommonPtr common,
        {
                x += state->x[i];
                y += state->y[i];
-               tx += state->tiltx[i];
-               ty += state->tilty[i];
+               if (HANDLE_TILT(common) && (ds->device_type == STYLUS_ID ||
+                                           ds->device_type == ERASER_ID))
+               {
+                       tx += state->tiltx[i];
+                       ty += state->tilty[i];
+               }
        }
        ds->x = x / common->wcmRawSample;
        ds->y = y / common->wcmRawSample;
 
-       ds->tiltx = tx / common->wcmRawSample;
-       if (ds->tiltx > common->wcmMaxtiltX/2-1)
-               ds->tiltx = common->wcmMaxtiltX/2-1;    
-       else if (ds->tiltx < -common->wcmMaxtiltX/2)
-               ds->tiltx = -common->wcmMaxtiltX/2;
-
-       ds->tilty = ty / common->wcmRawSample;
-       if (ds->tilty > common->wcmMaxtiltY/2-1)
-               ds->tilty = common->wcmMaxtiltY/2-1;    
-       else if (ds->tilty < -common->wcmMaxtiltY/2)
-               ds->tilty = -common->wcmMaxtiltY/2;
-}
-
-/*****************************************************************************
- * wcmFilterCoord -- provide noise correction to all transducers
- ****************************************************************************/
-
-int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr pChannel,
-       WacomDeviceStatePtr ds)
-{
-       /* Only noise correction should happen here. If there's a problem that
-        * cannot be fixed, return 1 such that the data is discarded. */
-
-       WacomDeviceState *pLast;
-       int *x, *y, i; 
-
-       DBG(10, common, "common->wcmRawSample = %d \n", common->wcmRawSample);
-
-       storeRawSample(common, pChannel, ds);
-
-       x = pChannel->rawFilter.x;
-       y = pChannel->rawFilter.y;
-
-       pLast = &pChannel->valid.state;
-       ds->x = 0;
-       ds->y = 0;
-
-       for ( i=0; i<common->wcmRawSample; i++ )
+       if (HANDLE_TILT(common) && (ds->device_type == STYLUS_ID ||
+                                   ds->device_type == ERASER_ID))
        {
-               ds->x += x[i];
-               ds->y += y[i];
+               ds->tiltx = tx / common->wcmRawSample;
+               if (ds->tiltx > common->wcmMaxtiltX/2-1)
+                       ds->tiltx = common->wcmMaxtiltX/2-1;
+               else if (ds->tiltx < -common->wcmMaxtiltX/2)
+                       ds->tiltx = -common->wcmMaxtiltX/2;
+
+               ds->tilty = ty / common->wcmRawSample;
+               if (ds->tilty > common->wcmMaxtiltY/2-1)
+                       ds->tilty = common->wcmMaxtiltY/2-1;
+               else if (ds->tilty < -common->wcmMaxtiltY/2)
+                       ds->tilty = -common->wcmMaxtiltY/2;
        }
-       ds->x /= common->wcmRawSample;
-       ds->y /= common->wcmRawSample;
-
-       return 0; /* lookin' good */
-}
-
-/*****************************************************************************
- * wcmFilterIntuos -- provide error correction to Intuos and Intuos2
- ****************************************************************************/
-
-int wcmFilterIntuos(WacomCommonPtr common, WacomChannelPtr pChannel,
-       WacomDeviceStatePtr ds)
-{
-       /* Only error correction should happen here. If there's a problem that
-        * cannot be fixed, return 1 such that the data is discarded. */
-
-       if (ds->device_type != CURSOR_ID)
-               filterIntuosStylus(common, pChannel, ds);
-       else
-               wcmFilterCoord(common, pChannel, ds);
 
        return 0; /* lookin' good */
 }
diff --git a/src/wcmFilter.h b/src/wcmFilter.h
index 3a8204d..be86eb5 100644
--- a/src/wcmFilter.h
+++ b/src/wcmFilter.h
@@ -26,8 +26,6 @@
 
 void wcmSetPressureCurve(WacomDevicePtr pDev, int x0, int y0,
        int x1, int y1);
-int wcmFilterIntuos(WacomCommonPtr common, WacomChannelPtr pChannel,
-       WacomDeviceStatePtr ds);
 int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr pChannel,
        WacomDeviceStatePtr ds);
 void wcmResetSampleCounter(const WacomChannelPtr pChannel);
diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index 90e8cf6..3b979bf 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -66,7 +66,7 @@ static int usbChooseChannel(WacomCommonPtr common);
                usbProbeKeys
        };
 
-#define DEFINE_MODEL(mname, identifier, protocol, filter) \
+#define DEFINE_MODEL(mname, identifier, protocol) \
 static struct _WacomModel mname =              \
 {                                              \
        .name = identifier,                     \
@@ -75,29 +75,28 @@ static struct _WacomModel mname =           \
        .GetRanges = usbWcmGetRanges,           \
        .Start = usbStart,                      \
        .Parse = usbParse,                      \
-       .FilterRaw = filter,                    \
        .DetectConfig = usbDetectConfig,        \
 };
 
-DEFINE_MODEL(usbUnknown,       "Unknown USB",          5, NULL);
-DEFINE_MODEL(usbPenPartner,    "USB PenPartner",       4, wcmFilterCoord);
-DEFINE_MODEL(usbGraphire,      "USB Graphire",         4, wcmFilterCoord);
-DEFINE_MODEL(usbGraphire2,     "USB Graphire2",        4, wcmFilterCoord);
-DEFINE_MODEL(usbGraphire3,     "USB Graphire3",        4, wcmFilterCoord);
-DEFINE_MODEL(usbGraphire4,     "USB Graphire4",        4, wcmFilterCoord);
-DEFINE_MODEL(usbBamboo,                "USB Bamboo",           4, 
wcmFilterCoord);
-DEFINE_MODEL(usbBamboo1,       "USB Bamboo1",          4, wcmFilterCoord);
-DEFINE_MODEL(usbBambooFun,     "USB BambooFun",        4, wcmFilterCoord);
-DEFINE_MODEL(usbCintiq,                "USB PL/Cintiq",        4, NULL);
-DEFINE_MODEL(usbCintiqPartner, "USB CintiqPartner",    4, NULL);
-DEFINE_MODEL(usbIntuos,                "USB Intuos1",          5, 
wcmFilterIntuos);
-DEFINE_MODEL(usbIntuos2,       "USB Intuos2",          5, wcmFilterIntuos);
-DEFINE_MODEL(usbIntuos3,       "USB Intuos3",          5, wcmFilterIntuos);
-DEFINE_MODEL(usbIntuos4,       "USB Intuos4",          5, wcmFilterIntuos);
-DEFINE_MODEL(usbVolito,                "USB Volito",           4, 
wcmFilterCoord);
-DEFINE_MODEL(usbVolito2,       "USB Volito2",          4, wcmFilterCoord);
-DEFINE_MODEL(usbCintiqV5,      "USB CintiqV5",         5, wcmFilterIntuos);
-DEFINE_MODEL(usbTabletPC,      "USB TabletPC",         4, NULL);
+DEFINE_MODEL(usbUnknown,       "Unknown USB",          5)
+DEFINE_MODEL(usbPenPartner,    "USB PenPartner",       4);
+DEFINE_MODEL(usbGraphire,      "USB Graphire",         4);
+DEFINE_MODEL(usbGraphire2,     "USB Graphire2",        4);
+DEFINE_MODEL(usbGraphire3,     "USB Graphire3",        4);
+DEFINE_MODEL(usbGraphire4,     "USB Graphire4",        4);
+DEFINE_MODEL(usbBamboo,                "USB Bamboo",           4);
+DEFINE_MODEL(usbBamboo1,       "USB Bamboo1",          4);
+DEFINE_MODEL(usbBambooFun,     "USB BambooFun",        4);
+DEFINE_MODEL(usbCintiq,                "USB PL/Cintiq",        4);
+DEFINE_MODEL(usbCintiqPartner, "USB CintiqPartner",    4);
+DEFINE_MODEL(usbIntuos,                "USB Intuos1",          5);
+DEFINE_MODEL(usbIntuos2,       "USB Intuos2",          5);
+DEFINE_MODEL(usbIntuos3,       "USB Intuos3",          5);
+DEFINE_MODEL(usbIntuos4,       "USB Intuos4",          5);
+DEFINE_MODEL(usbVolito,                "USB Volito",           4);
+DEFINE_MODEL(usbVolito2,       "USB Volito2",          4);
+DEFINE_MODEL(usbCintiqV5,      "USB CintiqV5",         5);
+DEFINE_MODEL(usbTabletPC,      "USB TabletPC",         4);
 
 /*****************************************************************************
  * usbDetect --
-- 
1.7.3.2


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to