Skip to content

Commit f28f392

Browse files
authored
Fix 1000 hz on new Windows versions
1 parent 6da742e commit f28f392

11 files changed

Lines changed: 75 additions & 15 deletions

TabletDriverGUI/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public partial class MainWindow : Window
2424
{
2525

2626
// Version
27-
public string Version = "0.1.5.5 Devocub Edition";
27+
public string Version = "0.1.5.6 Devocub Edition";
2828

2929
// Console stuff
3030
private List<string> commandHistory;

TabletDriverService/Main.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#pragma comment(lib, "hid.lib")
1717
#pragma comment(lib, "setupapi.lib")
1818
#pragma comment(lib, "winusb.lib")
19+
#pragma comment(lib, "winmm.lib")
1920

2021

2122
// Global variables...
@@ -24,6 +25,8 @@ VMulti *vmulti;
2425
ScreenMapper *mapper;
2526
thread *tabletThread;
2627
chrono::high_resolution_clock::time_point timeBegin = chrono::high_resolution_clock::now();
28+
chrono::high_resolution_clock::time_point lastMovement = chrono::high_resolution_clock::now();
29+
Vector2D prevPos;
2730

2831
//
2932
// Init console parameters
@@ -212,7 +215,9 @@ void RunTabletThread() {
212215
//
213216
// Tablet filter timer callback
214217
//
215-
VOID CALLBACK FilterTimerCallback(_In_ PVOID lpParameter, _In_ BOOLEAN TimerOrWaitFired) {
218+
219+
static VOID CALLBACK FilterTimerCallback(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD dw1, DWORD dw2)
220+
{
216221
Vector2D position, position_prev;
217222
double z;
218223
TabletFilter *filter;
@@ -225,6 +230,18 @@ VOID CALLBACK FilterTimerCallback(_In_ PVOID lpParameter, _In_ BOOLEAN TimerOrWa
225230
// For debug
226231
tablet->filterTimed[0]->GetPosition(&position_prev);
227232

233+
// Detect absence of movement
234+
double noMovement = 0.0;
235+
if (position.Distance(prevPos) > 0.000001)
236+
{
237+
lastMovement = timeNow;
238+
prevPos = position;
239+
}
240+
else
241+
{
242+
noMovement = (timeNow - lastMovement).count() / 1000000.0;
243+
}
244+
228245
// Loop through filters
229246
for (int filterIndex = 0; filterIndex < tablet->filterTimedCount; filterIndex++) {
230247

@@ -234,6 +251,13 @@ VOID CALLBACK FilterTimerCallback(_In_ PVOID lpParameter, _In_ BOOLEAN TimerOrWa
234251
// Filter enabled?
235252
if (!filter->isEnabled) return;
236253

254+
255+
if (noMovement > 35)
256+
{
257+
filter->Reset(position);
258+
return;
259+
}
260+
237261
// Set filter targets
238262
filter->SetTarget(position, z);
239263
//filter->z = tablet->state.z;

TabletDriverService/TabletDriverService.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ProjectGuid>{3101CEC2-8F39-45FD-943B-79A488AD05EA}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>TabletDriverService</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

TabletDriverService/TabletFilter.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ TabletFilter::TabletFilter() {
1313
// Start Timer
1414
//
1515
bool TabletFilter::StartTimer() {
16-
return CreateTimerQueueTimer(
17-
&timer,
18-
NULL, callback,
19-
NULL,
20-
0,
21-
(int)timerInterval,
22-
WT_EXECUTEDEFAULT
23-
);
16+
if (timer == NULL) {
17+
MMRESULT result = timeSetEvent(
18+
(UINT)timerInterval,//UINT uDelay,
19+
0,//UINT uResolution,
20+
callback, //LPTIMECALLBACK lpTimeProc,
21+
NULL, //DWORD_PTR dwUser,
22+
TIME_PERIODIC | TIME_KILL_SYNCHRONOUS //UINT fuEvent
23+
);
24+
if (result == NULL) {
25+
return false;
26+
}
27+
else {
28+
timer = (HANDLE)1; // for code compatibility purposes
29+
uTimerID = result;
30+
}
31+
}
32+
return true;
2433
}
2534

2635

@@ -29,9 +38,13 @@ bool TabletFilter::StartTimer() {
2938
//
3039
bool TabletFilter::StopTimer() {
3140
if (timer == NULL) return false;
32-
bool result = DeleteTimerQueueTimer(NULL, timer, NULL);
33-
if (result) {
41+
42+
MMRESULT result = timeKillEvent(uTimerID);
43+
// Returns TIMERR_NOERROR if successful or MMSYSERR_INVALPARAM if the specified timer event does not exist.
44+
if (result == TIMERR_NOERROR)
45+
{
3446
timer = NULL;
47+
return true;
3548
}
36-
return result;
49+
return false;
3750
}

TabletDriverService/TabletFilter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
class TabletFilter {
33
public:
44
virtual void SetTarget(Vector2D vector, double h) = 0;
5+
virtual void Reset(Vector2D vector) = 0;
56
virtual void SetPosition(Vector2D vector, double h) = 0;
67
virtual bool GetPosition(Vector2D *vector) = 0;
78
virtual void Update() = 0;
89

910
HANDLE timer;
10-
WAITORTIMERCALLBACK callback;
11+
UINT uTimerID;
12+
LPTIMECALLBACK callback;
1113
double timerInterval;
1214

1315
bool isEnabled;

TabletDriverService/TabletFilterNoiseReduction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ TabletFilterNoiseReduction::~TabletFilterNoiseReduction() {
2020
// TabletFilter methods
2121
//
2222

23+
// Reset
24+
void TabletFilterNoiseReduction::Reset(Vector2D position) {
25+
lastTarget.Set(position);
26+
buffer.Reset();
27+
}
28+
2329
// Set target position
2430
void TabletFilterNoiseReduction::SetTarget(Vector2D targetVector, double h) {
2531
lastTarget.Set(targetVector);

TabletDriverService/TabletFilterNoiseReduction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class TabletFilterNoiseReduction : public TabletFilter {
1212
int iterations;
1313
double distanceThreshold;
1414

15+
void Reset(Vector2D position);
1516
void SetTarget(Vector2D targetVector, double h);
1617
void SetPosition(Vector2D vector, double h);
1718
bool GetPosition(Vector2D *outputVector);

TabletDriverService/TabletFilterPeak.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ TabletFilterPeak::~TabletFilterPeak() {
2727
//
2828
// TabletFilter methods
2929
//
30+
// reset
31+
void TabletFilterPeak::Reset(Vector2D targetVector) {
32+
buffer.Reset();
33+
}
3034
// Set target position
3135
void TabletFilterPeak::SetTarget(Vector2D targetVector, double h) {
3236
buffer.Add(targetVector);

TabletDriverService/TabletFilterPeak.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class TabletFilterPeak : public TabletFilter {
1010
Vector2D position;
1111
double distanceThreshold;
1212

13+
void Reset(Vector2D targetVector);
1314
void SetTarget(Vector2D targetVector, double h);
1415
void SetPosition(Vector2D vector, double h);
1516
bool GetPosition(Vector2D *outputVector);

TabletDriverService/TabletFilterSmoothing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ TabletFilterSmoothing::~TabletFilterSmoothing() {
3737
// TabletFilter methods
3838
//
3939

40+
// Reset
41+
void TabletFilterSmoothing::Reset(Vector2D position) {
42+
target.Set(position);
43+
prev_target.Set(position);
44+
calculated_target.Set(position);
45+
position.Set(position);
46+
}
47+
4048
// Set target position
4149
void TabletFilterSmoothing::SetTarget(Vector2D vector, double h) {
4250
this->target.x = vector.x;

0 commit comments

Comments
 (0)