Implement random-movement credit in the constant acceleration detector.

This makes it more forgiving of constant acceleration mid-movement, if
the beginning of the movement looks random. Handy for mice that for some
reason generate bot-like constant velocities.
USG_1.0
Robert Fisk 6 years ago
parent 7e4af61910
commit 3d91aa2115

@ -43,8 +43,9 @@
#ifdef CONFIG_MOUSE_BOT_DETECT_ENABLED
//-----------------------------------------------------------
//Adjust these thresholds first to tune mouse bot detection. Lower values = more sensitive
#define MOUSE_BOTDETECT_JUMP_VELOCITY_THRESHOLD 20 //Varies by mouse. Most short jumps are <= 10
#define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_COUNT 30 //20 is ok for most mice. But some mice (or users!) generate longer sequences.
#define MOUSE_BOTDETECT_JUMP_VELOCITY_THRESHOLD 20 //Varies by mouse. Most short jumps are <= 10 velocity
#define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_LIMIT 30 //10 is ok for most mice. But some mice (or users!) generate longer sequences.
#define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_CREDIT 40 //Non-constant-acceleration movements can build a credit that will be used before hitting the ACCEL_COUNT limit above. Handy for mice or users that exhibit constant velocity characteristics mid-movement.
//-----------------------------------------------------------
#define MOUSE_BOTDETECT_VELOCITY_MULTIPLIER 10

@ -63,10 +63,11 @@ volatile LockoutStateTypeDef LockoutState = LOCKOUT_STATE_INACTIVE;
//Constant acceleration detection stuff
uint16_t MouseVelocityHistory[MOUSE_BOTDETECT_VELOCITY_HISTORY_SIZE] = {0};
int32_t PreviousSmoothedAcceleration = 0;
uint8_t ConstantAccelerationCounter = 0;
int8_t ConstantAccelerationCounter = 0;
//Debug:
// uint8_t ConstantAccelerationCounterMax = 0;
// int8_t ConstantAccelerationCounterMax = 0;
// int8_t ConstantAccelerationCounterMin = 0;
static void Upstream_HID_BotDetectMouse_DoLockout(void);
#endif
@ -406,6 +407,9 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData)
//Did the mouse stop moving?
if ((now - LastMouseMoveTime) > ((MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2)))
{
//Constant acceleration detection
ConstantAccelerationCounter = 0;
//Jump detection
if (MouseIsMoving)
{
@ -457,19 +461,20 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData)
((PreviousSmoothedAcceleration - smoothedAccelerationMatchError) <= newSmoothedAcceleration))
{
ConstantAccelerationCounter++;
if (ConstantAccelerationCounter > MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_COUNT)
if (ConstantAccelerationCounter > MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_LIMIT)
{
Upstream_HID_BotDetectMouse_DoLockout();
}
//Debug:
// if (ConstantAccelerationCounter > ConstantAccelerationCounterMax) ConstantAccelerationCounterMax = ConstantAccelerationCounter;
}
else
{
ConstantAccelerationCounter = 0;
if (ConstantAccelerationCounter > -MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_CREDIT) ConstantAccelerationCounter--;
}
PreviousSmoothedAcceleration = newSmoothedAcceleration;
//Debug:
// if (ConstantAccelerationCounter > ConstantAccelerationCounterMax) ConstantAccelerationCounterMax = ConstantAccelerationCounter;
// if (ConstantAccelerationCounter < ConstantAccelerationCounterMin) ConstantAccelerationCounterMin = ConstantAccelerationCounter;
}
}
else

Loading…
Cancel
Save