Add an alternate version of our keystate code that depends on in-hardware

debouncing
pull/18/head
Jesse Vincent 9 years ago
parent 719ab8e6c7
commit 5e49c8fef3

@ -2,19 +2,19 @@
const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST };
void handle_synthetic_key_event(uint8_t switchState, Key mappedKey) {
void handle_synthetic_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) {
if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) {
handle_mouse_key_event(switchState, mappedKey);
handle_mouse_key_event(mappedKey, currentState, previousState);
} else if (! (mappedKey.flags & IS_INTERNAL)
&& (mappedKey.rawKey == KEY_MOUSE_BTN_L
|| mappedKey.rawKey == KEY_MOUSE_BTN_M
|| mappedKey.rawKey == KEY_MOUSE_BTN_R)) {
if (key_toggled_on (switchState)) {
if (key_toggled_on(currentState, previousState)) {
MouseWrapper.press_button(
(mappedKey.rawKey == KEY_MOUSE_BTN_L ? KEY_MOUSE_BUTTON_LEFT : 0x00) |
(mappedKey.rawKey == KEY_MOUSE_BTN_M ? KEY_MOUSE_BUTTON_MIDDLE : 0x00) |
(mappedKey.rawKey == KEY_MOUSE_BTN_R ? KEY_MOUSE_BUTTON_RIGHT : 0x00) );
} else if (key_toggled_off(switchState)) {
} else if (key_toggled_off(currentState, previousState)) {
MouseWrapper.release_button(
(mappedKey.rawKey == KEY_MOUSE_BTN_L ? KEY_MOUSE_BUTTON_LEFT : 0x00) |
(mappedKey.rawKey == KEY_MOUSE_BTN_M ? KEY_MOUSE_BUTTON_MIDDLE : 0x00) |
@ -23,7 +23,7 @@ void handle_synthetic_key_event(uint8_t switchState, Key mappedKey) {
}
else if (key_toggled_on(switchState)) {
else if (key_toggled_on(currentState,previousState)) {
if (mappedKey.rawKey & KEY_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
@ -46,18 +46,18 @@ void handle_synthetic_key_event(uint8_t switchState, Key mappedKey) {
}
}
void handle_key_event(byte row, byte col, uint8_t *switchState) {
void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previousState) {
//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
Key mappedKey = keymaps[temporary_keymap][row][col];
if (keymaps[primary_keymap][row][col].flags & SWITCH_TO_KEYMAP) {
handle_keymap_key_event(*switchState, keymaps[primary_keymap][row][col]);
handle_keymap_key_event(keymaps[primary_keymap][row][col], currentState, previousState);
}
if (mappedKey.flags & SYNTHETIC_KEY) {
handle_synthetic_key_event(*switchState, mappedKey);
} else if (key_is_pressed(*switchState)) {
else if (mappedKey.flags & SYNTHETIC_KEY) {
handle_synthetic_key_event( mappedKey, currentState, previousState);
} else if (key_is_pressed(currentState, previousState)) {
press_key(mappedKey);
}
}
@ -79,9 +79,9 @@ void press_key(Key mappedKey) {
}
void handle_keymap_key_event(uint8_t switchState, Key keymapEntry) {
void handle_keymap_key_event(Key keymapEntry, uint8_t currentState, uint8_t previousState) {
if (keymapEntry.flags & MOMENTARY ) {
if (key_toggled_on(switchState)) {
if (key_toggled_on(currentState, previousState)) {
if ( keymapEntry.rawKey == KEYMAP_NEXT) {
temporary_keymap++;
} else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) {
@ -90,19 +90,19 @@ void handle_keymap_key_event(uint8_t switchState, Key keymapEntry) {
temporary_keymap = keymapEntry.rawKey;
}
}
if (key_toggled_off(switchState)) {
if (key_toggled_off(currentState, previousState)) {
temporary_keymap = primary_keymap;
}
// switch keymap and stay there
} else if (key_toggled_on(switchState)) {
} else if (key_toggled_on(currentState, previousState)) {
temporary_keymap = primary_keymap = keymapEntry.rawKey;
Storage.save_primary_keymap(primary_keymap);
}
}
void handle_mouse_key_event(uint8_t switchState, Key mappedKey) {
if (key_is_pressed(switchState)) {
void handle_mouse_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) {
if (key_is_pressed(currentState,previousState)) {
if (mappedKey.rawKey & KEY_MOUSE_UP) {
MouseWrapper.move(0,-1);
}

@ -14,9 +14,9 @@ extern uint8_t primary_keymap;
extern uint8_t temporary_keymap;
// sending events to the computer
void handle_synthetic_key_event(uint8_t switchState, Key mappedKey);
void handle_key_event(byte row, byte col, uint8_t *switch_state);
void handle_synthetic_key_event( Key mappedKey, uint8_t currentState, uint8_t previousState);
void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previousState);
void press_key(Key mappedKey);
void handle_keymap_key_event(uint8_t switchState, Key keymapEntry);
void handle_mouse_key_event(uint8_t switchState, Key mappedKey);
void handle_keymap_key_event(Key keymapEntry, uint8_t currentState, uint8_t previousState);
void handle_mouse_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState);

@ -10,6 +10,14 @@ boolean key_was_pressed (byte keyState) {
}
}
boolean key_was_pressed (uint8_t currentState, uint8_t previousState) {
if (previousState) {
return true;
} else {
return false;
}
}
boolean key_is_pressed (byte keyState) {
if ( keyState & B00000001 && keyState & B00000010 ) {
return true;
@ -18,6 +26,14 @@ boolean key_is_pressed (byte keyState) {
}
}
boolean key_is_pressed (uint8_t currentState, uint8_t previousState) {
if (currentState) {
return true;
} else {
return false;
}
}
boolean key_toggled_on(byte keyState) {
if (key_is_pressed(keyState) && ! key_was_pressed(keyState)) {
return true;
@ -26,6 +42,14 @@ boolean key_toggled_on(byte keyState) {
}
}
boolean key_toggled_on (uint8_t currentState, uint8_t previousState) {
if (currentState && ! previousState ) {
return true;
} else {
return false;
}
}
boolean key_toggled_off(byte keyState) {
if (key_was_pressed(keyState) && ! key_is_pressed(keyState)) {
@ -34,3 +58,11 @@ boolean key_toggled_off(byte keyState) {
return false;
}
}
boolean key_toggled_off (uint8_t currentState, uint8_t previousState) {
if (previousState && ! currentState ) {
return true;
} else {
return false;
}
}

@ -8,3 +8,8 @@ boolean key_was_pressed (byte keyState);
boolean key_is_pressed (byte keyState);
boolean key_toggled_on(byte keyState);
boolean key_toggled_off(byte keyState);
boolean key_was_pressed (uint8_t currentState, uint8_t previousState);
boolean key_is_pressed (uint8_t currentState, uint8_t previousState);
boolean key_toggled_on(uint8_t currentState, uint8_t previousState);
boolean key_toggled_off(uint8_t currentState, uint8_t previousState);

Loading…
Cancel
Save