keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

tutorial_3a_multi-layer_keyboard.md 5.1KB

8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
8 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. Tutorial 3a - multi-layer keyboard
  2. ==================================
  3. When you finish this tutorial you will be able to be able to modify a multi-layer keybrd sketch to write your very own multi-layer keyboard firmware.
  4. Multi-layer nomenclature
  5. ------------------------
  6. **[layers](http://deskthority.net/wiki/Layer)** - are key bindings provided by the keyboard firmware. For example,
  7. * The classic [IBM PC keyboard](http://en.wikipedia.org/wiki/IBM_PC_keyboard) has one layer.
  8. * Many compact keyboards have an additional [Fn layer](http://en.wikipedia.org/wiki/Fn_key).
  9. * The [Neo layout](http://neo-layout.org/index_en.html) has 6 layers.
  10. **layer id** - is an integer used to identify a layer.
  11. **active layer** - is the layer currently used by the keyboard.
  12. **layer scheme** - is a system for changing the active layer while typing (a single-layer scheme does not change layers).
  13. A simple multi-layer keybrd sketch
  14. ----------------------------------
  15. The [keybrd_3a_multi-layer.ino](keybrd_3a_multi-layer/keybrd_3a_multi-layer.ino) sketch is for a simple two-layer keyboard.
  16. It will run on the basic breadboard keyboard described in [tutorial_1_breadboard_keyboard.md](tutorial_1_breadboard_keyboard.md).
  17. ![basic breadboard keyboard](keybrd_1_breadboard/breadboard_keyboard_2x2.JPG "basic breadboard keyboard")
  18. The sketch annotations explain how multi-layer keyboards work.
  19. The sketch uses three layer-scheme classes:
  20. * LayerState
  21. * Code_LayerHold
  22. * Key_LayeredKeys
  23. The internal workings of these three classes are revealed in the next section.
  24. Pseudo code for simple layer scheme
  25. -----------------------------------
  26. The following pseudo code is of three keybrd library classes.
  27. It has just enough detail to show the internal workings of layer schemes.
  28. **Code_Layer** objects change the active layer.
  29. When a Code_Layer object is pressed, it tells LayerState to update the active layer.
  30. ```
  31. class Code_Layer
  32. {
  33. int layerId;
  34. LayerState& refLayerState;
  35. press() { refLayerState.setActiveLayer(layerId); }
  36. };
  37. ```
  38. **LayerState** objects keep track of the activeLayer.
  39. A LayerState's activeLayer is always up to date.
  40. ```
  41. class LayerState
  42. {
  43. int activeLayer;
  44. setActiveLayer(int layerId) { activeLayer = layerId; }
  45. getActiveLayer() { return activeLayer; }
  46. };
  47. ```
  48. **Key_LayeredKeys** objects contain an array of keys, one key for each layer.
  49. Key_LayeredKeys objects use layerIds as Key_LayeredKeys indexes.
  50. When a Key_LayeredKeys object is pressed, it gets the active layerId from LayerState, and sends the corresponding key.
  51. ```
  52. class Key_LayeredKeys
  53. {
  54. Key** ptrsKeys; //array of Key pointers, one Key pointer per layer
  55. LayerState& refLayerState;
  56. press() { layerId = refLayerState.getActiveLayer();
  57. ptrsKeys[layerId]->press(); }
  58. };
  59. ```
  60. Dependency diagram
  61. ```
  62. +------------+
  63. | Code_Layer |
  64. +------------+
  65. |
  66. |setActiveLayer()
  67. |
  68. v
  69. +------------+
  70. | LayerState |
  71. +------------+
  72. ^
  73. |
  74. |getActiveLayer()
  75. |
  76. +-----------------+
  77. | Key_LayeredKeys |
  78. +-----------------+
  79. ```
  80. Layer-scheme classes
  81. --------------------
  82. There are several layer scheme-classes to choose from.
  83. You can view all the class definitions in the [keybrd library](../src/).
  84. Code_Layer classes include:
  85. * Code_LayerHold
  86. * Code_LayerLock
  87. A basic LayerState class is:
  88. * LayerState
  89. Key_Layered classes include:
  90. * Key_LayeredKeys
  91. * Key_LayeredScSc
  92. * Key_LayeredCodeSc
  93. The basic LayerState provided by the keybrd library is sufficient for implementing ordinary layer schemes.
  94. For experimental layer schemes, you would need to create a custom LayerState class, and possibly custom Code_Layer and Key_Layered classes as well.
  95. Single-layer Codes
  96. ------------------
  97. Most Code objects only have one scancode or code.
  98. Example single-layer Code classes include:
  99. * Code_Sc
  100. * Code_ScS
  101. * Code_ScNS
  102. * Code_Shift
  103. * Code_LayerHold
  104. * Code_LayerLock
  105. Exercises
  106. ---------
  107. 1) Modify the keybrd_3a_multi-layer.ino sketch to use two Code_LayerLock objects.
  108. | Layout | **0** | **1** |
  109. |:------:|:------:|:------:|
  110. | **0** | a 1 | b 2 |
  111. | **1** | layer0 | layer1 |
  112. <br>
  113. <a rel="license" href="https://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">keybrd tutorial</span> by <a xmlns:cc="https://creativecommons.org/ns" href="https://github.com/wolfv6/keybrd" property="cc:attributionName" rel="cc:attributionURL">Wolfram Volpi</a> is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.<br />Permissions beyond the scope of this license may be available at <a xmlns:cc="https://creativecommons.org/ns" href="https://github.com/wolfv6/keybrd/issues/new" rel="cc:morePermissions">https://github.com/wolfv6/keybrd/issues/new</a>.