From f1bdace080b280481444591501aaa2b19f944527 Mon Sep 17 00:00:00 2001 From: David Henderson Date: Mon, 26 Apr 2021 20:19:58 +0100 Subject: [PATCH] This proposed change stops the inverse mouse acceleration effect under DPI dividing. Instead of placing a floor of one movement unit output for any movement units input, a pair of static locals track skipped units allowing the divisor to also work where input movementUnits < DPI_DIVIDER. --- SmallyMouse2/main.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/SmallyMouse2/main.c b/SmallyMouse2/main.c index 9e4eee7..7098a77 100644 --- a/SmallyMouse2/main.c +++ b/SmallyMouse2/main.c @@ -447,6 +447,8 @@ void processMouse(void) uint8_t processMouseMovement(int8_t movementUnits, uint8_t axis, bool limitRate, bool dpiDivide) { uint16_t timerTopValue = 0; + static int8_t skippedunits[2] = {0,0}; + // Set the mouse movement direction and record the movement units if (movementUnits > 0) { @@ -455,7 +457,19 @@ uint8_t processMouseMovement(int8_t movementUnits, uint8_t axis, bool limitRate, // Apply DPI limiting if required if (dpiDivide) { movementUnits /= DPI_DIVIDER; - if (movementUnits < 1) movementUnits = 1; + // avoid inverse mouse acceleration effect where slow movement is at full DPI -- dh219 + if( movementUnits == 0 ) {// has been scaled away to zero + if( skippedunits[axis] >= DPI_DIVIDER ) { + movementUnits = 1; + skippedunits[axis] = 0; + } + else { + if( skippedunits[axis] < 0 ) { + skippedunits[axis] = 0; + } + skippedunits[axis]++; + } + } } // Add the movement units to the quadrature output buffer @@ -467,7 +481,19 @@ uint8_t processMouseMovement(int8_t movementUnits, uint8_t axis, bool limitRate, // Apply DPI limiting if required if (dpiDivide) { movementUnits /= DPI_DIVIDER; - if (movementUnits > -1) movementUnits = -1; + // avoid inverse mouse acceleration effect where slow movement is at full DPI -- dh219 + if( movementUnits == 0 ) {// has been scaled away to zero + if( skippedunits[axis] <= -DPI_DIVIDER ) { + movementUnits = -1; + skippedunits[axis] = 0; + } + else { + if( skippedunits[axis] > 0 ) { + skippedunits[axis] = 0; + } + skippedunits[axis]--; + } + } } // Add the movement units to the quadrature output buffer