When you finish this tutorial you will be able to be able to modify a multi-layer keybrd sketch to suite your own multi-layer keyboard design.
layers are key bindings provided by the keyboard firmware. For example,
layer id - is an integer used to identify a layer.
active layer - is the layer currently used by the keyboard.
layer scheme - is a system for changing layers while typing (a single-layer scheme does not change layers).
The following pseudo code has just enough detail to show how layer schemes work.
Key_Layer objects are used to select an active layer. The “layer” variable is a layer id number. When a Key_Layer object is pressed, it tells LayerState to update the active layer.
class Key_Layer
{
int layer
LayerState& refLayerState
press() { refLayerState.setActiveLayer(layer) }
}
LayerState objects keep track of the active layer. A LayerState’s activeLayer is always up to date.
class LayerState
{
int activeLayer
setActiveLayer(int layer) { activeLayer = layer }
getActiveLayer() { return activeLayer }
}
Key_Layered objects contain multiple elements, one element for each layer. Layer ids are used like indexes to send the appropriate element. When a Key_Layered object is pressed, it gets the active layer from LayerState, and then sends the appropriate element.
class Key_Layered
{
Key** ptrsKeys //array of Key pointers, one Key pointer per layer
LayerState& refLayerState
press() { layer = refLayerState.getActiveLayer()
ptrsKeys[layer]->press() }
}
Dependency diagram
+-----------+
| Key_Layer |
+-----------+
|
|setActiveLayer()
|
v
+------------+
| LayerState |
+------------+
^
|
|getActiveLayer()
|
+-------------+
| Key_Layered |
+-------------+
There are several layer scheme-classes to choose from. You can view all the class definitions in the keybrd library.
Key_Layer classes include:
A basic LayerState class is:
Key_Layered classes include:
Most Code objects only have one scancode or code. They are not affected by the active layer. Example single-layer Code classes include:
(Future version of keybrd library may change all Code classes to Key classes.)
The keybrd_3a_multi-layer_annotated.ino sketch uses three layer-scheme classes:
Annotations in the sketch explain how the multi-layer feature works.
1) Modify the keybrd_3_multi-layer_annotated.ino sketch to use two Code_LayerLock objects.
Layout | 0 | 1 |
---|---|---|
0 | a 1 | b 2 |
1 | layer0 | layer1 |
keybrd tutorial by Wolfram Volpi is licensed under a Creative Commons Attribution 4.0 International License.
Permissions beyond the scope of this license may be available at https://github.com/wolfv6/keybrd/issues/new.