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

@ -8,11 +8,16 @@ class MouseKeys_ : public KeyboardioPlugin {
MouseKeys_ (void); MouseKeys_ (void);
virtual void begin(void) final; 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: private:
static uint8_t mouseMoveIntent; static uint8_t mouseMoveIntent;
static uint8_t accelDelayCounter; static uint32_t startTime;
static uint32_t accelStartTime;
static void loopHook(bool postClear); static void loopHook(bool postClear);
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState); 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; uint16_t MouseWrapper_::section_left;
boolean MouseWrapper_::is_warping; boolean MouseWrapper_::is_warping;
uint8_t MouseWrapper_::mouseActiveForCycles; uint8_t MouseWrapper_::accelStep;
MouseWrapper_::MouseWrapper_(void) { MouseWrapper_::MouseWrapper_(void) {
Mouse.begin(); Mouse.begin();
@ -101,10 +101,10 @@ void MouseWrapper_::move(int8_t x, int8_t y) {
int16_t moveX =0; int16_t moveX =0;
int16_t moveY = 0; int16_t moveY = 0;
if (x != 0 ) { if (x != 0 ) {
moveX = (x * acceleration(mouseActiveForCycles)); moveX = (x * acceleration(accelStep));
} }
if (y != 0) { if (y != 0) {
moveY = (y * acceleration(mouseActiveForCycles)); moveY = (y * acceleration(accelStep));
} }
end_warping(); end_warping();

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

Loading…
Cancel
Save