From 2240f87a6c12ed09af29029e3d03f34994009eae Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 25 Oct 2023 18:33:26 +0200 Subject: [PATCH] improved mouse acceleration in pad mode --- FLipWare/FLipWare.ino | 3 ++- FLipWare/FlipWare.h | 5 ++-- FLipWare/modes.cpp | 58 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/FLipWare/FLipWare.ino b/FLipWare/FLipWare.ino index 3035c26..bf9048e 100644 --- a/FLipWare/FLipWare.ino +++ b/FLipWare/FLipWare.ino @@ -75,7 +75,7 @@ const struct SlotSettings defaultSlotSettings = { // default slotSettings v static variables and data structures for settings and sensor data management */ struct SensorData sensorData { - .x=0, .y=0, .xRaw=0, .yRaw=0, .pressure=0, + .x=0, .y=0, .xRaw=0, .yRaw=0, .padState=0, .pressure=0, .deadZone=0, .force=0, .forceRaw=0, .angle=0, .dir=0, .autoMoveX=0, .autoMoveY=0, @@ -185,6 +185,7 @@ void loop() { // get coordinates and handle tap gestures sensorData.xRaw=sensorData.x=padX; sensorData.yRaw=sensorData.y=padY; + sensorData.padState=padState; handleTapClicks(padState, slotSettings.gv*10); // perform clicks and drag actions when in pad mode // calculate angular direction and force diff --git a/FLipWare/FlipWare.h b/FLipWare/FlipWare.h index 7c67e27..eb4f537 100644 --- a/FLipWare/FlipWare.h +++ b/FLipWare/FlipWare.h @@ -33,8 +33,9 @@ #include "bluetooth.h" #include "hid_hal.h" -#define VERSION_STRING "v1.3" +#define VERSION_STRING "v1.4" +// V1.4: improved mouse acceleration in pad mode // V1.3: fixed memory allocation problem (removed malloc, reduced static memory allocation) // V1.2: added check for MPRLS pressure sensor @@ -114,7 +115,7 @@ struct SlotSettings { contains working data of sensors (raw and processed values) */ struct SensorData { - int x, y, xRaw,yRaw; + int x, y, xRaw,yRaw, padState; int pressure; float deadZone, force, forceRaw, angle; uint8_t dir; diff --git a/FLipWare/modes.cpp b/FLipWare/modes.cpp index d795d9e..bbd2347 100644 --- a/FLipWare/modes.cpp +++ b/FLipWare/modes.cpp @@ -19,6 +19,8 @@ #include "gpio.h" #include "tone.h" #include "utils.h" +#include "cirque.h" + /** static variables for mode handling @@ -210,12 +212,12 @@ void handleUserInteraction() } /** - @name getAccelFactor - @brief calculates acceleration for mouse pointer movements + @name getStickAccelFactor + @brief calculates acceleration for mouse pointer movements in stick mode according to sensordata and acceleration settings @return float value of current acceleration factor */ -float getAccelFactor() { +float getStickAccelFactor() { static float accelFactor=0; static int xo = 0, yo = 0; static float accelMaxForce = 0, lastAngle = 0; @@ -244,27 +246,59 @@ float getAccelFactor() { return(accelFactor); } + +/** + @name getPadAccelFactor + @brief calculates acceleration for mouse pointer movements in pad mode + according to sensordata and acceleration settings + @return float value of current acceleration factor +*/ +float getPadAccelFactor() { + static float accelFactor=0; + static float distance=0; + + if ((sensorData.padState==CIRQUE_STATE_LIFTOFF) || (sensorData.padState==CIRQUE_STATE_HOVERING)) { + accelFactor = 0; + distance=0; + } + else { + distance += (fabsf(sensorData.x) + fabsf(sensorData.y)) / 700000; + accelFactor = 0.0005+distance; + if (accelFactor>0.01) accelFactor=0.01; + } + return(accelFactor); +} + /** @name acceleratedMouseMove @brief performs accelerated mouse pointer movement @param accelFactor current acceleration factor @return none */ -void acceleratedMouseMove(float accelFactor) { +void acceleratedMouseMove(float accelFactor, uint8_t use_maxSpeed) { static float accumXpos = 0; static float accumYpos = 0; float moveValX = sensorData.x * (float)slotSettings.ax * accelFactor; float moveValY = sensorData.y * (float)slotSettings.ay * accelFactor; - - float actSpeed = __ieee754_sqrtf (moveValX * moveValX + moveValY * moveValY); - float max_speed = (float)slotSettings.ms / 10.0f; - if (actSpeed > max_speed) { - moveValX *= (max_speed / actSpeed); - moveValY *= (max_speed / actSpeed); + if (use_maxSpeed) { + float actSpeed = __ieee754_sqrtf (moveValX * moveValX + moveValY * moveValY); + float max_speed = (float)slotSettings.ms / 10.0f; + if (actSpeed > max_speed) { + moveValX *= (max_speed / actSpeed); + moveValY *= (max_speed / actSpeed); + } } +/* + if ((sensorData.x!=0) && (sensorData.y!=0)) { + Serial.print ("x=");Serial.print (sensorData.x); Serial.print (" y=");Serial.print (sensorData.y); + Serial.print (" / moveValX=");Serial.print (moveValX); Serial.print (" moveValY=");Serial.print (moveValY); + Serial.println(" "); + } +*/ + accumXpos += moveValX; accumYpos += moveValY; @@ -310,11 +344,11 @@ void handleMovement() switch (slotSettings.padMode) { case PADMODE_MOUSE: // handle mouse stick mode - acceleratedMouseMove(getAccelFactor()); + acceleratedMouseMove(getStickAccelFactor(), 1); break; case PADMODE_PAD: // handle mouse pad mode - acceleratedMouseMove(0.01); + acceleratedMouseMove(getPadAccelFactor(), 0); break; case PADMODE_ALTERNATIVE: // handle alternative actions (non-sticky)