On Tue, Nov 23, 2010 at 03:11:12PM -0600, ch...@cnpbagwell.com wrote: > From: Chris Bagwell <ch...@cnpbagwell.com> > > Combining filter routines to reduce upkeep and > keep all step step of filtering aligned. > > There are two steps in filtering. 1) Storing filter and > 2) filtering samples. > > Stage #1 is storing X/Y and optionally storing > tiltX/tiltY based on HANDLE_TILT(). > > Stage #2 is filtering value. It uses device specific > callbacks to filter. There are 2 ways currently. > Both ways filter X/Y use same math but second also > filters tiltX/tiltY. > > It seems reasonable to do tiltX/tiltY filtering > decision at runtime using HANDLE_TILT() to align > both steps and reduce duplication. > > Signed-off-by: Chris Bagwell <ch...@cnpbagwell.com> > --- > src/wcmFilter.c | 94 ++++++++++++++---------------------------------------- > src/wcmFilter.h | 2 - > src/wcmUSB.c | 42 ++++++++++++------------ > 3 files changed, 46 insertions(+), 92 deletions(-) > > diff --git a/src/wcmFilter.c b/src/wcmFilter.c > index 6e4a810..9f4f366 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); > > > @@ -265,19 +264,19 @@ static void storeRawSample(WacomCommonPtr common, > WacomChannelPtr pChannel, > ++fs->npoints; > } > } > + > > /***************************************************************************** > - * 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; > @@ -286,74 +285,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..6ee7472 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,29 @@ static struct _WacomModel mname = \ > .GetRanges = usbWcmGetRanges, \ > .Start = usbStart, \ > .Parse = usbParse, \ > - .FilterRaw = filter, \ > + .FilterRaw = wcmFilterCoord, \ > .DetectConfig = usbDetectConfig, \ > };
if this is always set anyway, we don't need the model-specific function pointer. Please send me a follow-up patch to call wcmFilterCoord() directly from the respective places. all three patches merged Cheers, Peter > > -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 ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ Linuxwacom-devel mailing list Linuxwacom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel