diff options
| author | tmk <nobody@nowhere> | 2011-02-03 13:26:44 +0900 | 
|---|---|---|
| committer | tmk <nobody@nowhere> | 2011-02-22 03:08:52 +0900 | 
| commit | 0632618d29dfb30c76b4e7c310dc7bee36919f63 (patch) | |
| tree | 8a5b0bab7a1b46b83943e3676cf868137fd91fa7 /ps2_vusb/mousekey.c | |
| parent | 4f5f1a53d449172263e83c5769c92976e0d3332e (diff) | |
| download | firmware-0632618d29dfb30c76b4e7c310dc7bee36919f63.tar.gz firmware-0632618d29dfb30c76b4e7c310dc7bee36919f63.tar.bz2 firmware-0632618d29dfb30c76b4e7c310dc7bee36919f63.zip | |
added initial support of mousekeys to ps2_vusb
Diffstat (limited to 'ps2_vusb/mousekey.c')
| -rw-r--r-- | ps2_vusb/mousekey.c | 102 | 
1 files changed, 102 insertions, 0 deletions
| diff --git a/ps2_vusb/mousekey.c b/ps2_vusb/mousekey.c new file mode 100644 index 000000000..a311eecc2 --- /dev/null +++ b/ps2_vusb/mousekey.c @@ -0,0 +1,102 @@ +#include <stdint.h> +#include <util/delay.h> +#include "usb_keycodes.h" +#include "host.h" +#include "timer.h" +#include "print.h" +#include "mousekey.h" + + +static report_mouse_t report; +static report_mouse_t report_prev; + +static uint8_t mousekey_repeat =  0; + + +/* + * TODO: fix acceleration algorithm + * see wikipedia http://en.wikipedia.org/wiki/Mouse_keys + */ +#ifndef MOUSEKEY_DELAY_TIME +#   define MOUSEKEY_DELAY_TIME 255 +#endif + + +static inline uint8_t move_unit(void) +{ +    uint8_t unit = (10 + (mousekey_repeat)); +    return unit > 127 ? 127 : unit; +} + +void mousekey_decode(uint8_t code) +{ +    if      (code == KB_MS_UP)      report.y -= move_unit(); +    else if (code == KB_MS_DOWN)    report.y += move_unit(); +    else if (code == KB_MS_LEFT)    report.x -= move_unit(); +    else if (code == KB_MS_RIGHT)   report.x += move_unit(); +    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; +*/ +} + +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); +} + +void mousekey_send(void) +{ +    static uint16_t last_timer = 0; + +    if (!mousekey_changed()) { +        mousekey_repeat = 0; +        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))) { +            return; +        } +    } + +    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"); +    */ + +    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++; +    last_timer = timer_read(); +    mousekey_clear_report(); +} + +void mousekey_clear_report(void) +{ +    report.buttons = 0; +    report.x = 0; +    report.y = 0; +} | 
