X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mousekey.c;h=76bd0fd3630fcaa8d3744d3b88e60823e3605a01;hb=d553289e7edfdf17dfe4fb9cf45a3b23ea2e03df;hp=2e9b8cb1aaf7172368e6803872e3135b8e5193fd;hpb=2b8cd88ab142068eed0a3f230a3de79deb567536;p=tmk_firmware.git diff --git a/mousekey.c b/mousekey.c old mode 100644 new mode 100755 index 2e9b8cb..76bd0fd --- a/mousekey.c +++ b/mousekey.c @@ -1,3 +1,20 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + #include #include #include "usb_keycodes.h" @@ -24,11 +41,15 @@ static void mousekey_debug(void); # define MOUSEKEY_DELAY_TIME 255 #endif +// acceleration parameters +uint8_t mousekey_move_unit = 2; +uint8_t mousekey_resolution = 5; + static inline uint8_t move_unit(void) { - uint16_t unit = 10 + (mousekey_repeat); - return (unit > 127 ? 127 : unit); + uint16_t unit = 5 + mousekey_repeat*2; + return (unit > 63 ? 63 : unit); } void mousekey_decode(uint8_t code) @@ -40,23 +61,18 @@ void mousekey_decode(uint8_t code) else if (code == KB_MS_BTN1) report.buttons |= MOUSE_BTN1; else if (code == KB_MS_BTN2) report.buttons |= MOUSE_BTN2; else if (code == KB_MS_BTN3) report.buttons |= MOUSE_BTN3; -/* else if (code == KB_MS_BTN4) report.buttons |= MOUSE_BTN4; else if (code == KB_MS_BTN5) report.buttons |= MOUSE_BTN5; - else if (code == KB_MS_WH_UP) report.v += 1; - else if (code == KB_MS_WH_DOWN) report.v -= 1; - else if (code == KB_MS_WH_LEFT) report.h -= 1; - else if (code == KB_MS_WH_RIGHT)report.h += 1; -*/ + else if (code == KB_MS_WH_UP) report.v += move_unit()/4; + else if (code == KB_MS_WH_DOWN) report.v -= move_unit()/4; + else if (code == KB_MS_WH_LEFT) report.h -= move_unit()/4; + else if (code == KB_MS_WH_RIGHT)report.h += move_unit()/4; } bool mousekey_changed(void) { return (report.buttons != report_prev.buttons || - report.x != report_prev.x || - report.y != report_prev.y || - report.x || report.y); - //return (report.buttons != report_prev.buttons || report.x || report.y); + report.x || report.y || report.v || report.h); } void mousekey_send(void) @@ -65,36 +81,30 @@ void mousekey_send(void) if (!mousekey_changed()) { mousekey_repeat = 0; + mousekey_clear_report(); return; } // send immediately when buttun state is changed if (report.buttons == report_prev.buttons) { - // TODO: delay parameter setting - if ((timer_elapsed(last_timer) < (mousekey_repeat == 1 ? 20 : 5))) { + if (timer_elapsed(last_timer) < 100) { + mousekey_clear_report(); return; } } + if (mousekey_repeat != 0xFF) { + mousekey_repeat++; + } + if (report.x && report.y) { report.x *= 0.7; report.y *= 0.7; } - /* - print("mousekey_repeat: "); phex(mousekey_repeat); print("\n"); - print("timer: "); phex16(timer_read()); print("\n"); - print("last_timer: "); phex16(last_timer); print("\n"); - print("mousekey: "); phex(report.buttons); print(" "); phex(report.x); print(" "); phex(report.y); print("\n"); - */ - mousekey_debug(); - host_mouse_send(&report); - report_prev.buttons = report.buttons; - report_prev.x = report.x; - report_prev.y = report.y; - if (mousekey_repeat != 0xFF) mousekey_repeat++; + report_prev = report; last_timer = timer_read(); mousekey_clear_report(); } @@ -104,6 +114,8 @@ void mousekey_clear_report(void) report.buttons = 0; report.x = 0; report.y = 0; + report.v = 0; + report.h = 0; } static void mousekey_debug(void) @@ -113,9 +125,8 @@ static void mousekey_debug(void) phex(report.buttons); print("|"); phex(report.x); print(" "); phex(report.y); print(" "); -/* phex(report.v); print(" "); phex(report.h); -*/ + phex(mousekey_repeat); print("\n"); }