Refactor a bit of code for clarity..that also saves us a fair bit of flash

pull/18/head
Jesse Vincent 9 years ago
parent 1d0b628470
commit 3333df16d9

@ -1,38 +1,8 @@
#include "key_events.h" #include "key_events.h"
void handle_synthetic_key_event(byte switchState, Key mappedKey) { void handle_synthetic_key_event(byte switchState, Key mappedKey) {
if (mappedKey.flags & IS_MOUSE_KEY ) { if (mappedKey.flags & IS_MOUSE_KEY & ! (mappedKey.rawKey & MOUSE_WARP )) {
if (mappedKey.rawKey & MOUSE_WARP) { handle_mouse_key_event(switchState, mappedKey);
if (key_toggled_on(switchState)) {
// we don't pass in the left and up values because those are the
// default, "no-op" conditionals
MouseWrapper.warp( (mappedKey.rawKey & MOUSE_WARP_END ? WARP_END : 0x00) |
(mappedKey.rawKey & MOUSE_DOWN ? WARP_DOWN : 0x00) |
(mappedKey.rawKey & MOUSE_RIGHT ? WARP_RIGHT : 0x00) );
}
} else {
handle_mouse_key_event(switchState, mappedKey);
}
} else if (mappedKey.flags & IS_CONSUMER) {
if (key_toggled_on (switchState)) {
ConsumerControl.press(mappedKey.rawKey);
}
} else if (mappedKey.flags & IS_INTERNAL) {
if (key_toggled_on (switchState)) {
if (mappedKey.rawKey == LED_TOGGLE) {
LEDControl.next_mode();
}
}
} else if (mappedKey.flags & IS_SYSCTL) {
if (key_toggled_on (switchState)) {
SystemControl.press(mappedKey.rawKey);
}
} else if (mappedKey.flags & IS_MACRO) {
if (key_toggled_on (switchState)) {
if (mappedKey.rawKey == 1) {
Serial.print("Keyboard.IO keyboard driver v0.00");
}
}
} else if (mappedKey.rawKey == KEY_MOUSE_BTN_L } else if (mappedKey.rawKey == KEY_MOUSE_BTN_L
|| mappedKey.rawKey == KEY_MOUSE_BTN_M || mappedKey.rawKey == KEY_MOUSE_BTN_M
|| mappedKey.rawKey == KEY_MOUSE_BTN_R) { || mappedKey.rawKey == KEY_MOUSE_BTN_R) {
@ -49,8 +19,31 @@ void handle_synthetic_key_event(byte switchState, Key mappedKey) {
(mappedKey.rawKey == KEY_MOUSE_BTN_R ? MOUSE_BUTTON_RIGHT : 0x00) ); (mappedKey.rawKey == KEY_MOUSE_BTN_R ? MOUSE_BUTTON_RIGHT : 0x00) );
} }
} }
}
else if (key_toggled_on(switchState)) {
if (mappedKey.rawKey & MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) {
// we don't pass in the left and up values because those are the
// default, "no-op" conditionals
MouseWrapper.warp( (mappedKey.rawKey & MOUSE_WARP_END ? WARP_END : 0x00) |
(mappedKey.rawKey & MOUSE_DOWN ? WARP_DOWN : 0x00) |
(mappedKey.rawKey & MOUSE_RIGHT ? WARP_RIGHT : 0x00) );
} else if (mappedKey.flags & IS_CONSUMER) {
ConsumerControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & IS_INTERNAL) {
if (mappedKey.rawKey == LED_TOGGLE) {
LEDControl.next_mode();
}
} else if (mappedKey.flags & IS_SYSCTL) {
SystemControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & IS_MACRO) {
if (mappedKey.rawKey == 1) {
Serial.print("Keyboard.IO keyboard driver v0.00");
}
}
}
}
void handle_key_event(byte row, byte col) { void handle_key_event(byte row, byte col) {
//for every newly pressed button, figure out what logical key it is and send a key down event //for every newly pressed button, figure out what logical key it is and send a key down event
// for every newly released button, figure out what logical key it is and send a key up event // for every newly released button, figure out what logical key it is and send a key up event
@ -104,12 +97,10 @@ void handle_keymap_key_event(byte switchState, Key keymapEntry) {
temporary_keymap = primary_keymap; temporary_keymap = primary_keymap;
} }
} else {
// switch keymap and stay there // switch keymap and stay there
if (key_toggled_on(switchState)) { } else if (key_toggled_on(switchState)) {
temporary_keymap = primary_keymap = keymapEntry.rawKey; temporary_keymap = primary_keymap = keymapEntry.rawKey;
Storage.save_primary_keymap(primary_keymap); Storage.save_primary_keymap(primary_keymap);
}
} }
} }

Loading…
Cancel
Save