add next/prev layer feature so we don't need to hardcode keymap layers

pull/18/head
Jesse Vincent 11 years ago
parent a1fe10f684
commit e6176b2176

@ -29,7 +29,6 @@
#define COLS 14
#define ROWS 5
#define LAYERS 6
static const byte colPins[COLS] = { 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
@ -298,17 +297,27 @@ void scan_matrix()
if (! (keymaps[active_layer][row][col].flags ^ ( MOMENTARY | SWITCH_TO_LAYER))) { // this logic sucks. there is a better way TODO this
// this logic sucks. there is a better way TODO this
if (! (keymaps[active_layer][row][col].flags ^ ( MOMENTARY | SWITCH_TO_LAYER))) {
if (key_is_pressed(matrixState[row][col])) {
active_layer = keymaps[current_layer][row][col].rawKey;
} }
else if (! (keymaps[active_layer][row][col].flags ^ ( SWITCH_TO_LAYER))) { // switch layer and stay there
if ( keymaps[current_layer][row][col].rawKey == LAYER_NEXT) {
active_layer++;
} else if ( keymaps[current_layer][row][col].rawKey == LAYER_PREVIOUS) {
active_layer--;
} else {
active_layer = keymaps[current_layer][row][col].rawKey;
}
}
}
else if (! (keymaps[active_layer][row][col].flags ^ ( SWITCH_TO_LAYER))) {
// switch layer and stay there
if (key_toggled_on(matrixState[row][col])) {
current_layer = active_layer = keymaps[current_layer][row][col].rawKey;
save_current_layer(current_layer);
current_layer = active_layer = keymaps[current_layer][row][col].rawKey;
save_current_layer(current_layer);
}
}
}
}
digitalWrite(rowPins[row], HIGH);

@ -27,6 +27,11 @@
#define LAYER_7 7
#define LAYER_PREVIOUS 253
#define LAYER_NEXT 254
#define Key_NoKey (Key){ KEY_FLAGS,0 }
#define Key_skip (Key){ KEY_FLAGS,0 }
@ -360,3 +365,8 @@
#define Key_Keymap4_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_4 }
#define Key_Keymap5_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_5 }
#define Key_KeymapNext_Momentary (Key) {KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_NEXT }
#define Key_KeymapPrevious_Momentary (Key) {KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_PREVIOUS }

