-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR enables logically grouping keys and apply layer switch and to…
…ggle operation to selected key groups only. Examples are provide that demonstrate grouping keys by keyboard hand sides, via condition expressions and with keymap-style color arrays. The basic idea that led to this PR was the question: How to switch one half of the keyboard to another layer while the other half should stay at the base layer. My intention was to switch via the thumb key of the Model01 one half of the keyboard to a modifier layer where all modifiers are supposed to reside on the home row. The other half of the keyboard should stay at the base layer. By means of that I intent to make typing modifier shortcuts with combined modifiers and keys more convenient. Of coures, this could already be done with the existing Kaleidoscope, e.g. by defining two individual additional layers whose keys for one half match those of the base layer and the other half the modifier layer. The redundancy is obvious. That's how the idea emerged to modity the layer class in a way that it stores not only one pair of `layer_state_` and `top_active_layer_` but several, each pair of those variables for a separate region of the keyboard. This makes it possible to make separate regions of the keyboard behave as individual keyboards in terms of their layer state. Lacking a better name, I called those keys assigned to such a region a "key group". Keys can be arbitrarily assigned to key groups. Layer switches/toggles can be defined to affect one or more key groups (see examples). By default only two key groups are defined. One for the left and one for the right hand side of the keyboard. * added header `src/Kaleidoscope-KeyGroups.h` * hardwares implement static constexpr bool isOnLeftHalf(uint8_t row, uint8_t col) convenience methods to test for the hand a key belongs to (one-handed keybords could just unconditionally return true) * added header `key_groups.h` * layers class tracks state of up to six key groups now * all public methods that affect the layer states now can be passed a key group flags to name the affected layers * method `extern uint8_t groupOfKey(uint8_t row, uint8_t col)` introduced that can be overridden from within the sketch * fixed Colormap plugin to work with multiple key groups * fixed plugin LED-ActiveLayerColor to work with multiple key groups * fixed plugin LED-ActiveModColor to work with multiple key groups * added TODO-comments in contexts (plugins EEPROM-KeymapOProgrmmer and NumPad) where layer-methods are used but no layer group information is available * added TODO-comments about the implementation of method `isOnLeftHalf` in some keyboards * examples were added to illustrate different use cases The PR will not break any user code or plugins. Only if keygroups are assigned to layer switch operations, the firmware behavior will differ from what it does currently. Changes will probably not noticeabley affect runtime performance. Stock firmware: Groth of program size from 25192 to 26992 bytes. Data usage grows from 1414 to 1459 bytes. Carefully check commit line changes containing TODOs and fix those. Especially concerning plugins EEPROM-KeymapOProgrmmer and NumPad. This PR comes with quite some changes and both program size and Data usage grow significantly. Nonetheless, this feature might be worth it. If Arduino eventually would introduce a global per-sketch configuration header (there's an ongoing discussion about this in the Arduino community) we could support several alternative implementations of the layer system, let the user select one and select a default one otherwise. As this is currently not possible, I chose to "upgrade" the existing layer class. Signed-off-by: Florian Fleissner <[email protected]>
- Loading branch information
Florian Fleissner
authored and
Florian Fleissner
committed
Apr 30, 2019
1 parent
5acb979
commit 1ac7503
Showing
22 changed files
with
613 additions
and
85 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
examples/Features/KeyGroups/ArrayBasedMembership/ArrayBasedMembership.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* -*- mode: c++ -*- | ||
* Basic -- A very basic Kaleidoscope example | ||
* Copyright (C) 2018 Keyboard.io, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "Kaleidoscope.h" | ||
|
||
#include "Kaleidoscope-LED-ActiveLayerColor.h" | ||
|
||
// This example demonstrates how keys can be grouped by | ||
// a decision function that relies on a keymap layer kind of array | ||
// that stores the key group id of every individual key. | ||
// | ||
// Please note that the function groupOfKey(..) may only return values | ||
// in the range [0;5]. | ||
|
||
enum { AMap, BMap }; | ||
|
||
/* *INDENT-OFF* */ | ||
KEYMAPS( | ||
[AMap] = KEYMAP_STACKED | ||
( | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
|
||
Key_A, Key_A, Key_A, Key_A, | ||
KeyGroup(KEY_GROUP_2, ShiftToLayer(BMap)), | ||
|
||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
|
||
Key_A, Key_A, Key_A, Key_A, | ||
KeyGroup(KEY_GROUP_1, ShiftToLayer(BMap)) | ||
), | ||
|
||
[BMap] = KEYMAP_STACKED | ||
( | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
|
||
Key_B, Key_B, Key_B, Key_B, | ||
___, | ||
|
||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
|
||
Key_B, Key_B, Key_B, Key_B, | ||
___ | ||
) | ||
) | ||
/* *INDENT-ON* */ | ||
|
||
KALEIDOSCOPE_INIT_PLUGINS( | ||
LEDControl, | ||
LEDActiveLayerColorEffect | ||
) | ||
|
||
KEY_GROUP_IDS_STACKED( | ||
0, 0, 0, 0, 0, 0, 0, | ||
1, 1, 1, 1, 1, 1, 1, | ||
1, 1, 1, 1, 1, 1, | ||
0, 0, 0, 0, 0, 0, 0, | ||
|
||
0, 0, 0, 0, | ||
0, | ||
|
||
0, 0, 0, 0, 0, 0, 0, | ||
2, 2, 2, 2, 2, 2, 2, | ||
2, 2, 2, 2, 2, 2, | ||
0, 0, 0, 0, 0, 0, 0, | ||
|
||
0, 0, 0, 0, | ||
0 | ||
) | ||
|
||
uint8_t groupOfKey(uint8_t row, uint8_t col) { | ||
return GROUP_OF_KEY(row, col); | ||
} | ||
|
||
void setup() { | ||
Kaleidoscope.setup(); | ||
|
||
static const cRGB layerColormap[] PROGMEM = { | ||
CRGB(128, 0, 0), | ||
CRGB(0, 128, 0) | ||
}; | ||
|
||
LEDActiveLayerColorEffect.setColormap(layerColormap); | ||
} | ||
|
||
void loop() { | ||
Kaleidoscope.loop(); | ||
} |
94 changes: 94 additions & 0 deletions
94
examples/Features/KeyGroups/ConditionalMembership/ConditionalMembership.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* -*- mode: c++ -*- | ||
* Basic -- A very basic Kaleidoscope example | ||
* Copyright (C) 2018 Keyboard.io, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "Kaleidoscope.h" | ||
|
||
#include "Kaleidoscope-LED-ActiveLayerColor.h" | ||
|
||
// This example demonstrates how keys can be grouped using conditionals | ||
// in a decision function. | ||
// | ||
// Please note that the function groupOfKey(...) may only return values | ||
// in the range [0;5]. | ||
|
||
enum { AMap, BMap }; | ||
|
||
/* *INDENT-OFF* */ | ||
KEYMAPS( | ||
[AMap] = KEYMAP_STACKED | ||
( | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
|
||
Key_A, Key_A, Key_A, Key_A, | ||
KeyGroup(KEY_GROUP_1, ShiftToLayer(BMap)), | ||
|
||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
|
||
Key_A, Key_A, Key_A, Key_A, | ||
KeyGroup(KEY_GROUP_0 | KEY_GROUP_2, ShiftToLayer(BMap)) | ||
), | ||
|
||
[BMap] = KEYMAP_STACKED | ||
( | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
|
||
Key_B, Key_B, Key_B, Key_B, | ||
___, | ||
|
||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
|
||
Key_B, Key_B, Key_B, Key_B, | ||
___ | ||
) | ||
) | ||
/* *INDENT-ON* */ | ||
|
||
KALEIDOSCOPE_INIT_PLUGINS( | ||
LEDControl, | ||
LEDActiveLayerColorEffect | ||
) | ||
|
||
uint8_t groupOfKey(uint8_t row, uint8_t col) { | ||
return row; | ||
} | ||
|
||
void setup() { | ||
Kaleidoscope.setup(); | ||
|
||
static const cRGB layerColormap[] PROGMEM = { | ||
CRGB(128, 0, 0), | ||
CRGB(0, 128, 0) | ||
}; | ||
|
||
LEDActiveLayerColorEffect.setColormap(layerColormap); | ||
} | ||
|
||
void loop() { | ||
Kaleidoscope.loop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* -*- mode: c++ -*- | ||
* Basic -- A very basic Kaleidoscope example | ||
* Copyright (C) 2018 Keyboard.io, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "Kaleidoscope.h" | ||
|
||
#include "Kaleidoscope-LED-ActiveLayerColor.h" | ||
|
||
// This example demonstrates the default key grouping mechanism | ||
// where the left hand is assigned to key group 0 (KEY_GROUP_LEFT_HAND), | ||
// the right hand to key group 1 (KEY_GROUP_RIGHT_HAND). | ||
|
||
enum { AMap, BMap }; | ||
|
||
/* *INDENT-OFF* */ | ||
KEYMAPS( | ||
[AMap] = KEYMAP_STACKED | ||
( | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
|
||
Key_A, Key_A, Key_A, Key_A, | ||
KeyGroup(KEY_GROUP_RIGHT_HAND, ShiftToLayer(BMap)), | ||
|
||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, | ||
|
||
Key_A, Key_A, Key_A, Key_A, | ||
KeyGroup(KEY_GROUP_LEFT_HAND, ShiftToLayer(BMap)) | ||
), | ||
|
||
[BMap] = KEYMAP_STACKED | ||
( | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
|
||
Key_B, Key_B, Key_B, Key_B, | ||
___, | ||
|
||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, | ||
|
||
Key_B, Key_B, Key_B, Key_B, | ||
___ | ||
) | ||
) | ||
/* *INDENT-ON* */ | ||
|
||
KALEIDOSCOPE_INIT_PLUGINS( | ||
LEDControl, | ||
LEDActiveLayerColorEffect | ||
) | ||
|
||
void setup() { | ||
Kaleidoscope.setup(); | ||
|
||
static const cRGB layerColormap[] PROGMEM = { | ||
CRGB(128, 0, 0), | ||
CRGB(0, 128, 0) | ||
}; | ||
|
||
LEDActiveLayerColorEffect.setColormap(layerColormap); | ||
} | ||
|
||
void loop() { | ||
Kaleidoscope.loop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* -*- mode: c++ -*- | ||
* Kaleidoscope-Hardware-EZ-ErgoDox -- ErgoDox hardware support for Kaleidoscope | ||
* Copyright (C) 2018 Keyboard.io, Inc | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
#include "kaleidoscope/key_groups.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.