Skip to content
This repository was archived by the owner on Sep 21, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions TabletDriverService/CommandHandler.Filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,30 @@ void CommandHandler::CreateFilterCommands() {
}));


// Command: ButtonFix, ButtonFix
//
// Sets ButtonFix filter parameters
//
AddAlias("ButtonFix", "ButtonFixAdd");
AddCommand(new Command("ButtonFixAdd", [&](CommandLine* cmd) {

// Tablet valid?
if (!ExecuteCommand("TabletValid")) return false;

std::string stringValue = cmd->GetStringLower(0, "");

// Off / False
if (stringValue == "off" || stringValue == "false") {
tablet->buttonFix.isEnabled = false;
LOG_INFO("Button Fix = off\n");
}
else {
tablet->buttonFix.isEnabled = true;
LOG_INFO("Button Fix = on\n");
}
return true;
}));


//
// Command: FilterTimerInterval, TimerInterval, Interval
Expand Down
7 changes: 4 additions & 3 deletions TabletDriverService/Tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ Tablet::Tablet() {
filterTimedCount = 3;

// Report filters
filterReport[0] = &antiSmoothing;
filterReport[1] = &noiseFilter;
filterReportCount = 2;
filterReport[0] = &buttonFix;
filterReport[1] = &antiSmoothing;
filterReport[2] = &noiseFilter;
filterReportCount = 3;

// Tablet connection open
isOpen = false;
Expand Down
2 changes: 2 additions & 0 deletions TabletDriverService/Tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "TabletFilterNoiseReduction.h"
#include "TabletFilterAntiSmoothing.h"
#include "TabletFilterPeak.h"
#include "TabletFilterButtonFix.h"
#include "TabletMeasurement.h"
#include "DataFormatter.h"

Expand Down Expand Up @@ -164,6 +165,7 @@ class Tablet {
TabletFilterNoiseReduction noiseFilter;
TabletFilterAntiSmoothing antiSmoothing;
TabletFilterGravity gravityFilter;
TabletFilterButtonFix buttonFix;

// Timed filters
TabletFilter *filterTimed[10];
Expand Down
2 changes: 2 additions & 0 deletions TabletDriverService/TabletDriverService.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<ClInclude Include="Tablet.h" />
<ClInclude Include="TabletFilterAdvancedSmoothing.h" />
<ClInclude Include="TabletFilterAntiSmoothing.h" />
<ClInclude Include="TabletFilterButtonFix.h" />
<ClInclude Include="TabletFilterGravity.h" />
<ClInclude Include="TabletFilterTester.h" />
<ClInclude Include="TabletHandler.h" />
Expand Down Expand Up @@ -239,6 +240,7 @@
<ClCompile Include="Tablet.cpp" />
<ClCompile Include="TabletFilterAdvancedSmoothing.cpp" />
<ClCompile Include="TabletFilterAntiSmoothing.cpp" />
<ClCompile Include="TabletFilterButtonFix.cpp" />
<ClCompile Include="TabletFilterGravity.cpp" />
<ClCompile Include="TabletFilterTester.cpp" />
<ClCompile Include="TabletHandler.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions TabletDriverService/TabletDriverService.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<ClInclude Include="precompiled.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TabletFilterButtonFix.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="HIDDevice.cpp">
Expand Down Expand Up @@ -289,6 +292,9 @@
</ClCompile>
<ClCompile Include="precompiled.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TabletFilterButtonFix.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down
72 changes: 72 additions & 0 deletions TabletDriverService/TabletFilterButtonFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "precompiled.h"
#include "TabletFilterButtonFix.h"


#define LOG_MODULE "ButtonFix"
#include "Logger.h"


//
// Constructor
//
TabletFilterButtonFix::TabletFilterButtonFix() {
ignoreInvalidReports = 0;
outputPosition = &outputState.position;
}

//
// Destructor
//
TabletFilterButtonFix::~TabletFilterButtonFix() {
}


//
// Set target
//
void TabletFilterButtonFix::SetTarget(TabletState* tabletState) {
latestTarget.Set(tabletState->position);
memcpy(&this->tabletState, tabletState, sizeof(TabletState));
memcpy(&outputState, tabletState, sizeof(TabletState));
}


//
// Update filter
//
void TabletFilterButtonFix::Update() {
//
// Invalid position data detection.
// Some tablets do send invalid/broken data when buttons are released
//

if (tabletState.buttons <= 1 && oldTabletState.buttons > 1 && ignoreInvalidReports == 0) {
//LOG_INFO("RELEASE\n");
tabletState.pressure = oldTabletState.pressure;
tabletState.inputPressure = oldTabletState.inputPressure;
if (oldTabletState.buttons == 5 || oldTabletState.buttons == 3)
tabletState.buttons = 1;
ignoreInvalidReports = 2;
oldTarget.Set(latestTarget);
memcpy(&this->oldTabletState, &this->tabletState, sizeof(TabletState));
return;
}
else if (oldTabletState.buttons <= 1 && tabletState.buttons > 1 && ignoreInvalidReports == 0) {
//LOG_INFO("PRESS\n");
oldTabletState.buttons = tabletState.buttons;
ignoreInvalidReports = 2;
}
if (ignoreInvalidReports == 0) {
// Update old values
oldTarget.Set(latestTarget);
memcpy(&this->oldTabletState, &this->tabletState, sizeof(TabletState));
}
else {
oldTabletState.time = tabletState.time;
tabletState = oldTabletState;
// TODO: extrapolate a new coordinate
outputPosition->Set(oldTarget);
ignoreInvalidReports--;
}
}

23 changes: 23 additions & 0 deletions TabletDriverService/TabletFilterButtonFix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include "TabletFilter.h"

class TabletFilterButtonFix : public TabletFilter {
private:
int ignoreInvalidReports;

public:
Vector2D latestTarget;
Vector2D oldTarget;
Vector2D* outputPosition;

TabletState tabletState;
TabletState oldTabletState;

void SetTarget(TabletState* tabletState);
void Update();

TabletFilterButtonFix();
~TabletFilterButtonFix();

};