diff --git a/ArduinoKeyboard.h b/ArduinoKeyboard.h index bc429b71..1c295f79 100644 --- a/ArduinoKeyboard.h +++ b/ArduinoKeyboard.h @@ -34,8 +34,8 @@ boolean key_toggled_on(byte keyState); // EEPROM related -void save_current_layer(byte layer); -byte load_current_layer(); +void save_primary_keymap(byte keymap); +byte load_primary_keymap(); // Keyboard debugging @@ -49,7 +49,7 @@ double mouse_accel (double cycles); void handle_mouse_movement( char x, char y); -// hardware layer interaction +// hardware keymap interaction void setup_pins(); void scan_matrix(); @@ -59,7 +59,7 @@ void reset_matrix(); void handle_immediate_action_during_matrix_scan(Key keymapEntry, byte matrixStateEntry); // keymaps -void set_keymap_layer(Key keymapEntry, byte matrixStateEntry); +void set_keymap_keymap(Key keymapEntry, byte matrixStateEntry); // sending events to the computer void record_key_being_pressed(byte character); diff --git a/ArduinoKeyboard.ino b/ArduinoKeyboard.ino index 16b7fce6..a30478cf 100644 --- a/ArduinoKeyboard.ino +++ b/ArduinoKeyboard.ino @@ -36,8 +36,8 @@ byte charsReportedLastTime[KEYS_HELD_BUFFER]; // A bit vector for the 256 keys w long reporting_counter = 0; -byte current_layer = 0; -byte active_layer = 0; +byte primary_keymap = 0; +byte active_keymap = 0; double mouseActiveForCycles = 0; float carriedOverX = 0; @@ -64,34 +64,34 @@ void reset_matrix() -void set_keymap_layer(Key keymapEntry, byte matrixStateEntry) { - if (keymapEntry.flags & SWITCH_TO_LAYER) { +void set_keymap_keymap(Key keymapEntry, byte matrixStateEntry) { + if (keymapEntry.flags & SWITCH_TO_KEYMAP) { // this logic sucks. there is a better way TODO this - if (! (keymapEntry.flags ^ ( MOMENTARY | SWITCH_TO_LAYER))) { + if (! (keymapEntry.flags ^ ( MOMENTARY | SWITCH_TO_KEYMAP))) { if (key_is_pressed(matrixStateEntry)) { - if ( keymapEntry.rawKey == LAYER_NEXT) { - active_layer++; - } else if ( keymapEntry.rawKey == LAYER_PREVIOUS) { - active_layer--; + if ( keymapEntry.rawKey == KEYMAP_NEXT) { + active_keymap++; + } else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) { + active_keymap--; } else { - active_layer = keymapEntry.rawKey; + active_keymap = keymapEntry.rawKey; } } - } else if (! (keymapEntry.flags ^ ( SWITCH_TO_LAYER))) { - // switch layer and stay there + } else if (! (keymapEntry.flags ^ ( SWITCH_TO_KEYMAP))) { + // switch keymap and stay there if (key_toggled_on(matrixStateEntry)) { - current_layer = active_layer = keymapEntry.rawKey; - save_current_layer(current_layer); + primary_keymap = active_keymap = keymapEntry.rawKey; + save_primary_keymap(primary_keymap); } } } } void handle_immediate_action_during_matrix_scan(Key keymapEntry, byte matrixStateEntry) { - set_keymap_layer(keymapEntry, matrixStateEntry); + set_keymap_keymap(keymapEntry, matrixStateEntry); } @@ -116,7 +116,7 @@ void scan_matrix() // that we should be looking at a seconary Keymap halfway through the matrix scan - handle_immediate_action_during_matrix_scan(keymaps[active_layer][row][col], matrixState[row][col]); + handle_immediate_action_during_matrix_scan(keymaps[active_keymap][row][col], matrixState[row][col]); } digitalWrite(rowPins[row], HIGH); @@ -132,13 +132,13 @@ void setup() Mouse.begin(); setup_matrix(); setup_pins(); - current_layer = load_current_layer(); - active_layer = current_layer; + primary_keymap = load_primary_keymap(); + active_keymap = primary_keymap; } void loop() { - active_layer = current_layer; + active_keymap = primary_keymap; scan_matrix(); send_key_events(); reset_matrix(); @@ -221,18 +221,18 @@ boolean key_toggled_off(byte keyState) -void save_current_layer(byte layer) +void save_primary_keymap(byte keymap) { - EEPROM.write(EEPROM_LAYER_LOCATION, layer); + EEPROM.write(EEPROM_KEYMAP_LOCATION, keymap); } -byte load_current_layer() +byte load_primary_keymap() { - byte layer = EEPROM.read(EEPROM_LAYER_LOCATION); - if (layer >= LAYERS ) { + byte keymap = EEPROM.read(EEPROM_KEYMAP_LOCATION); + if (keymap >= KEYMAPS ) { return 0; // undefined positions get saved as 255 } - return layer; + return keymap; } @@ -452,13 +452,13 @@ void send_key_events() for (byte col = 0; col < COLS; col++) { byte switchState = matrixState[row][col]; - Key mappedKey = keymaps[active_layer][row][col]; + Key mappedKey = keymaps[active_keymap][row][col]; if (mappedKey.flags & MOUSE_KEY ) { - handle_mouse_key_press(matrixState[row][col], keymaps[active_layer][row][col], x, y); + handle_mouse_key_press(matrixState[row][col], keymaps[active_keymap][row][col], x, y); } else if (mappedKey.flags & SYNTHETIC_KEY) { - handle_synthetic_key_press(matrixState[row][col], keymaps[active_layer][row][col]); + handle_synthetic_key_press(matrixState[row][col], keymaps[active_keymap][row][col]); } else { if (key_is_pressed(switchState)) { diff --git a/KeyboardConfig.h b/KeyboardConfig.h index 3711ba99..88d6137b 100644 --- a/KeyboardConfig.h +++ b/KeyboardConfig.h @@ -2,7 +2,7 @@ #define COLS 14 #define ROWS 5 -#define EEPROM_LAYER_LOCATION 0 +#define EEPROM_KEYMAP_LOCATION 0 static const byte colPins[COLS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, A0 }; diff --git a/key_defs.h b/key_defs.h index 781ddfe7..6d5fe7d9 100644 --- a/key_defs.h +++ b/key_defs.h @@ -3,7 +3,7 @@ #define ALT_HELD B00000010 #define SHIFT_HELD B00000100 #define GUI_HELD B00001000 -#define SWITCH_TO_LAYER B00010000 +#define SWITCH_TO_KEYMAP B00010000 #define MOMENTARY B00100000 #define MOUSE_KEY B01000000 #define SYNTHETIC_KEY B10000000 @@ -20,19 +20,19 @@ #define MOUSE_R B1000 -#define LAYER_0 0 -#define LAYER_1 1 -#define LAYER_2 2 -#define LAYER_3 3 -#define LAYER_4 4 -#define LAYER_5 5 -#define LAYER_6 6 -#define LAYER_7 7 +#define KEYMAP_0 0 +#define KEYMAP_1 1 +#define KEYMAP_2 2 +#define KEYMAP_3 3 +#define KEYMAP_4 4 +#define KEYMAP_5 5 +#define KEYMAP_6 6 +#define KEYMAP_7 7 -#define LAYER_PREVIOUS 253 -#define LAYER_NEXT 254 +#define KEYMAP_PREVIOUS 253 +#define KEYMAP_NEXT 254 #define Key_NoKey (Key){ KEY_FLAGS,0 } @@ -392,21 +392,21 @@ #define META_NEXT_KEYMAP_MOMENTARY 0xFF -#define Key_Keymap0 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_0 } -#define Key_Keymap1 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_1 } -#define Key_Keymap2 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_2 } -#define Key_Keymap3 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_3 } -#define Key_Keymap4 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_4 } -#define Key_Keymap5 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_5 } -#define Key_Keymap0_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_0 } -#define Key_Keymap1_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_1 } -#define Key_Keymap2_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_2 } -#define Key_Keymap3_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_3 } -#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 } +#define Key_Keymap0 (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP , KEYMAP_0 } +#define Key_Keymap1 (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP , KEYMAP_1 } +#define Key_Keymap2 (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP , KEYMAP_2 } +#define Key_Keymap3 (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP , KEYMAP_3 } +#define Key_Keymap4 (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP , KEYMAP_4 } +#define Key_Keymap5 (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP , KEYMAP_5 } +#define Key_Keymap0_Momentary (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP | MOMENTARY, KEYMAP_0 } +#define Key_Keymap1_Momentary (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP | MOMENTARY, KEYMAP_1 } +#define Key_Keymap2_Momentary (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP | MOMENTARY, KEYMAP_2 } +#define Key_Keymap3_Momentary (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP | MOMENTARY, KEYMAP_3 } +#define Key_Keymap4_Momentary (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP | MOMENTARY, KEYMAP_4 } +#define Key_Keymap5_Momentary (Key){ KEY_FLAGS | SWITCH_TO_KEYMAP | MOMENTARY, KEYMAP_5 } + +#define Key_KeymapNext_Momentary (Key) {KEY_FLAGS | SWITCH_TO_KEYMAP | MOMENTARY, KEYMAP_NEXT } +#define Key_KeymapPrevious_Momentary (Key) {KEY_FLAGS | SWITCH_TO_KEYMAP | MOMENTARY, KEYMAP_PREVIOUS } diff --git a/keymaps_generated.h b/keymaps_generated.h index f3089dc2..2161b9f9 100644 --- a/keymaps_generated.h +++ b/keymaps_generated.h @@ -34,9 +34,9 @@ {Key_PageDn, Key_Z, Key_X, Key_M, Key_C, Key_V, Key_Esc, Key_Keymap0, 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},\ }, -#define LAYERS 8 +#define KEYMAPS 8 // This is a total waste. we should only ever include any given keymap once -static const Key keymaps[LAYERS][ROWS][COLS] = { +static const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_QWERTY KEYMAP_GENERIC_FN2 KEYMAP_COLEMAK diff --git a/keymaps_h-template b/keymaps_h-template index a744612b..f6d30568 100644 --- a/keymaps_h-template +++ b/keymaps_h-template @@ -1,6 +1,6 @@ -#define LAYERS 8 +#define KEYMAPS 8 // This is a total waste. we should only ever include any given keymap once -static const Key keymaps[LAYERS][ROWS][COLS] = { +static const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_QWERTY KEYMAP_GENERIC_FN2 KEYMAP_COLEMAK