1
0

Fix layer switching and host API.

This commit is contained in:
tmk 2012-10-12 04:46:37 +09:00
parent d91d8c0ba0
commit f5f200cb03
4 changed files with 193 additions and 155 deletions

View File

@ -27,10 +27,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
bool keyboard_nkro = false; bool keyboard_nkro = false;
#endif #endif
static host_driver_t *driver;
report_keyboard_t *keyboard_report = &(report_keyboard_t){}; report_keyboard_t *keyboard_report = &(report_keyboard_t){};
report_mouse_t mouse_report = {};
static host_driver_t *driver;
static uint16_t last_system_report = 0;
static uint16_t last_consumer_report = 0;
static inline void add_key_byte(uint8_t code); static inline void add_key_byte(uint8_t code);
static inline void del_key_byte(uint8_t code); static inline void del_key_byte(uint8_t code);
static inline void add_key_bit(uint8_t code); static inline void add_key_bit(uint8_t code);
@ -52,8 +56,48 @@ uint8_t host_keyboard_leds(void)
if (!driver) return 0; if (!driver) return 0;
return (*driver->keyboard_leds)(); return (*driver->keyboard_leds)();
} }
/* send report */
void host_keyboard_send(report_keyboard_t *report)
{
if (!driver) return;
(*driver->send_keyboard)(report);
/* keyboard report operations */ if (debug_keyboard) {
print("keys: ");
for (int i = 0; i < REPORT_KEYS; i++) {
phex(keyboard_report->keys[i]); print(" ");
}
print(" mods: "); phex(keyboard_report->mods); print("\n");
}
}
void host_mouse_send(report_mouse_t *report)
{
if (!driver) return;
(*driver->send_mouse)(report);
}
void host_system_send(uint16_t report)
{
if (report == last_system_report) return;
last_system_report = report;
if (!driver) return;
(*driver->send_system)(report);
}
void host_consumer_send(uint16_t report)
{
if (report == last_consumer_report) return;
last_consumer_report = report;
if (!driver) return;
(*driver->send_consumer)(report);
}
/* keyboard report utils */
void host_add_key(uint8_t key) void host_add_key(uint8_t key)
{ {
#ifdef NKRO_ENABLE #ifdef NKRO_ENABLE
@ -113,6 +157,11 @@ uint8_t host_has_anykey(void)
return cnt; return cnt;
} }
uint8_t host_has_anymod(void)
{
return bitpop(keyboard_report->mods);
}
uint8_t host_get_first_key(void) uint8_t host_get_first_key(void)
{ {
#ifdef NKRO_ENABLE #ifdef NKRO_ENABLE
@ -129,52 +178,24 @@ uint8_t host_get_first_key(void)
void host_send_keyboard_report(void) void host_send_keyboard_report(void)
{ {
if (!driver) return; if (!driver) return;
(*driver->send_keyboard)(keyboard_report); host_keyboard_send(keyboard_report);
if (debug_keyboard) {
print("keys: ");
for (int i = 0; i < REPORT_KEYS; i++) {
phex(keyboard_report->keys[i]); print(" ");
}
print(" mods: "); phex(keyboard_report->mods); print("\n");
}
} }
uint8_t host_mouse_in_use(void)
/* send report */
void host_keyboard_send(report_keyboard_t *report)
{ {
if (!driver) return; return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h);
(*driver->send_keyboard)(report);
} }
void host_mouse_send(report_mouse_t *report) uint16_t host_last_sysytem_report(void)
{ {
if (!driver) return; return last_system_report;
(*driver->send_mouse)(report);
} }
void host_system_send(uint16_t data) uint16_t host_last_consumer_report(void)
{ {
static uint16_t last_data = 0; return last_consumer_report;
if (data == last_data) return;
last_data = data;
if (!driver) return;
(*driver->send_system)(data);
} }
void host_consumer_send(uint16_t data)
{
static uint16_t last_data = 0;
if (data == last_data) return;
last_data = data;
if (!driver) return;
(*driver->send_consumer)(data);
}
static inline void add_key_byte(uint8_t code) static inline void add_key_byte(uint8_t code)
{ {
int8_t i = 0; int8_t i = 0;

View File

@ -31,38 +31,40 @@ extern "C" {
extern bool keyboard_nkro; extern bool keyboard_nkro;
#endif #endif
/* report */
extern report_keyboard_t *keyboard_report; extern report_keyboard_t *keyboard_report;
extern report_keyboard_t *keyboard_report_prev; extern report_mouse_t mouse_report;
/* host driver */ /* host driver */
void host_set_driver(host_driver_t *driver); void host_set_driver(host_driver_t *driver);
host_driver_t *host_get_driver(void); host_driver_t *host_get_driver(void);
/* host driver interface */
uint8_t host_keyboard_leds(void); uint8_t host_keyboard_leds(void);
void host_keyboard_send(report_keyboard_t *report);
void host_mouse_send(report_mouse_t *report);
void host_system_send(uint16_t data);
void host_consumer_send(uint16_t data);
/* keyboard report utils */
/* keyboard report operations */
/* key */
void host_add_key(uint8_t key); void host_add_key(uint8_t key);
void host_del_key(uint8_t key); void host_del_key(uint8_t key);
void host_clear_keys(void); void host_clear_keys(void);
/* modifier */
void host_add_mod_bit(uint8_t mod); void host_add_mod_bit(uint8_t mod);
void host_del_mod_bit(uint8_t mod); void host_del_mod_bit(uint8_t mod);
void host_set_mods(uint8_t mods); void host_set_mods(uint8_t mods);
void host_clear_mods(void); void host_clear_mods(void);
/* query */
uint8_t host_has_anykey(void); uint8_t host_has_anykey(void);
uint8_t host_has_anymod(void);
uint8_t host_get_first_key(void); uint8_t host_get_first_key(void);
/* send report */
void host_send_keyboard_report(void); void host_send_keyboard_report(void);
/* mouse report utils */
uint8_t host_mouse_in_use(void);
/* send report: mouse, system contorl and consumer page */ uint16_t host_last_sysytem_report(void);
void host_mouse_send(report_mouse_t *report); uint16_t host_last_consumer_report(void);
void host_system_send(uint16_t data);
void host_consumer_send(uint16_t data);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -110,6 +110,12 @@ static void clear_keyboard_but_mods(void)
#endif #endif
} }
static bool anykey_sent_to_host(void)
{
return (host_has_anykey() || host_mouse_in_use() ||
host_last_sysytem_report() || host_last_consumer_report());
}
static void layer_switch_on(uint8_t code) static void layer_switch_on(uint8_t code)
{ {
if (!IS_FN(code)) return; if (!IS_FN(code)) return;
@ -123,9 +129,9 @@ static void layer_switch_on(uint8_t code)
} }
} }
static void layer_switch_off(uint8_t code) static bool layer_switch_off(uint8_t code)
{ {
if (!IS_FN(code)) return; if (!IS_FN(code)) return false;
fn_state_bits &= ~FN_BIT(code); fn_state_bits &= ~FN_BIT(code);
if (current_layer != keymap_fn_layer(biton(fn_state_bits))) { if (current_layer != keymap_fn_layer(biton(fn_state_bits))) {
clear_keyboard_but_mods(); clear_keyboard_but_mods();
@ -133,21 +139,7 @@ static void layer_switch_off(uint8_t code)
debug("Layer Switch(off): "); debug_hex(current_layer); debug("Layer Switch(off): "); debug_hex(current_layer);
current_layer = keymap_fn_layer(biton(fn_state_bits)); current_layer = keymap_fn_layer(biton(fn_state_bits));
debug(" -> "); debug_hex(current_layer); debug("\n"); debug(" -> "); debug_hex(current_layer); debug("\n");
} return true;
}
// whether any key except modifier is down or not
static inline bool is_anykey_down(void)
{
for (int r = 0; r < MATRIX_ROWS; r++) {
matrix_row_t matrix_row = matrix_get_row(r);
for (int c = 0; c < MATRIX_COLS; c++) {
if (matrix_row && (1<<c)) {
if (IS_KEY(keymap_get_keycode(current_layer, r, c))) {
return true;
}
}
}
} }
return false; return false;
} }
@ -162,6 +154,10 @@ static void register_code(uint8_t code)
host_add_mod_bit(MOD_BIT(code)); host_add_mod_bit(MOD_BIT(code));
host_send_keyboard_report(); host_send_keyboard_report();
} }
else if IS_FN(code) {
host_add_key(keymap_fn_keycode(FN_INDEX(code)));
host_send_keyboard_report();
}
else if IS_MOUSEKEY(code) { else if IS_MOUSEKEY(code) {
#ifdef MOUSEKEY_ENABLE #ifdef MOUSEKEY_ENABLE
mousekey_on(code); mousekey_on(code);
@ -256,6 +252,10 @@ static void unregister_code(uint8_t code)
host_del_mod_bit(MOD_BIT(code)); host_del_mod_bit(MOD_BIT(code));
host_send_keyboard_report(); host_send_keyboard_report();
} }
else if IS_FN(code) {
host_del_key(keymap_fn_keycode(FN_INDEX(code)));
host_send_keyboard_report();
}
else if IS_MOUSEKEY(code) { else if IS_MOUSEKEY(code) {
#ifdef MOUSEKEY_ENABLE #ifdef MOUSEKEY_ENABLE
mousekey_off(code); mousekey_off(code);
@ -272,24 +272,31 @@ static void unregister_code(uint8_t code)
/* /*
* *
* Event/State|IDLE DELAYING[f] WAITING[f,k] PRESSING * Event/State|IDLE PRESSING DELAYING[f] WAITING[f,k]
* -----------+------------------------------------------------------------------ * -----------+------------------------------------------------------------------
* Fn Down |IDLE(L+) WAITING(Sk) WAITING(Sk) - * Fn Down |(L+) -*1 WAITING(Sk) IDLE(Rf,Ps)*7
* Up |IDLE(L-) IDLE(L-) IDLE(L-) IDLE(L-) * Up |(L-) IDLE(L-)*8 IDLE(L-)*8 IDLE(L-)*8
* Fnk Down |DELAYING(Sf) WAITING(Sk) WAINTING(Sk) PRESSING(Rf) * Fnk Down |DELAYING(Sf)* (Rf) WAITING(Sk) IDLE(Rf,Ps,Rf)
* Up |IDLE(L-) IDLE(Rf,Uf) IDLE(Rf,Ps,Uf)*3 PRESSING(Uf) * Up |(L-) IDLE(L-/Uf)*8 IDLE(Rf,Uf/L-)*3 IDLE(Rf,Ps,Uf/L-)*3
* Key Down |PRESSING(Rk) WAITING(Sk) WAITING(Sk) PRESSING(Rk) * Key Down |PRESSING(Rk) (Rk) WAITING(Sk) IDLE(Rf,Ps,Rk)
* Up |IDLE(Uk) DELAYING(Uk) IDLE(L+,Ps,Uk) IDLE(Uk)*4 * Up |(Uk) IDLE(Uk)*4 (Uk) IDLE(L+,Ps,Pk)/(Uk)*a
* Delay |- IDLE(L+) IDLE(L+,Ps) -
* | * |
* No key Down|IDLE(Ld) IDLE(Ld) IDLE(Ld) IDLE(Ld) * Delay |- - IDLE(L+) IDLE(L+,Ps)
* Magic Key |COMMAND*5
* *
* *1: ignore Fn if other key is down.
* *2: register Fnk if any key is pressing * *2: register Fnk if any key is pressing
* *3: when Fnk == Stored Fnk, if not ignore. * *3: register/unregister delayed Fnk and move to IDLE if code == delayed Fnk, else *8
* *4: when no registered key any more * *4: if no keys registered to host
* *5: unregister all keys
* *6: only if no keys down
* *7: ignore Fn because Fnk key and stored key are down.
* *8: move to IDLE if layer switch(off) occurs, else stay at current state
* *9: repeat key if pressing Fnk twice quickly(move to PRESSING)
* *a: layer switch and process waiting key and code if code == wainting key, else unregister key
* *
* States: * States:
* IDLE: * IDLE: No key is down except modifiers
* DELAYING: delay layer switch after pressing Fn with alt keycode * DELAYING: delay layer switch after pressing Fn with alt keycode
* WAITING: key is pressed during DELAYING * WAITING: key is pressed during DELAYING
* *
@ -297,17 +304,20 @@ static void unregister_code(uint8_t code)
* Fn: Fn key without alternative keycode * Fn: Fn key without alternative keycode
* Fnk: Fn key with alternative keycode * Fnk: Fn key with alternative keycode
* -: ignore * -: ignore
* Delay: layer switch delay term is elapsed
* *
* Actions: * Actions:
* Rk: register key * Rk: register key
* Uk: unregister key * Uk: unregister key
* Rf: register stored Fn(alt keycode) * Rf: register Fn(alt keycode)
* Uf: unregister stored Fn(alt keycode) * Uf: unregister Fn(alt keycode)
* Rs: register stored key * Rs: register stored key
* Us: unregister stored key * Us: unregister stored key
* Sk: store key * Sk: Store key(waiting Key)
* Sf: store Fn * Sf: Store Fn(delayed Fn)
* Ps: play stored key(Interpret stored key and transit state) * Ps: Process stored key
* Ps: Process key
* Is: Interpret stored keys in current layer
* L+: Switch to new layer(*unregister* all keys but modifiers) * L+: Switch to new layer(*unregister* all keys but modifiers)
* L-: Switch back to last layer(*unregister* all keys but modifiers) * L-: Switch back to last layer(*unregister* all keys but modifiers)
* Ld: Switch back to default layer(*unregister* all keys but modifiers) * Ld: Switch back to default layer(*unregister* all keys but modifiers)
@ -344,7 +354,7 @@ static inline void process_key(keyevent_t event)
// repeat Fn alt key when press Fn key down, up then down again quickly // repeat Fn alt key when press Fn key down, up then down again quickly
if (KEYEQ(delayed_fn.event.key, event.key) && if (KEYEQ(delayed_fn.event.key, event.key) &&
timer_elapsed(delayed_fn.time) < LAYER_DELAY) { timer_elapsed(delayed_fn.time) < LAYER_DELAY) {
register_code(keymap_fn_keycode(FN_INDEX(code))); register_code(code);
NEXT(PRESSING); NEXT(PRESSING);
} else { } else {
delayed_fn = (keyrecord_t) { delayed_fn = (keyrecord_t) {
@ -380,16 +390,20 @@ static inline void process_key(keyevent_t event)
// ignored when any key is pressed // ignored when any key is pressed
break; break;
case FN_UP: case FN_UP:
layer_switch_off(code); if (layer_switch_off(code))
NEXT(IDLE); NEXT(IDLE);
break; break;
case FNK_DOWN: case FNK_DOWN:
register_code(keymap_fn_keycode(FN_INDEX(code))); register_code(code);
break; break;
case FNK_UP: case FNK_UP:
// can't know whether layer switched or not if (layer_switch_off(code)) {
layer_switch_off(code); NEXT(IDLE);
unregister_code(keymap_fn_keycode(FN_INDEX(code))); } else {
unregister_code(code);
if (!anykey_sent_to_host())
NEXT(IDLE);
}
break; break;
case KEY_DOWN: case KEY_DOWN:
case MOD_DOWN: case MOD_DOWN:
@ -398,8 +412,7 @@ static inline void process_key(keyevent_t event)
case KEY_UP: case KEY_UP:
case MOD_UP: case MOD_UP:
unregister_code(code); unregister_code(code);
// TODO: no key registered? mousekey, mediakey, systemkey if (!anykey_sent_to_host())
if (!host_has_anykey())
NEXT(IDLE); NEXT(IDLE);
break; break;
default: default:
@ -423,8 +436,8 @@ static inline void process_key(keyevent_t event)
register_code(code); register_code(code);
break; break;
case FN_UP: case FN_UP:
layer_switch_off(code); if (layer_switch_off(code))
NEXT(IDLE); NEXT(IDLE);
break; break;
case FNK_UP: case FNK_UP:
if (code == delayed_fn.code) { if (code == delayed_fn.code) {
@ -432,19 +445,16 @@ static inline void process_key(keyevent_t event)
// restore the mod status at the time of pressing Fn key // restore the mod status at the time of pressing Fn key
tmp_mods = keyboard_report->mods; tmp_mods = keyboard_report->mods;
host_set_mods(delayed_fn.mods); host_set_mods(delayed_fn.mods);
register_code(keymap_fn_keycode(FN_INDEX(delayed_fn.code))); register_code(delayed_fn.code);
unregister_code(keymap_fn_keycode(FN_INDEX(delayed_fn.code))); unregister_code(delayed_fn.code);
host_set_mods(tmp_mods); host_set_mods(tmp_mods);
NEXT(IDLE); NEXT(IDLE);
} else { } else {
layer_switch_off(code); if (layer_switch_off(code))
NEXT(IDLE); NEXT(IDLE);
} }
break; break;
case KEY_UP: case KEY_UP:
unregister_code(code);
NEXT(IDLE);
break;
case MOD_UP: case MOD_UP:
unregister_code(code); unregister_code(code);
break; break;
@ -459,34 +469,40 @@ static inline void process_key(keyevent_t event)
case KEY_DOWN: case KEY_DOWN:
tmp_mods = keyboard_report->mods; tmp_mods = keyboard_report->mods;
host_set_mods(delayed_fn.mods); host_set_mods(delayed_fn.mods);
register_code(keymap_fn_keycode(FN_INDEX(delayed_fn.code))); register_code(delayed_fn.code);
host_set_mods(waiting_key.mods); host_set_mods(waiting_key.mods);
register_code(waiting_key.code); register_code(waiting_key.code);
host_set_mods(tmp_mods); host_set_mods(tmp_mods);
register_code(code); if (kind == FN_DOWN) {
// ignore Fn
} else if (kind == FNK_DOWN) {
register_code(code);
} else if (kind == KEY_DOWN) {
register_code(code);
}
NEXT(IDLE); NEXT(IDLE);
break; break;
case MOD_DOWN: case MOD_DOWN:
register_code(code); register_code(code);
break; break;
case FN_UP: case FN_UP:
layer_switch_off(code); if (layer_switch_off(code))
NEXT(IDLE); NEXT(IDLE);
break; break;
case FNK_UP: case FNK_UP:
if (code == delayed_fn.code) { if (code == delayed_fn.code) {
// alt down, key down, alt up // alt down, key down, alt up
tmp_mods = keyboard_report->mods; tmp_mods = keyboard_report->mods;
host_set_mods(delayed_fn.mods); host_set_mods(delayed_fn.mods);
register_code(keymap_fn_keycode(FN_INDEX(delayed_fn.code))); register_code(delayed_fn.code);
host_set_mods(waiting_key.mods); host_set_mods(waiting_key.mods);
register_code(waiting_key.code); register_code(waiting_key.code);
unregister_code(keymap_fn_keycode(FN_INDEX(delayed_fn.code))); unregister_code(delayed_fn.code);
host_set_mods(tmp_mods); host_set_mods(tmp_mods);
NEXT(IDLE); NEXT(IDLE);
} else { } else {
layer_switch_off(code); if (layer_switch_off(code))
NEXT(IDLE); NEXT(IDLE);
} }
break; break;
case KEY_UP: case KEY_UP:

View File

@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mousekey.h" #include "mousekey.h"
static report_mouse_t report;
static uint8_t mousekey_repeat = 0; static uint8_t mousekey_repeat = 0;
@ -115,89 +114,89 @@ void mousekey_task(void)
if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10)) if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10))
return; return;
if (report.x == 0 && report.y == 0 && report.v == 0 && report.h == 0) if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0)
return; return;
if (mousekey_repeat != UINT8_MAX) if (mousekey_repeat != UINT8_MAX)
mousekey_repeat++; mousekey_repeat++;
if (report.x > 0) report.x = move_unit(); if (mouse_report.x > 0) mouse_report.x = move_unit();
if (report.x < 0) report.x = move_unit() * -1; if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
if (report.y > 0) report.y = move_unit(); if (mouse_report.y > 0) mouse_report.y = move_unit();
if (report.y < 0) report.y = move_unit() * -1; if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
if (report.x && report.y) { if (mouse_report.x && mouse_report.y) {
report.x *= 0.7; mouse_report.x *= 0.7;
report.y *= 0.7; mouse_report.y *= 0.7;
} }
if (report.v > 0) report.v = wheel_unit(); if (mouse_report.v > 0) mouse_report.v = wheel_unit();
if (report.v < 0) report.v = wheel_unit() * -1; if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
if (report.h > 0) report.h = wheel_unit(); if (mouse_report.h > 0) mouse_report.h = wheel_unit();
if (report.h < 0) report.h = wheel_unit() * -1; if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1;
mousekey_send(); mousekey_send();
} }
void mousekey_on(uint8_t code) void mousekey_on(uint8_t code)
{ {
if (code == KC_MS_UP) report.y = MOUSEKEY_MOVE_DELTA * -1; if (code == KC_MS_UP) mouse_report.y = MOUSEKEY_MOVE_DELTA * -1;
else if (code == KC_MS_DOWN) report.y = MOUSEKEY_MOVE_DELTA; else if (code == KC_MS_DOWN) mouse_report.y = MOUSEKEY_MOVE_DELTA;
else if (code == KC_MS_LEFT) report.x = MOUSEKEY_MOVE_DELTA * -1; else if (code == KC_MS_LEFT) mouse_report.x = MOUSEKEY_MOVE_DELTA * -1;
else if (code == KC_MS_RIGHT) report.x = MOUSEKEY_MOVE_DELTA; else if (code == KC_MS_RIGHT) mouse_report.x = MOUSEKEY_MOVE_DELTA;
else if (code == KC_MS_WH_UP) report.v = MOUSEKEY_WHEEL_DELTA; else if (code == KC_MS_WH_UP) mouse_report.v = MOUSEKEY_WHEEL_DELTA;
else if (code == KC_MS_WH_DOWN) report.v = MOUSEKEY_WHEEL_DELTA * -1; else if (code == KC_MS_WH_DOWN) mouse_report.v = MOUSEKEY_WHEEL_DELTA * -1;
else if (code == KC_MS_WH_LEFT) report.h = MOUSEKEY_WHEEL_DELTA * -1; else if (code == KC_MS_WH_LEFT) mouse_report.h = MOUSEKEY_WHEEL_DELTA * -1;
else if (code == KC_MS_WH_RIGHT) report.h = MOUSEKEY_WHEEL_DELTA; else if (code == KC_MS_WH_RIGHT) mouse_report.h = MOUSEKEY_WHEEL_DELTA;
else if (code == KC_MS_BTN1) report.buttons |= MOUSE_BTN1; else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1;
else if (code == KC_MS_BTN2) report.buttons |= MOUSE_BTN2; else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2;
else if (code == KC_MS_BTN3) report.buttons |= MOUSE_BTN3; else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3;
else if (code == KC_MS_BTN4) report.buttons |= MOUSE_BTN4; else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4;
else if (code == KC_MS_BTN5) report.buttons |= MOUSE_BTN5; else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5;
} }
void mousekey_off(uint8_t code) void mousekey_off(uint8_t code)
{ {
if (code == KC_MS_UP && report.y < 0) report.y = 0; if (code == KC_MS_UP && mouse_report.y < 0) mouse_report.y = 0;
else if (code == KC_MS_DOWN && report.y > 0) report.y = 0; else if (code == KC_MS_DOWN && mouse_report.y > 0) mouse_report.y = 0;
else if (code == KC_MS_LEFT && report.x < 0) report.x = 0; else if (code == KC_MS_LEFT && mouse_report.x < 0) mouse_report.x = 0;
else if (code == KC_MS_RIGHT && report.x > 0) report.x = 0; else if (code == KC_MS_RIGHT && mouse_report.x > 0) mouse_report.x = 0;
else if (code == KC_MS_WH_UP && report.v > 0) report.v = 0; else if (code == KC_MS_WH_UP && mouse_report.v > 0) mouse_report.v = 0;
else if (code == KC_MS_WH_DOWN && report.v < 0) report.v = 0; else if (code == KC_MS_WH_DOWN && mouse_report.v < 0) mouse_report.v = 0;
else if (code == KC_MS_WH_LEFT && report.h < 0) report.h = 0; else if (code == KC_MS_WH_LEFT && mouse_report.h < 0) mouse_report.h = 0;
else if (code == KC_MS_WH_RIGHT && report.h > 0) report.h = 0; else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0;
else if (code == KC_MS_BTN1) report.buttons &= ~MOUSE_BTN1; else if (code == KC_MS_BTN1) mouse_report.buttons &= ~MOUSE_BTN1;
else if (code == KC_MS_BTN2) report.buttons &= ~MOUSE_BTN2; else if (code == KC_MS_BTN2) mouse_report.buttons &= ~MOUSE_BTN2;
else if (code == KC_MS_BTN3) report.buttons &= ~MOUSE_BTN3; else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3;
else if (code == KC_MS_BTN4) report.buttons &= ~MOUSE_BTN4; else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4;
else if (code == KC_MS_BTN5) report.buttons &= ~MOUSE_BTN5; else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5;
if (report.x == 0 && report.y == 0 && report.v == 0 && report.h == 0) if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0)
mousekey_repeat = 0; mousekey_repeat = 0;
} }
void mousekey_send(void) void mousekey_send(void)
{ {
mousekey_debug(); mousekey_debug();
host_mouse_send(&report); host_mouse_send(&mouse_report);
last_timer = timer_read(); last_timer = timer_read();
} }
void mousekey_clear(void) void mousekey_clear(void)
{ {
report = (report_mouse_t){}; mouse_report = (report_mouse_t){};
} }
static void mousekey_debug(void) static void mousekey_debug(void)
{ {
if (!debug_mouse) return; if (!debug_mouse) return;
print("mousekey [btn|x y v h]rep: ["); print("mousekey [btn|x y v h]rep: [");
phex(report.buttons); print("|"); phex(mouse_report.buttons); print("|");
phex(report.x); print(" "); phex(mouse_report.x); print(" ");
phex(report.y); print(" "); phex(mouse_report.y); print(" ");
phex(report.v); print(" "); phex(mouse_report.v); print(" ");
phex(report.h); print("]"); phex(mouse_report.h); print("]");
phex(mousekey_repeat); phex(mousekey_repeat);
print("\n"); print("\n");
} }