On Sun, Nov 14, 2010 at 9:08 AM, <ch...@cnpbagwell.com> wrote: > From: Chris Bagwell <ch...@cnpbagwell.com> > > This helps abstract out filtering better and also allows > custom behavior on storing of samples as well; such as not > moving avg window if no X/Y values have changed in current > event cycle.
I am a bit confused with the last sentence above. I think we move the window even X/Y values stay the same. The code looks like that. The patch set looks fine to me. > Intent of this change is refactor only (no behavior change). > Most off diff is moving logic over to wcmFilter.c. There is minor > flow difference because RawFilter() and wcmCheckSuppress() needs > to be kept in wcmCommon.c, and so outside logic that stores samples, > but intent is same results. > > Signed-off-by: Chris Bagwell <ch...@cnpbagwell.com> Reviewed-by: Ping Cheng <pingli...@gmail.com> Ping > --- > src/wcmCommon.c | 81 +++++++++++++----------------------------------------- > src/wcmFilter.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++-- > src/wcmFilter.h | 1 + > 3 files changed, 94 insertions(+), 64 deletions(-) > > diff --git a/src/wcmCommon.c b/src/wcmCommon.c > index 1a87027..9bb5afb 100644 > --- a/src/wcmCommon.c > +++ b/src/wcmCommon.c > @@ -23,6 +23,7 @@ > > #include "xf86Wacom.h" > #include "Xwacom.h" > +#include "wcmFilter.h" > #include <xkbsrv.h> > #include <xf86_OSproc.h> > > @@ -37,7 +38,6 @@ > static void transPressureCurve(WacomDevicePtr pDev, WacomDeviceStatePtr > pState); > static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel, > const WacomChannelPtr pChannel, int suppress); > -static void resetSampleCounter(const WacomChannelPtr pChannel); > static void sendAButton(InputInfoPtr pInfo, int button, int mask, > int rx, int ry, int rz, int v3, int v4, int v5); > > @@ -855,13 +855,6 @@ static int wcmCheckSuppress(WacomCommonPtr common, > return returnV; > } > > -/* reset raw data counters for filters */ > -static void resetSampleCounter(const WacomChannelPtr pChannel) > -{ > - pChannel->nSamples = 0; > - pChannel->rawFilter.npoints = 0; > -} > - > /***************************************************************************** > * wcmEvent - > * Handles suppression, transformation, filtering, and event dispatch. > @@ -873,8 +866,7 @@ void wcmEvent(WacomCommonPtr common, unsigned int channel, > WacomDeviceState* pLast; > WacomDeviceState ds; > WacomChannelPtr pChannel; > - WacomFilterState* fs; > - int i, suppress = 0; > + int suppress = 0; > WacomDevicePtr priv = common->wcmDevices; > pChannel = common->wcmChannel + channel; > pLast = &pChannel->valid.state; > @@ -937,62 +929,29 @@ void wcmEvent(WacomCommonPtr common, unsigned int > channel, > wcmTilt2R(&ds); > } > > - fs = &pChannel->rawFilter; > - if (!fs->npoints && ds.proximity) > + /* Optionally filter values only while in proximity */ > + if (RAW_FILTERING(common) && common->wcmModel->FilterRaw && > + ds.proximity && ds.device_type != PAD_ID) > { > - DBG(11, common, "initialize Channel data.\n"); > - /* store channel device state for later use */ > - for (i=common->wcmRawSample - 1; i>=0; i--) > - { > - fs->x[i]= ds.x; > - fs->y[i]= ds.y; > - fs->tiltx[i] = ds.tiltx; > - fs->tilty[i] = ds.tilty; > - } > - ++fs->npoints; > - } else { > - /* Filter raw data, fix hardware defects, perform error > correction */ > - for (i=common->wcmRawSample - 1; i>0; i--) > - { > - fs->x[i]= fs->x[i-1]; > - fs->y[i]= fs->y[i-1]; > - } > - fs->x[0] = ds.x; > - fs->y[0] = ds.y; > - if (HANDLE_TILT(common) && (ds.device_type == STYLUS_ID || > ds.device_type == ERASER_ID)) > - { > - for (i=common->wcmRawSample - 1; i>0; i--) > - { > - fs->tiltx[i]= fs->tiltx[i-1]; > - fs->tilty[i]= fs->tilty[i-1]; > - } > - fs->tiltx[0] = ds.tiltx; > - fs->tilty[0] = ds.tilty; > - } > - /* Optionally filter values while in proximity */ > - if (RAW_FILTERING(common) && common->wcmModel->FilterRaw && > - ds.proximity && ds.device_type != PAD_ID) > - { > - if (!pLast->proximity) > - resetSampleCounter(pChannel); > - > - if (common->wcmModel->FilterRaw(common,pChannel,&ds)) > - { > - DBG(10, common, > - "Raw filtering discarded data.\n"); > - resetSampleCounter(pChannel); > - return; /* discard */ > - } > - } > + /* Start filter fresh when entering proximity */ > + if (!pLast->proximity) > + wcmResetSampleCounter(pChannel); > > - /* Discard unwanted data */ > - suppress = wcmCheckSuppress(common, pLast, &ds); > - if (!suppress) > + if (common->wcmModel->FilterRaw(common,pChannel,&ds)) > { > - return; > + DBG(10, common, "Raw filtering discarded data.\n"); > + wcmResetSampleCounter(pChannel); > + return; /* discard */ > } > } > > + /* Discard unwanted data */ > + suppress = wcmCheckSuppress(common, pLast, &ds); > + if (!suppress) > + { > + return; > + } > + > /* JEJ - Do not move this code without discussing it with me. > * The device state is invariant of any filtering performed below. > * Changing the device state after this point can and will cause > @@ -1018,7 +977,7 @@ void wcmEvent(WacomCommonPtr common, unsigned int > channel, > (ds.device_type != TOUCH_ID)) > commonDispatchDevice(common,channel,pChannel, suppress); > ret: > - resetSampleCounter(pChannel); > + wcmResetSampleCounter(pChannel); > } > > static int idtotype(int id) > diff --git a/src/wcmFilter.c b/src/wcmFilter.c > index f2cbec1..4af4911 100644 > --- a/src/wcmFilter.c > +++ b/src/wcmFilter.c > @@ -35,7 +35,7 @@ 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, WacomFilterStatePtr > state, WacomDeviceStatePtr ds); > +static void filterIntuosStylus(WacomCommonPtr common, WacomChannelPtr > pChannel, WacomDeviceStatePtr ds); > void wcmTilt2R(WacomDeviceStatePtr ds); > > > @@ -80,6 +80,19 @@ void wcmSetPressureCurve(WacomDevicePtr pDev, int x0, int > y0, > pDev->nPressCtrl[3] = y1; > } > > +/* > + * wcmResetSampleCounter -- > + * Device specific filter routines are responcable for storing raw data > + * as well as filtering. wcmResetSampleCounter is called to reset > + * raw counters. > + */ > +void wcmResetSampleCounter(const WacomChannelPtr pChannel) > +{ > + pChannel->nSamples = 0; > + pChannel->rawFilter.npoints = 0; > +} > + > + > static void filterNearestPoint(double x0, double y0, double x1, double y1, > double a, double b, double* x, double* y) > { > @@ -202,16 +215,70 @@ static void filterLine(int* pCurve, int nMax, int x0, > int y0, int x1, int y1) > } > } > } > +static void storeRawSample(WacomCommonPtr common, WacomChannelPtr pChannel, > + WacomDeviceStatePtr ds) > +{ > + WacomFilterState *fs; > + int i; > > + fs = &pChannel->rawFilter; > + if (!fs->npoints) > + { > + DBG(10, common, "initialize channel data.\n"); > + /* Store initial value over whole average window */ > + for (i=common->wcmRawSample - 1; i>=0; i--) > + { > + fs->x[i]= ds->x; > + fs->y[i]= ds->y; > + } > + if (HANDLE_TILT(common) && (ds->device_type == STYLUS_ID || > + ds->device_type == ERASER_ID)) > + { > + for (i=common->wcmRawSample - 1; i>=0; i--) > + { > + fs->tiltx[i] = ds->tiltx; > + fs->tilty[i] = ds->tilty; > + } > + } > + ++fs->npoints; > + } else { > + /* Shift window and insert latest sample */ > + for (i=common->wcmRawSample - 1; i>0; i--) > + { > + fs->x[i]= fs->x[i-1]; > + fs->y[i]= fs->y[i-1]; > + } > + fs->x[0] = ds->x; > + fs->y[0] = ds->y; > + if (HANDLE_TILT(common) && (ds->device_type == STYLUS_ID || > + ds->device_type == ERASER_ID)) > + { > + for (i=common->wcmRawSample - 1; i>0; i--) > + { > + fs->tiltx[i]= fs->tiltx[i-1]; > + fs->tilty[i]= fs->tilty[i-1]; > + } > + fs->tiltx[0] = ds->tiltx; > + fs->tilty[0] = ds->tilty; > + } > + } > +} > /***************************************************************************** > * filterIntuosStylus -- > * Correct some hardware defects we've been seeing in Intuos pads, > * but also cuts down quite a bit on jitter. > ****************************************************************************/ > > -static void filterIntuosStylus(WacomCommonPtr common, WacomFilterStatePtr > state, WacomDeviceStatePtr ds) > +static void filterIntuosStylus(WacomCommonPtr common, > + WacomChannelPtr pChannel, > + WacomDeviceStatePtr ds) > { > int x=0, y=0, tx=0, ty=0, i; > + WacomFilterState *state; > + > + storeRawSample(common, pChannel, ds); > + > + state = &pChannel->rawFilter; > > for ( i=0; i<common->wcmRawSample; i++ ) > { > @@ -250,6 +317,9 @@ int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr > pChannel, > 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; > > @@ -279,7 +349,7 @@ int wcmFilterIntuos(WacomCommonPtr common, > WacomChannelPtr pChannel, > * cannot be fixed, return 1 such that the data is discarded. */ > > if (ds->device_type != CURSOR_ID) > - filterIntuosStylus(common, &pChannel->rawFilter, ds); > + filterIntuosStylus(common, pChannel, ds); > else > wcmFilterCoord(common, pChannel, ds); > > diff --git a/src/wcmFilter.h b/src/wcmFilter.h > index db84dc9..3a8204d 100644 > --- a/src/wcmFilter.h > +++ b/src/wcmFilter.h > @@ -30,6 +30,7 @@ int wcmFilterIntuos(WacomCommonPtr common, WacomChannelPtr > pChannel, > WacomDeviceStatePtr ds); > int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr pChannel, > WacomDeviceStatePtr ds); > +void wcmResetSampleCounter(const WacomChannelPtr pChannel); > > /****************************************************************************/ > #endif /* __XF86_WCMFILTER_H */ > -- > 1.7.3.2 > > > ------------------------------------------------------------------------------ > Centralized Desktop Delivery: Dell and VMware Reference Architecture > Simplifying enterprise desktop deployment and management using > Dell EqualLogic storage and VMware View: A highly scalable, end-to-end > client virtualization framework. Read more! > http://p.sf.net/sfu/dell-eql-dev2dev > _______________________________________________ > Linuxwacom-devel mailing list > Linuxwacom-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel > ------------------------------------------------------------------------------ Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev _______________________________________________ Linuxwacom-devel mailing list Linuxwacom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel