Introducing the tuning knobs

Instead of counting loops for the purpose of calculating acceleration, use
timers and steps instead. This means that we can now tune how often the mouse
moves (`speedDelay`), how much it moves when it does (`speed`), how fast
acceleration is (`accelSpeed`), and how often we accelerate (`accelDelay`).

By default, the movement speed is one, and there is no delay, while acceleration
has an 50ms delay, and a speed of one.

But all of these can be tuned at run-time: we can turn off acceleration
completely, or slow down the mouse considerably - the possibilities are almost
endless!

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent f6b04da9d2
commit a33621e867

@ -5,8 +5,15 @@
#include "KeyboardioFirmware.h"
uint8_t MouseKeys_::mouseMoveIntent;
uint8_t MouseKeys_::accelDelay;
uint8_t MouseKeys_::accelDelayCounter;
uint8_t MouseKeys_::speed = 1;
uint16_t MouseKeys_::speedDelay = 0;
uint8_t MouseKeys_::accelSpeed = 1;
uint16_t MouseKeys_::accelDelay = 50;
uint32_t MouseKeys_::accelStartTime;
uint32_t MouseKeys_::startTime;
void MouseKeys_::loopHook(bool postClear) {
if (postClear) {
@ -15,28 +22,33 @@ void MouseKeys_::loopHook(bool postClear) {
}
if (mouseMoveIntent == 0) {
MouseWrapper.mouseActiveForCycles = 0;
MouseWrapper.accelStep = 0;
startTime = 0;
accelStartTime = 0;
return;
}
if ((millis() - startTime) < speedDelay)
return;
startTime = millis();
int8_t moveX = 0, moveY = 0;
if (accelDelayCounter == accelDelay) {
if (MouseWrapper.mouseActiveForCycles < 255)
MouseWrapper.mouseActiveForCycles++;
accelDelayCounter = 0;
} else
accelDelayCounter++;
if ((millis() - accelStartTime) >= (accelDelay * MouseWrapper.accelStep)) {
if (MouseWrapper.accelStep < 255 - accelSpeed)
MouseWrapper.accelStep += accelSpeed;
}
if (mouseMoveIntent & KEY_MOUSE_UP)
moveY = -1;
moveY = -speed;
else if (mouseMoveIntent & KEY_MOUSE_DOWN)
moveY = 1;
moveY = speed;
if (mouseMoveIntent & KEY_MOUSE_LEFT)
moveX = -1;
moveX = -speed;
else if (mouseMoveIntent & KEY_MOUSE_RIGHT)
moveX = 1;
moveX = speed;
MouseWrapper.move(moveX, moveY);
}
@ -54,6 +66,12 @@ Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyS
MouseWrapper.release_button(button);
}
} else if (!(mappedKey.keyCode & KEY_MOUSE_WARP)) {
if (key_toggled_on(keyState)) {
if (!startTime)
startTime = millis();
if (!accelStartTime)
accelStartTime = millis();
}
if (key_is_pressed(keyState))
mouseMoveIntent |= mappedKey.keyCode;
} else if (key_toggled_on(keyState)) {

@ -8,11 +8,16 @@ class MouseKeys_ : public KeyboardioPlugin {
MouseKeys_ (void);
virtual void begin(void) final;
static uint8_t accelDelay;
static uint8_t speed;
static uint16_t speedDelay;
static uint8_t accelSpeed;
static uint16_t accelDelay;
private:
static uint8_t mouseMoveIntent;
static uint8_t accelDelayCounter;
static uint32_t startTime;
static uint32_t accelStartTime;
static void loopHook(bool postClear);
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);

@ -10,7 +10,7 @@ uint16_t MouseWrapper_::section_top;
uint16_t MouseWrapper_::section_left;
boolean MouseWrapper_::is_warping;
uint8_t MouseWrapper_::mouseActiveForCycles;
uint8_t MouseWrapper_::accelStep;
MouseWrapper_::MouseWrapper_(void) {
Mouse.begin();
@ -101,10 +101,10 @@ void MouseWrapper_::move(int8_t x, int8_t y) {
int16_t moveX =0;
int16_t moveY = 0;
if (x != 0 ) {
moveX = (x * acceleration(mouseActiveForCycles));
moveX = (x * acceleration(accelStep));
}
if (y != 0) {
moveY = (y * acceleration(mouseActiveForCycles));
moveY = (y * acceleration(accelStep));
}
end_warping();

@ -35,7 +35,7 @@ class MouseWrapper_ {
static void warp(uint8_t warp_cmd);
static void press_button(uint8_t button);
static void release_button(uint8_t button);
static uint8_t mouseActiveForCycles;
static uint8_t accelStep;
private:
static uint16_t next_width;

Loading…
Cancel
Save