Ticket #4731: wacom_filter.patch

File wacom_filter.patch, 2.5 KB (added by idefix, 15 years ago)

patch implementing moving average filter in Wacom input_server addon

  • src/add-ons/input_server/devices/wacom/TabletDevice.h

     
    1414
    1515#include "PointingDevice.h"
    1616
     17#define MAX_FILTER_SAMPLES 4
     18
    1719class TabletDevice : public PointingDevice {
    1820 public:
    1921                                TabletDevice(MasterServerDevice* parent,
     
    108110
    109111            float               fJitterX;
    110112            float               fJitterY;
     113
     114            float               fFilterX[MAX_FILTER_SAMPLES];
     115            float               fFilterY[MAX_FILTER_SAMPLES];
    111116};
    112117
    113118#endif  // WACOM_TABLET_H
  • src/add-ons/input_server/devices/wacom/TabletDevice.cpp

     
    230230    fMaxY = maxY;
    231231    fJitterX = JITTER_X;
    232232    fJitterY = JITTER_Y;
     233    for (int i = 0; i < MAX_FILTER_SAMPLES; i++) {
     234        fFilterX[i] = 0.0;
     235        fFilterY[i] = 0.0;
     236    }
    233237}
    234238
    235239// ReadData
     
    427431        float unfilteredY = y;
    428432
    429433        if (fHasContact) {
     434            // apply a bit of filtering
     435            for (int i = 0; i < MAX_FILTER_SAMPLES - 1; i++) {
     436                fFilterX[i] = fFilterX[i + 1];
     437                fFilterY[i] = fFilterY[i + 1];
     438                x += fFilterX[i];
     439                y += fFilterY[i];
     440            }
     441            fFilterX[MAX_FILTER_SAMPLES - 1] = unfilteredX;
     442            fFilterY[MAX_FILTER_SAMPLES - 1] = unfilteredY;
     443            x /= MAX_FILTER_SAMPLES;
     444            y /= MAX_FILTER_SAMPLES;
     445
    430446            deltaX = x - fPosX;
    431447            deltaY = y - fPosY;
    432448
    433449            absDeltaX = fabsf(deltaX);
    434450            absDeltaY = fabsf(deltaY);
    435 
    436 #if 0 //DEBUG
    437 fParent->LogString() << "x: " << x << ", y: " << y << ", pressure: " << pressure << "\n";
    438 fParent->LogString() << "tilt x: " << tiltX << ", tilt y: " << tiltY << "\n\n";
    439 #endif
    440             // apply a bit of filtering
    441             if (absDeltaX < fJitterX)
    442                 x = fPosX;
    443             if (absDeltaY < fJitterY)
    444                 y = fPosY;
     451        } else {
     452            for (int i = 0; i < MAX_FILTER_SAMPLES; i++) {
     453                fFilterX[i] = x;
     454                fFilterY[i] = y;
     455            }
    445456        }
    446457   
    447458        // only do send message if something changed
     
    468479                // adjust mouse coordinates as well
    469480                // to have the mouse appear at the pens
    470481                // last position when switching
    471                 fFakeMouseX = unfilteredX;
    472                 fFakeMouseY = unfilteredY;
     482                fFakeMouseX = x;
     483                fFakeMouseY = y;
    473484            } else if (mode == MODE_MOUSE) {
    474485                // apply acceleration
    475486                float accelerationX = fJitterX * ACCELERATION_KICK_IN;