summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-08-06 21:43:44 -0400
committera1xd <[email protected]>2020-08-06 21:43:44 -0400
commit9d39a2bf6b521576f20b52e95956e4b194a8b307 (patch)
tree50571ce8e080df57049809696cdf0808eb1018a5 /driver
parentMerge pull request #12 from JacobPalecki/GUI (diff)
downloadrawaccel-9d39a2bf6b521576f20b52e95956e4b194a8b307.tar.xz
rawaccel-9d39a2bf6b521576f20b52e95956e4b194a8b307.zip
add a cooldown on write (one second)
Diffstat (limited to 'driver')
-rw-r--r--driver/driver.cpp23
-rw-r--r--driver/driver.h4
2 files changed, 22 insertions, 5 deletions
diff --git a/driver/driver.cpp b/driver/driver.cpp
index c893b8b..3e67539 100644
--- a/driver/driver.cpp
+++ b/driver/driver.cpp
@@ -16,6 +16,7 @@ using milliseconds = double;
struct {
milliseconds tick_interval = 0; // set in DriverEntry
ra::mouse_modifier modifier;
+ counter_t last_write = 0;
} global;
VOID
@@ -70,9 +71,9 @@ Arguments:
};
if (global.modifier.apply_accel && local_apply_accel) {
- auto now = KeQueryPerformanceCounter(NULL).QuadPart;
- auto ticks = now - devExt->counter.QuadPart;
- devExt->counter.QuadPart = now;
+ counter_t now = KeQueryPerformanceCounter(NULL).QuadPart;
+ counter_t ticks = now - devExt->counter;
+ devExt->counter = now;
milliseconds time = ticks * global.tick_interval;
if (time < global.modifier.accel_fn.time_min) {
@@ -154,6 +155,19 @@ Return Value:
DebugPrint(("Ioctl received into filter control object.\n"));
if (InputBufferLength == sizeof(ra::mouse_modifier)) {
+ constexpr milliseconds WRITE_COOLDOWN_TIME = 1000;
+
+ counter_t now = KeQueryPerformanceCounter(NULL).QuadPart;
+ counter_t ticks = now - global.last_write;
+ milliseconds time = ticks * global.tick_interval;
+
+ if (global.last_write > 0 && time < WRITE_COOLDOWN_TIME) {
+ DebugPrint(("RA write on cooldown\n"));
+ // status maps to win32 error code 170: ERROR_BUSY
+ WdfRequestComplete(Request, STATUS_ENCOUNTERED_WRITE_IN_PROGRESS);
+ return;
+ }
+
status = WdfRequestRetrieveInputBuffer(
Request,
sizeof(ra::mouse_modifier),
@@ -169,6 +183,7 @@ Return Value:
}
global.modifier = *reinterpret_cast<ra::mouse_modifier*>(buffer);
+ global.last_write = now;
WdfRequestComplete(Request, STATUS_SUCCESS);
}
@@ -550,7 +565,7 @@ Routine Description:
break;
}
- devExt->counter = KeQueryPerformanceCounter(NULL);
+ devExt->counter = 0;
devExt->carry = {};
devExt->UpperConnectData = *connectData;
diff --git a/driver/driver.h b/driver/driver.h
index 2a400de..8554f8c 100644
--- a/driver/driver.h
+++ b/driver/driver.h
@@ -15,8 +15,10 @@
#define NTDEVICE_NAME L"\\Device\\rawaccel"
#define SYMBOLIC_NAME_STRING L"\\DosDevices\\rawaccel"
+using counter_t = long long;
+
typedef struct _DEVICE_EXTENSION {
- LARGE_INTEGER counter;
+ counter_t counter;
vec2d carry;
CONNECT_DATA UpperConnectData;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;