@ -1,12 +1,23 @@
#include "layouts-generated/qwerty.h"
#include "layouts-generated/qwerty_fn2.h"
#include "layouts-generated/dvorak.h"
#include "layouts-generated/dvorak_fn2.h"
#include "layouts-generated/colemak.h"
#include "layouts-generated/colemak_fn2.h"
#include "layouts-generated/maltron.h"
#include "layouts-generated/maltron_fn2.h"
#include "layouts-generated/workman.h"
#include "layouts-generated/workman_fn2.h"
#define LAYERS 8
static const Key keymaps[LAYERS][ROWS][COLS] = {
KEYMAP_QWERTY
KEYMAP_QWERTY_FN2
KEYMAP_COLEMAK
KEYMAP_COLEMAK_FN2
KEYMAP_DVORAK
KEYMAP_DVORAK_FN2
KEYMAP_WORKMAN
KEYMAP_WORKMAN_FN2

@ -2,5 +2,5 @@
{Key_Backtick, Key_Q, Key_W, Key_F, Key_P, Key_G, Key_skip, Key_skip, Key_J, Key_L, Key_U, Key_Y, Key_Semicolon, Key_Equals},\
{Key_PageUp, Key_A, Key_R, Key_S, Key_T, Key_D, Key_Tab, Key_Return, Key_H, Key_N, Key_E, Key_I, Key_O, Key_Quote},\
{Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Keymap0, Key_K, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_Keymap3_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_Keymap3_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_KeymapNext_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_KeymapNext_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -0,0 +1,6 @@
#define KEYMAP_DVORAK { /* Generated keymap for DVORAK */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\
{Key_Backtick, Key_Quote, Key_Comma, Key_Period, Key_P, Key_Y, Key_skip, Key_skip, Key_F, Key_G, Key_C, Key_R, Key_L, Key_Equals},\
{Key_PageUp, Key_A, Key_O, Key_E, Key_U, Key_I, Key_Tab, Key_Return, Key_D, Key_H, Key_T, Key_N, Key_S, Key_Minus},\
{Key_PageDn, Key_Slash, Key_Semicolon, Key_Q, Key_J, Key_K, Key_Esc, Key_Keymap2, Key_X, Key_B, Key_M, Key_W, Key_V, Key_Z},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_KeymapNext_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_KeymapNext_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -0,0 +1,6 @@
#define KEYMAP_DVORAK_FN2 { /* Generated keymap for DVORAK_FN2 */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\
{Key_Backtick, Key_macroKey1, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},\
{Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},\
{Key_PageDn, Key_Backslash, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Enter, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NoKey, Key_skip, Key_skip, Key_skip, Key_skip, Key_NoKey, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -0,0 +1,6 @@
#define KEYMAP_MALTRON { /* Generated keymap for MALTRON */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\
{Key_Backtick, Key_Q, Key_P, Key_Y, Key_C, Key_B, Key_skip, Key_skip, Key_V, Key_M, Key_U, Key_Z, Key_L, Key_Equals},\
{Key_PageUp, Key_A, Key_N, Key_I, Key_S, Key_F, Key_Tab, Key_Return, Key_D, Key_T, Key_H, Key_O, Key_R, Key_Quote},\
{Key_PageDn, Key_Comma, Key_Period, Key_J, Key_G, Key_Slash, Key_Esc, Key_Keymap2, Key_Semicolon, Key_W, Key_K, Key_Minus, Key_X, Key_LSquareBracket},\
{Key_LGUI, Key_E, Key_LShift, Key_Backspace, Key_KeymapNext_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_KeymapNext_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -0,0 +1,6 @@
#define KEYMAP_MALTRON_FN2 { /* Generated keymap for MALTRON_FN2 */ {Key_skip, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_skip, Key_skip, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_skip},\
{Key_Backtick, Key_macroKey1, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},\
{Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},\
{Key_PageDn, Key_Keymap2, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_Backslash, Key_Esc, Key_Enter, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_RSquareBracket},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NoKey, Key_skip, Key_skip, Key_skip, Key_skip, Key_NoKey, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -2,5 +2,5 @@
{Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_skip, Key_skip, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},\
{Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote},\
{Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Keymap2, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_Keymap1_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_Keymap1_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_KeymapNext_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_KeymapNext_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -0,0 +1,6 @@
#define KEYMAP_WORKMAN { /* Generated keymap for WORKMAN */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\
{Key_Backtick, Key_Q, Key_D, Key_R, Key_W, Key_B, Key_skip, Key_skip, Key_J, Key_F, Key_U, Key_P, Key_Semicolon, Key_Equals},\
{Key_PageUp, Key_A, Key_S, Key_H, Key_T, Key_G, Key_Tab, Key_Return, Key_Y, Key_N, Key_E, Key_O, Key_I, Key_Quote},\
{Key_PageDn, Key_Z, Key_X, Key_M, Key_C, Key_V, Key_Esc, Key_Keymap2, Key_K, Key_L, Key_Comma, Key_Period, Key_Slash, Key_Minus},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_KeymapNext_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_KeymapNext_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -0,0 +1,6 @@
#define KEYMAP_WORKMAN_FN2 { /* Generated keymap for WORKMAN_FN2 */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\
{Key_Backtick, Key_macroKey1, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_NoKey, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_NoKey, Key_Equals},\
{Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_NoKey, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},\
{Key_PageDn, Key_Keymap0, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_NoKey, Key_Esc, Key_Enter, Key_Pipe, Key_NoKey, Key_Comma, Key_Period, Key_Backslash, Key_Minus},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NoKey, Key_skip, Key_skip, Key_skip, Key_skip, Key_NoKey, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -3,4 +3,4 @@ skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip
` Q W F P G skip skip J L U Y ; =
PageUp A R S T D Tab Return H N E I O '
PageDn Z X C V B Esc Keymap0 K M , . / -
LGUI Backspace LShift LCtrl Keymap3_Momentary skip skip skip skip Keymap3_Momentary RCtrl RShift Space RAlt
LGUI Backspace LShift LCtrl KeymapNext_Momentary skip skip skip skip KeymapNext_Momentary RCtrl RShift Space RAlt

@ -3,4 +3,4 @@ skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip
` ' , . P Y skip skip F G C R L =
PageUp A O E U I Tab Return D H T N S -
PageDn / ; Q J K Esc Keymap2 X B M W V Z
LGUI Backspace LShift LCtrl Keymap1_Momentary skip skip skip skip Keymap1_Momentary RCtrl RShift Space RAlt
LGUI Backspace LShift LCtrl KeymapNext_Momentary skip skip skip skip KeymapNext_Momentary RCtrl RShift Space RAlt

@ -3,4 +3,4 @@ skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip
` Q P Y C B skip skip V M U Z L =
PageUp A N I S F Tab Return D T H O R '
PageDn , . J G / Esc Keymap2 ; W K - X [
LGUI E LShift Backspace Keymap5_Momentary skip skip skip skip Keymap5_Momentary RCtrl RShift Space RAlt
LGUI E LShift Backspace KeymapNext_Momentary skip skip skip skip KeymapNext_Momentary RCtrl RShift Space RAlt

@ -3,4 +3,4 @@ skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip
` Q W E R T skip skip Y U I O P =
PageUp A S D F G Tab Return H J K L ; '
PageDn Z X C V B Esc Keymap2 N M , . / -
LGUI Backspace LShift LCtrl Keymap1_Momentary skip skip skip skip Keymap1_Momentary RCtrl RShift Space RAlt
LGUI Backspace LShift LCtrl KeymapNext_Momentary skip skip skip skip KeymapNext_Momentary RCtrl RShift Space RAlt

@ -3,4 +3,4 @@ skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip
` Q D R W B skip skip J F U P ; =
PageUp A S H T G Tab Return Y N E O I '
PageDn Z X M C V Esc Keymap2 K L , . / -
LGUI Backspace LShift LCtrl Keymap1_Momentary skip skip skip skip Keymap1_Momentary RCtrl RShift Space RAlt
LGUI Backspace LShift LCtrl KeymapNext_Momentary skip skip skip skip KeymapNext_Momentary RCtrl RShift Space RAlt

Loading…
Cancel
Save