aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/keyboard.c12
-rw-r--r--common/mousekey.c36
-rw-r--r--keyboard/hhkb/config.h2
-rw-r--r--keyboard/hhkb/config_vusb.h2
4 files changed, 34 insertions, 18 deletions
diff --git a/common/keyboard.c b/common/keyboard.c
index 37d3b06ba..43abf4236 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -90,8 +90,10 @@ static void clear_keyboard(void)
90 host_system_send(0); 90 host_system_send(0);
91 host_consumer_send(0); 91 host_consumer_send(0);
92 92
93#ifdef MOUSEKEY_ENABLE
93 mousekey_clear(); 94 mousekey_clear();
94 mousekey_send(); 95 mousekey_send();
96#endif
95} 97}
96 98
97static void clear_keyboard_but_mods(void) 99static void clear_keyboard_but_mods(void)
@@ -102,8 +104,10 @@ static void clear_keyboard_but_mods(void)
102 host_system_send(0); 104 host_system_send(0);
103 host_consumer_send(0); 105 host_consumer_send(0);
104 106
107#ifdef MOUSEKEY_ENABLE
105 mousekey_clear(); 108 mousekey_clear();
106 mousekey_send(); 109 mousekey_send();
110#endif
107} 111}
108 112
109static void layer_switch_on(uint8_t code) 113static void layer_switch_on(uint8_t code)
@@ -159,8 +163,10 @@ static void register_code(uint8_t code)
159 host_send_keyboard_report(); 163 host_send_keyboard_report();
160 } 164 }
161 else if IS_MOUSEKEY(code) { 165 else if IS_MOUSEKEY(code) {
166#ifdef MOUSEKEY_ENABLE
162 mousekey_on(code); 167 mousekey_on(code);
163 mousekey_send(); 168 mousekey_send();
169#endif
164 } 170 }
165 else if IS_CONSUMER(code) { 171 else if IS_CONSUMER(code) {
166 uint16_t usage = 0; 172 uint16_t usage = 0;
@@ -251,8 +257,10 @@ static void unregister_code(uint8_t code)
251 host_send_keyboard_report(); 257 host_send_keyboard_report();
252 } 258 }
253 else if IS_MOUSEKEY(code) { 259 else if IS_MOUSEKEY(code) {
260#ifdef MOUSEKEY_ENABLE
254 mousekey_off(code); 261 mousekey_off(code);
255 mousekey_send(); 262 mousekey_send();
263#endif
256 } 264 }
257 else if IS_CONSUMER(code) { 265 else if IS_CONSUMER(code) {
258 host_consumer_send(0x0000); 266 host_consumer_send(0x0000);
@@ -390,7 +398,7 @@ static inline void process_key(keyevent_t event)
390 case KEY_UP: 398 case KEY_UP:
391 case MOD_UP: 399 case MOD_UP:
392 unregister_code(code); 400 unregister_code(code);
393 // no key registered? mousekey, mediakey, systemkey 401 // TODO: no key registered? mousekey, mediakey, systemkey
394 if (!host_has_anykey()) 402 if (!host_has_anykey())
395 NEXT(IDLE); 403 NEXT(IDLE);
396 break; 404 break;
@@ -570,8 +578,10 @@ void keyboard_task(void)
570 } 578 }
571 } 579 }
572 580
581#ifdef MOUSEKEY_ENABLE
573 // mousekey repeat & acceleration 582 // mousekey repeat & acceleration
574 mousekey_task(); 583 mousekey_task();
584#endif
575 585
576 // FAIL SAFE: clear all key if no key down 586 // FAIL SAFE: clear all key if no key down
577 if (matrix_change) { 587 if (matrix_change) {
diff --git a/common/mousekey.c b/common/mousekey.c
index 58a6e35bb..6fe8e2d26 100644
--- a/common/mousekey.c
+++ b/common/mousekey.c
@@ -37,7 +37,7 @@ static void mousekey_debug(void);
37 * see wikipedia http://en.wikipedia.org/wiki/Mouse_keys 37 * see wikipedia http://en.wikipedia.org/wiki/Mouse_keys
38 */ 38 */
39#ifndef MOUSEKEY_DELAY_TIME 39#ifndef MOUSEKEY_DELAY_TIME
40# define MOUSEKEY_DELAY_TIME 20 40# define MOUSEKEY_DELAY_TIME 100
41#endif 41#endif
42 42
43#define MOUSEKEY_MOVE_INIT 5 43#define MOUSEKEY_MOVE_INIT 5
@@ -54,10 +54,16 @@ static uint16_t last_timer = 0;
54 54
55static inline uint8_t move_unit(void) 55static inline uint8_t move_unit(void)
56{ 56{
57 uint16_t unit = 5 + mousekey_repeat*4; 57 uint16_t unit = MOUSEKEY_MOVE_INIT + MOUSEKEY_MOVE_ACCEL * mousekey_repeat;
58 return (unit > 63 ? 63 : unit); 58 return (unit > 63 ? 63 : unit);
59} 59}
60 60
61static inline uint8_t wheel_unit(void)
62{
63 uint16_t unit = MOUSEKEY_WHEEL_INIT + MOUSEKEY_WHEEL_ACCEL * mousekey_repeat;
64 return (unit > 15 ? 15 : unit);
65}
66
61void mousekey_task(void) 67void mousekey_task(void)
62{ 68{
63 if (timer_elapsed(last_timer) < MOUSEKEY_DELAY_TIME) 69 if (timer_elapsed(last_timer) < MOUSEKEY_DELAY_TIME)
@@ -80,10 +86,10 @@ void mousekey_task(void)
80 report.y *= 0.7; 86 report.y *= 0.7;
81 } 87 }
82 88
83 if (report.v > 0) report.v = move_unit(); 89 if (report.v > 0) report.v = wheel_unit();
84 if (report.v < 0) report.v = move_unit() * -1; 90 if (report.v < 0) report.v = wheel_unit() * -1;
85 if (report.h > 0) report.h = move_unit(); 91 if (report.h > 0) report.h = wheel_unit();
86 if (report.h < 0) report.h = move_unit() * -1; 92 if (report.h < 0) report.h = wheel_unit() * -1;
87 93
88 mousekey_send(); 94 mousekey_send();
89} 95}
@@ -107,19 +113,19 @@ void mousekey_on(uint8_t code)
107 113
108void mousekey_off(uint8_t code) 114void mousekey_off(uint8_t code)
109{ 115{
110 if (code == KC_MS_UP && report.y < 0) report.y = 0; 116 if (code == KC_MS_UP && report.y < 0) report.y = 0;
111 else if (code == KC_MS_DOWN && report.y > 0) report.y = 0; 117 else if (code == KC_MS_DOWN && report.y > 0) report.y = 0;
112 else if (code == KC_MS_LEFT && report.x < 0) report.x = 0; 118 else if (code == KC_MS_LEFT && report.x < 0) report.x = 0;
113 else if (code == KC_MS_RIGHT && report.x > 0) report.x = 0; 119 else if (code == KC_MS_RIGHT && report.x > 0) report.x = 0;
114 else if (code == KC_MS_WH_UP && report.v > 0) report.v = 0; 120 else if (code == KC_MS_WH_UP && report.v > 0) report.v = 0;
115 else if (code == KC_MS_WH_DOWN && report.v < 0) report.v = 0; 121 else if (code == KC_MS_WH_DOWN && report.v < 0) report.v = 0;
116 else if (code == KC_MS_WH_LEFT && report.h < 0) report.h = 0; 122 else if (code == KC_MS_WH_LEFT && report.h < 0) report.h = 0;
117 else if (code == KC_MS_WH_RIGHT && report.h > 0) report.h = 0; 123 else if (code == KC_MS_WH_RIGHT && report.h > 0) report.h = 0;
118 else if (code == KC_MS_BTN1) report.buttons &= ~MOUSE_BTN1; 124 else if (code == KC_MS_BTN1) report.buttons &= ~MOUSE_BTN1;
119 else if (code == KC_MS_BTN2) report.buttons &= ~MOUSE_BTN2; 125 else if (code == KC_MS_BTN2) report.buttons &= ~MOUSE_BTN2;
120 else if (code == KC_MS_BTN3) report.buttons &= ~MOUSE_BTN3; 126 else if (code == KC_MS_BTN3) report.buttons &= ~MOUSE_BTN3;
121 else if (code == KC_MS_BTN4) report.buttons &= ~MOUSE_BTN4; 127 else if (code == KC_MS_BTN4) report.buttons &= ~MOUSE_BTN4;
122 else if (code == KC_MS_BTN5) report.buttons &= ~MOUSE_BTN5; 128 else if (code == KC_MS_BTN5) report.buttons &= ~MOUSE_BTN5;
123 129
124 if (report.x == 0 && report.y == 0 && report.v == 0 && report.h == 0) 130 if (report.x == 0 && report.y == 0 && report.v == 0 && report.h == 0)
125 mousekey_repeat = 0; 131 mousekey_repeat = 0;
diff --git a/keyboard/hhkb/config.h b/keyboard/hhkb/config.h
index e10a7ab37..cca75f243 100644
--- a/keyboard/hhkb/config.h
+++ b/keyboard/hhkb/config.h
@@ -42,7 +42,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
42 42
43/* mouse keys */ 43/* mouse keys */
44#ifdef MOUSEKEY_ENABLE 44#ifdef MOUSEKEY_ENABLE
45# define MOUSEKEY_DELAY_TIME 192 45# define MOUSEKEY_DELAY_TIME 100
46#endif 46#endif
47 47
48 48
diff --git a/keyboard/hhkb/config_vusb.h b/keyboard/hhkb/config_vusb.h
index b85e16fa3..44d5e4557 100644
--- a/keyboard/hhkb/config_vusb.h
+++ b/keyboard/hhkb/config_vusb.h
@@ -37,7 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
37 37
38/* mouse keys */ 38/* mouse keys */
39#ifdef MOUSEKEY_ENABLE 39#ifdef MOUSEKEY_ENABLE
40# define MOUSEKEY_DELAY_TIME 255 40# define MOUSEKEY_DELAY_TIME 100
41#endif 41#endif
42 42
43 43