diff options
author | Jason Gerecke <killertofu@gmail.com> | 2017-12-08 13:55:31 -0800 |
---|---|---|
committer | Jason Gerecke <killertofu@gmail.com> | 2017-12-15 11:02:53 -0800 |
commit | 527fa95c29f6aee2c2d655e834ff3f45a9160c06 (patch) | |
tree | b3ae1127aca6341743f5f32723894bfea3380f10 | |
parent | 7d6bded43bab93f8cc882c4e8b0fdc834e44208e (diff) | |
download | xf86-input-wacom-527fa95c29f6aee2c2d655e834ff3f45a9160c06.tar.gz |
Refactor coordinate averaging to seperate function
Moves the averaging code used by the driver's filter functions into a
seperate function to make the operation of wcm_filter_coord more clear.
Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Reviewed-by: Ping Cheng <ping.cheng@wacom.com>
-rw-r--r-- | src/wcmFilter.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/wcmFilter.c b/src/wcmFilter.c index e7ddb37..15ce1c8 100644 --- a/src/wcmFilter.c +++ b/src/wcmFilter.c @@ -276,6 +276,18 @@ static void storeRawSample(WacomCommonPtr common, WacomChannelPtr pChannel, } } +static int wcmFilterAverage(int *samples, int n) +{ + int x = 0; + int i; + + for (i = 0; i < n; i++) + { + x += samples[i]; + } + return x / n; +} + /***************************************************************************** * wcmFilterCoord -- provide noise correction to all transducers ****************************************************************************/ @@ -283,7 +295,6 @@ static void storeRawSample(WacomCommonPtr common, WacomChannelPtr pChannel, 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); @@ -292,30 +303,18 @@ int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr pChannel, state = &pChannel->rawFilter; - for ( i=0; i<common->wcmRawSample; i++ ) - { - x += state->x[i]; - y += state->y[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->x = wcmFilterAverage(state->x, common->wcmRawSample); + ds->y = wcmFilterAverage(state->y, common->wcmRawSample); if (HANDLE_TILT(common) && (ds->device_type == STYLUS_ID || ds->device_type == ERASER_ID)) { - ds->tiltx = tx / common->wcmRawSample; + ds->tiltx = wcmFilterAverage(state->tiltx, common->wcmRawSample); if (ds->tiltx > common->wcmTiltMaxX) ds->tiltx = common->wcmTiltMaxX; else if (ds->tiltx < common->wcmTiltMinX) ds->tiltx = common->wcmTiltMinX; - ds->tilty = ty / common->wcmRawSample; + ds->tilty = wcmFilterAverage(state->tiltx, common->wcmRawSample); if (ds->tilty > common->wcmTiltMaxY) ds->tilty = common->wcmTiltMaxY; else if (ds->tilty < common->wcmTiltMinY) |