diff options
Diffstat (limited to 'mousekey.c')
| -rw-r--r-- | mousekey.c | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/mousekey.c b/mousekey.c index 2e9b8cb1a..0c1436b0c 100644 --- a/mousekey.c +++ b/mousekey.c | |||
| @@ -24,11 +24,15 @@ static void mousekey_debug(void); | |||
| 24 | # define MOUSEKEY_DELAY_TIME 255 | 24 | # define MOUSEKEY_DELAY_TIME 255 |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | // acceleration parameters | ||
| 28 | uint8_t mousekey_move_unit = 2; | ||
| 29 | uint8_t mousekey_resolution = 5; | ||
| 30 | |||
| 27 | 31 | ||
| 28 | static inline uint8_t move_unit(void) | 32 | static inline uint8_t move_unit(void) |
| 29 | { | 33 | { |
| 30 | uint16_t unit = 10 + (mousekey_repeat); | 34 | uint16_t unit = 5 + mousekey_repeat*2; |
| 31 | return (unit > 127 ? 127 : unit); | 35 | return (unit > 63 ? 63 : unit); |
| 32 | } | 36 | } |
| 33 | 37 | ||
| 34 | void mousekey_decode(uint8_t code) | 38 | void mousekey_decode(uint8_t code) |
| @@ -40,23 +44,18 @@ void mousekey_decode(uint8_t code) | |||
| 40 | else if (code == KB_MS_BTN1) report.buttons |= MOUSE_BTN1; | 44 | else if (code == KB_MS_BTN1) report.buttons |= MOUSE_BTN1; |
| 41 | else if (code == KB_MS_BTN2) report.buttons |= MOUSE_BTN2; | 45 | else if (code == KB_MS_BTN2) report.buttons |= MOUSE_BTN2; |
| 42 | else if (code == KB_MS_BTN3) report.buttons |= MOUSE_BTN3; | 46 | else if (code == KB_MS_BTN3) report.buttons |= MOUSE_BTN3; |
| 43 | /* | ||
| 44 | else if (code == KB_MS_BTN4) report.buttons |= MOUSE_BTN4; | 47 | else if (code == KB_MS_BTN4) report.buttons |= MOUSE_BTN4; |
| 45 | else if (code == KB_MS_BTN5) report.buttons |= MOUSE_BTN5; | 48 | else if (code == KB_MS_BTN5) report.buttons |= MOUSE_BTN5; |
| 46 | else if (code == KB_MS_WH_UP) report.v += 1; | 49 | else if (code == KB_MS_WH_UP) report.v += 1; |
| 47 | else if (code == KB_MS_WH_DOWN) report.v -= 1; | 50 | else if (code == KB_MS_WH_DOWN) report.v -= 1; |
| 48 | else if (code == KB_MS_WH_LEFT) report.h -= 1; | 51 | else if (code == KB_MS_WH_LEFT) report.h -= 1; |
| 49 | else if (code == KB_MS_WH_RIGHT)report.h += 1; | 52 | else if (code == KB_MS_WH_RIGHT)report.h += 1; |
| 50 | */ | ||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | bool mousekey_changed(void) | 55 | bool mousekey_changed(void) |
| 54 | { | 56 | { |
| 55 | return (report.buttons != report_prev.buttons || | 57 | return (report.buttons != report_prev.buttons || |
| 56 | report.x != report_prev.x || | 58 | report.x || report.y || report.v || report.h); |
| 57 | report.y != report_prev.y || | ||
| 58 | report.x || report.y); | ||
| 59 | //return (report.buttons != report_prev.buttons || report.x || report.y); | ||
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | void mousekey_send(void) | 61 | void mousekey_send(void) |
| @@ -65,36 +64,30 @@ void mousekey_send(void) | |||
| 65 | 64 | ||
| 66 | if (!mousekey_changed()) { | 65 | if (!mousekey_changed()) { |
| 67 | mousekey_repeat = 0; | 66 | mousekey_repeat = 0; |
| 67 | mousekey_clear_report(); | ||
| 68 | return; | 68 | return; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | // send immediately when buttun state is changed | 71 | // send immediately when buttun state is changed |
| 72 | if (report.buttons == report_prev.buttons) { | 72 | if (report.buttons == report_prev.buttons) { |
| 73 | // TODO: delay parameter setting | 73 | if (timer_elapsed(last_timer) < 5) { |
| 74 | if ((timer_elapsed(last_timer) < (mousekey_repeat == 1 ? 20 : 5))) { | 74 | mousekey_clear_report(); |
| 75 | return; | 75 | return; |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | if (mousekey_repeat != 0xFF) { | ||
| 80 | mousekey_repeat++; | ||
| 81 | } | ||
| 82 | |||
| 79 | if (report.x && report.y) { | 83 | if (report.x && report.y) { |
| 80 | report.x *= 0.7; | 84 | report.x *= 0.7; |
| 81 | report.y *= 0.7; | 85 | report.y *= 0.7; |
| 82 | } | 86 | } |
| 83 | 87 | ||
| 84 | /* | ||
| 85 | print("mousekey_repeat: "); phex(mousekey_repeat); print("\n"); | ||
| 86 | print("timer: "); phex16(timer_read()); print("\n"); | ||
| 87 | print("last_timer: "); phex16(last_timer); print("\n"); | ||
| 88 | print("mousekey: "); phex(report.buttons); print(" "); phex(report.x); print(" "); phex(report.y); print("\n"); | ||
| 89 | */ | ||
| 90 | |||
| 91 | mousekey_debug(); | 88 | mousekey_debug(); |
| 92 | |||
| 93 | host_mouse_send(&report); | 89 | host_mouse_send(&report); |
| 94 | report_prev.buttons = report.buttons; | 90 | report_prev = report; |
| 95 | report_prev.x = report.x; | ||
| 96 | report_prev.y = report.y; | ||
| 97 | if (mousekey_repeat != 0xFF) mousekey_repeat++; | ||
| 98 | last_timer = timer_read(); | 91 | last_timer = timer_read(); |
| 99 | mousekey_clear_report(); | 92 | mousekey_clear_report(); |
| 100 | } | 93 | } |
| @@ -104,6 +97,8 @@ void mousekey_clear_report(void) | |||
| 104 | report.buttons = 0; | 97 | report.buttons = 0; |
| 105 | report.x = 0; | 98 | report.x = 0; |
| 106 | report.y = 0; | 99 | report.y = 0; |
| 100 | report.v = 0; | ||
| 101 | report.h = 0; | ||
| 107 | } | 102 | } |
| 108 | 103 | ||
| 109 | static void mousekey_debug(void) | 104 | static void mousekey_debug(void) |
| @@ -113,9 +108,8 @@ static void mousekey_debug(void) | |||
| 113 | phex(report.buttons); print("|"); | 108 | phex(report.buttons); print("|"); |
| 114 | phex(report.x); print(" "); | 109 | phex(report.x); print(" "); |
| 115 | phex(report.y); print(" "); | 110 | phex(report.y); print(" "); |
| 116 | /* | ||
| 117 | phex(report.v); print(" "); | 111 | phex(report.v); print(" "); |
| 118 | phex(report.h); | 112 | phex(report.h); |
| 119 | */ | 113 | phex(mousekey_repeat); |
| 120 | print("\n"); | 114 | print("\n"); |
| 121 | } | 115 | } |
