From 8600b9ee0977a2b0b42dc12a97e626c7b41ad0fc Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Sat, 20 Jan 2018 00:13:03 +1300 Subject: [PATCH] Jump detection now measures entire length of movement, not just the proportion above the jump velocity threshold. Also tweaked constant acceleration parameters. --- Upstream/Inc/build_config.h | 2 +- Upstream/Src/upstream_hid_botdetect.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Upstream/Inc/build_config.h b/Upstream/Inc/build_config.h index c753591..180266e 100644 --- a/Upstream/Inc/build_config.h +++ b/Upstream/Inc/build_config.h @@ -48,7 +48,7 @@ #define MOUSE_BOTDETECT_JUMP_PERIODS 4 //Constant acceleration detection stuff - #define MOUSE_BOTDETECT_CONSTANT_ACCEL_LOCKOUT 100 //Lock when constant acceleration counter reaches this number + #define MOUSE_BOTDETECT_CONSTANT_ACCEL_LOCKOUT 300 //Lock when constant acceleration counter reaches this number #define MOUSE_BOTDETECT_CONSTANT_ACCEL_STOP 10 //Block mouse movements when counter is above this value #define MOUSE_BOTDETECT_CONSTANT_ACCEL_CREDIT 100 //Non-constant-acceleration movements can build a credit that will be used before hitting the limits above. Handy for mice or users that exhibit constant velocity characteristics mid-movement. #define MOUSE_BOTDETECT_VELOCITY_RESET_TIMEOUT_MS 3000 //Reset constant acceleration counter when mouse stops for this time diff --git a/Upstream/Src/upstream_hid_botdetect.c b/Upstream/Src/upstream_hid_botdetect.c index f723a9a..222362e 100644 --- a/Upstream/Src/upstream_hid_botdetect.c +++ b/Upstream/Src/upstream_hid_botdetect.c @@ -58,7 +58,7 @@ volatile LockoutStateTypeDef LockoutState = LOCKOUT_STATE_INACTIVE; uint32_t LastMouseMoveTime = 0; //Jump detection stuff - uint32_t JumpLastMouseMoveBeginTime; + uint32_t FirstMouseMoveTime = 0; uint8_t JumpMouseIsMoving = 0; //Constant acceleration detection stuff @@ -464,16 +464,13 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData) //Jump detection: did the mouse stop moving briefly? if (moveDelay > ((MOUSE_BOTDETECT_JUMP_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2))) { - //Was a movement in progress? - if (JumpMouseIsMoving) + FirstMouseMoveTime = 0; + if (JumpMouseIsMoving) //Was a significant movement in progress? { JumpMouseIsMoving = 0; - if ((LastMouseMoveTime - JumpLastMouseMoveBeginTime) < ((MOUSE_BOTDETECT_JUMP_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2))) + if ((LastMouseMoveTime - FirstMouseMoveTime) < ((MOUSE_BOTDETECT_JUMP_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2))) { - if (ConstantAccelerationCounter >= 0) //Ignore jumps if ConstantAccelerationCounter is negative -> a human is using the mouse - { - Upstream_HID_BotDetectMouse_DoLockout(); - } + Upstream_HID_BotDetectMouse_DoLockout(); } } } @@ -483,10 +480,13 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData) { //Jump detection LastMouseMoveTime = now; - if ((JumpMouseIsMoving == 0) && (velocity > (MOUSE_BOTDETECT_JUMP_VELOCITY_THRESHOLD * MOUSE_BOTDETECT_VELOCITY_MULTIPLIER))) + if (FirstMouseMoveTime == 0) + { + FirstMouseMoveTime = now; + } + if (velocity > (MOUSE_BOTDETECT_JUMP_VELOCITY_THRESHOLD * MOUSE_BOTDETECT_VELOCITY_MULTIPLIER)) { JumpMouseIsMoving = 1; - JumpLastMouseMoveBeginTime = now; } //Constant acceleration detection