diff options
| author | tmk <nobody@nowhere> | 2012-10-10 15:31:00 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-10-17 15:55:37 +0900 |
| commit | 0a70be9a97215e2b514841f67e52b4c55a6adab1 (patch) | |
| tree | 22b584fa6ec728c519dd5c78156da0154db0a199 /common/mousekey.c | |
| parent | 5b00cf3f024a09d834d125374d93cacc269f84ba (diff) | |
| download | qmk_firmware-0a70be9a97215e2b514841f67e52b4c55a6adab1.tar.gz qmk_firmware-0a70be9a97215e2b514841f67e52b4c55a6adab1.zip | |
Add subset of Xorg MouseKey acceleration parameters.
Diffstat (limited to 'common/mousekey.c')
| -rw-r--r-- | common/mousekey.c | 102 |
1 files changed, 74 insertions, 28 deletions
diff --git a/common/mousekey.c b/common/mousekey.c index 6fe8e2d26..4b1fe1740 100644 --- a/common/mousekey.c +++ b/common/mousekey.c | |||
| @@ -32,41 +32,87 @@ static uint8_t mousekey_repeat = 0; | |||
| 32 | static void mousekey_debug(void); | 32 | static void mousekey_debug(void); |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | /* max value on report descriptor */ | ||
| 36 | #define MOUSEKEY_MOVE_MAX 127 | ||
| 37 | #define MOUSEKEY_WHEEL_MAX 15 | ||
| 38 | |||
| 39 | #ifndef MOUSEKEY_MOVE_DELTA | ||
| 40 | #define MOUSEKEY_MOVE_DELTA 5 | ||
| 41 | #endif | ||
| 42 | #ifndef MOUSEKEY_WHEEL_DELTA | ||
| 43 | #define MOUSEKEY_WHEEL_DELTA 1 | ||
| 44 | #endif | ||
| 45 | #ifndef MOUSEKEY_DELAY | ||
| 46 | #define MOUSEKEY_DELAY 300 | ||
| 47 | #endif | ||
| 48 | #ifndef MOUSEKEY_INTERVAL | ||
| 49 | #define MOUSEKEY_INTERVAL 50 | ||
| 50 | #endif | ||
| 51 | #ifndef MOUSEKEY_MAX_SPEED | ||
| 52 | #define MOUSEKEY_MAX_SPEED 10 | ||
| 53 | #endif | ||
| 54 | #ifndef MOUSEKEY_TIME_TO_MAX | ||
| 55 | #define MOUSEKEY_TIME_TO_MAX 20 | ||
| 56 | #endif | ||
| 57 | #ifndef MOUSEKEY_WHEEL_MAX_SPEED | ||
| 58 | #define MOUSEKEY_WHEEL_MAX_SPEED 8 | ||
| 59 | #endif | ||
| 60 | #ifndef MOUSEKEY_WHEEL_TIME_TO_MAX | ||
| 61 | #define MOUSEKEY_WHEEL_TIME_TO_MAX 40 | ||
| 62 | #endif | ||
| 63 | |||
| 64 | |||
| 35 | /* | 65 | /* |
| 36 | * TODO: fix acceleration algorithm | 66 | * Mouse keys acceleration algorithm |
| 37 | * see wikipedia http://en.wikipedia.org/wiki/Mouse_keys | 67 | * http://en.wikipedia.org/wiki/Mouse_keys |
| 68 | * | ||
| 69 | * speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000) | ||
| 38 | */ | 70 | */ |
| 39 | #ifndef MOUSEKEY_DELAY_TIME | 71 | /* milliseconds between the initial key press and first repeated motion event (0-2550) */ |
| 40 | # define MOUSEKEY_DELAY_TIME 100 | 72 | static uint8_t mk_delay = MOUSEKEY_DELAY/10; |
| 41 | #endif | 73 | /* milliseconds between repeated motion events (0-255) */ |
| 74 | static uint8_t mk_interval = MOUSEKEY_INTERVAL; | ||
| 75 | /* steady speed (in action_delta units) applied each event (0-255) */ | ||
| 76 | static uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED; | ||
| 77 | /* number of events (count) accelerating to steady speed (0-255) */ | ||
| 78 | static uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX; | ||
| 79 | /* ramp used to reach maximum pointer speed (NOT SUPPORTED) */ | ||
| 80 | //static int8_t mk_curve = 0; | ||
| 42 | 81 | ||
| 43 | #define MOUSEKEY_MOVE_INIT 5 | 82 | static uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; |
| 44 | #define MOUSEKEY_WHEEL_INIT 1 | 83 | static uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; |
| 45 | #define MOUSEKEY_MOVE_ACCEL 5 | ||
| 46 | #define MOUSEKEY_WHEEL_ACCEL 1 | ||
| 47 | 84 | ||
| 48 | static uint16_t last_timer = 0; | ||
| 49 | 85 | ||
| 50 | // acceleration parameters | 86 | static uint16_t last_timer = 0; |
| 51 | //uint8_t mousekey_move_unit = 2; | ||
| 52 | //uint8_t mousekey_resolution = 5; | ||
| 53 | 87 | ||
| 54 | 88 | ||
| 55 | static inline uint8_t move_unit(void) | 89 | static uint8_t move_unit(void) |
| 56 | { | 90 | { |
| 57 | uint16_t unit = MOUSEKEY_MOVE_INIT + MOUSEKEY_MOVE_ACCEL * mousekey_repeat; | 91 | uint16_t unit; |
| 58 | return (unit > 63 ? 63 : unit); | 92 | if (mousekey_repeat > mk_time_to_max) { |
| 93 | unit = MOUSEKEY_MOVE_DELTA * mk_max_speed; | ||
| 94 | } else { | ||
| 95 | unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max; | ||
| 96 | } | ||
| 97 | if (unit == 0) return 1; | ||
| 98 | return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : unit); | ||
| 59 | } | 99 | } |
| 60 | 100 | ||
| 61 | static inline uint8_t wheel_unit(void) | 101 | static uint8_t wheel_unit(void) |
| 62 | { | 102 | { |
| 63 | uint16_t unit = MOUSEKEY_WHEEL_INIT + MOUSEKEY_WHEEL_ACCEL * mousekey_repeat; | 103 | uint16_t unit; |
| 64 | return (unit > 15 ? 15 : unit); | 104 | if (mousekey_repeat > mk_time_to_max) { |
| 105 | unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; | ||
| 106 | } else { | ||
| 107 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_time_to_max; | ||
| 108 | } | ||
| 109 | if (unit == 0) return 1; | ||
| 110 | return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : unit); | ||
| 65 | } | 111 | } |
| 66 | 112 | ||
| 67 | void mousekey_task(void) | 113 | void mousekey_task(void) |
| 68 | { | 114 | { |
| 69 | if (timer_elapsed(last_timer) < MOUSEKEY_DELAY_TIME) | 115 | if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10)) |
| 70 | return; | 116 | return; |
| 71 | 117 | ||
| 72 | if (report.x == 0 && report.y == 0 && report.v == 0 && report.h == 0) | 118 | if (report.x == 0 && report.y == 0 && report.v == 0 && report.h == 0) |
| @@ -96,14 +142,14 @@ void mousekey_task(void) | |||
| 96 | 142 | ||
| 97 | void mousekey_on(uint8_t code) | 143 | void mousekey_on(uint8_t code) |
| 98 | { | 144 | { |
| 99 | if (code == KC_MS_UP) report.y = MOUSEKEY_MOVE_INIT * -1; | 145 | if (code == KC_MS_UP) report.y = MOUSEKEY_MOVE_DELTA * -1; |
| 100 | else if (code == KC_MS_DOWN) report.y = MOUSEKEY_MOVE_INIT; | 146 | else if (code == KC_MS_DOWN) report.y = MOUSEKEY_MOVE_DELTA; |
| 101 | else if (code == KC_MS_LEFT) report.x = MOUSEKEY_MOVE_INIT * -1; | 147 | else if (code == KC_MS_LEFT) report.x = MOUSEKEY_MOVE_DELTA * -1; |
| 102 | else if (code == KC_MS_RIGHT) report.x = MOUSEKEY_MOVE_INIT; | 148 | else if (code == KC_MS_RIGHT) report.x = MOUSEKEY_MOVE_DELTA; |
| 103 | else if (code == KC_MS_WH_UP) report.v = MOUSEKEY_WHEEL_INIT; | 149 | else if (code == KC_MS_WH_UP) report.v = MOUSEKEY_WHEEL_DELTA; |
| 104 | else if (code == KC_MS_WH_DOWN) report.v = MOUSEKEY_WHEEL_INIT * -1; | 150 | else if (code == KC_MS_WH_DOWN) report.v = MOUSEKEY_WHEEL_DELTA * -1; |
| 105 | else if (code == KC_MS_WH_LEFT) report.h = MOUSEKEY_WHEEL_INIT * -1; | 151 | else if (code == KC_MS_WH_LEFT) report.h = MOUSEKEY_WHEEL_DELTA * -1; |
| 106 | else if (code == KC_MS_WH_RIGHT) report.h = MOUSEKEY_WHEEL_INIT; | 152 | else if (code == KC_MS_WH_RIGHT) report.h = MOUSEKEY_WHEEL_DELTA; |
| 107 | else if (code == KC_MS_BTN1) report.buttons |= MOUSE_BTN1; | 153 | else if (code == KC_MS_BTN1) report.buttons |= MOUSE_BTN1; |
| 108 | else if (code == KC_MS_BTN2) report.buttons |= MOUSE_BTN2; | 154 | else if (code == KC_MS_BTN2) report.buttons |= MOUSE_BTN2; |
| 109 | else if (code == KC_MS_BTN3) report.buttons |= MOUSE_BTN3; | 155 | else if (code == KC_MS_BTN3) report.buttons |= MOUSE_BTN3; |
